-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM 18651 - Add in Option Group and soft validation #8503
Conversation
During installation and upgrade, we should probably be setting the
|
126efc8
to
b9a780e
Compare
@seamuslee001 Could you please rebase your PR and also move the upgrade code to 4.7.10.mysql.tpl since that's the next release. |
@yashodha have done so now |
ADD `data_type` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Data Type of Option Group.'; | ||
UPDATE civicrm_option_group SET `data_type` = 'Integer' | ||
WHERE name in ('activity_type', 'gender', 'payment_instrument', 'participant_role', 'event_type', | ||
'activity_status',); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a syntax error - unwanted comma after activity_status.
@@ -71,6 +71,8 @@ public function buildQuickForm() { | |||
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description') | |||
); | |||
|
|||
$this->addSelect('Data Type', CRM_Utils_Type::dataTypes(), TRUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't let Option Group Form to load. Form to add option group results into a fatal error.
Cannot determine default entity. CRM_Admin_Form_OptionGroup should implement getDefaultEntity().
Why allowing the user to create an invalid event type at all? Couldn't the error be caught at form validation? I can still create an event type with value "foo" and get the "Unable to reach the server. Please refresh this page in your browser and try again." error when creating an event of that type |
@@ -376,6 +376,19 @@ public static function formRule($fields, $files, $self) { | |||
} | |||
} | |||
|
|||
$optionGroup = civicrm_api3('OptionGroup', 'get', array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would wrap this in a private method to make the code cleaner and more readable (kind of pseudo-code following):
/**
*
*
*/
private function getOptionGroupDataType($groupName) {
$optionGroup = civicrm_api3('OptionGroup', 'get', array(
'sequential' => 1,
'name' => $groupName,
));
return CRM_Core_BAO_OptionGroup::getDataType($optionGroup['id']);
}
// ...
public static function formRule($fields, $files, $self) {
$dataType = $self->getOptionGroupDataType($self->_gName);
if ($dataType) {
// ...
}
//..
}
Anyway this PR still has some issues unsolved and the branch has conflicts that need to be fixed if we want to merge it |
4d189e7
to
d4c966c
Compare
hi @seamuslee001 , is this ready to be reviewed again? |
+1 for soft-validation / warnings. I'm usually a fan of hard-validation / failures, but in this case soft-validation feels like it has better overall cost/benefit (although I don't have a strict formula to rationalize that). |
2bd9c67
to
bc1924b
Compare
@AkA84 @totten @jitendrapurohit I've rebased this against master and moved upgrade code to 4.7.12. I would appreciate another review of this with the hope this may get in for .12 |
@@ -376,10 +376,36 @@ public static function formRule($fields, $files, $self) { | |||
} | |||
} | |||
|
|||
$optionGroup = $this->getOptionGroupDataType($self->_gName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think $this
call need to be changed to self::
under static formRule() function to avoid fatal error.
Found a |
$optionGroup = civicrm_api3('OptionGroup', 'get', array( | ||
'sequential' => 1, | ||
'name' => $optionGroupName, | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use getFieldValue()
directly here to get the group id instead of an API call ? Something like -
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupName, 'id', 'name');
According to changes done here, we don't build a value text field for activity_type. So, I get an invalid soft validation error on saving an |
@jitendrapurohit thanks for those pickups, I will make those fixes and try and work out a solution for activity_type. Will ping you once i have pushed changes |
Jenkins test this please |
c63b34d
to
53b3f76
Compare
thanks @jitendrapurohit I have fixed up the code now as per your comments and tested locally |
Fix up upgrade script and add a system check rerun regen after rebasing WIP on adding data type for option group Further work on soft fail when option value value field doesn't match given data type
Re run regen.sh
…type also minor code changes as suggested on PR
…rom the check when saving the option value form and re run regen.sh
53b3f76
to
89c05af
Compare
@jitendrapurohit Jitendra would you be able to test this again? |
@seamuslee001 Yes, I'll test this very soon :-) |
I've tested this on installation/upgradation. Option values are soft validated and problematic values are shown on the status page correctly. From my side, this is ok to merge. Thanks. |
Jenkins reports one test failure which is pre-existing/not-relevant. |
No description provided.