Skip to content
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

Merged
merged 16 commits into from
Sep 13, 2016

Conversation

seamuslee001
Copy link
Contributor

No description provided.

@totten
Copy link
Member

totten commented Jun 6, 2016

During installation and upgrade, we should probably be setting the data_type for a few OptionGroups, e.g.

  • Installation (e.g. patch xml/templates/civicrm_data.tpl and maybe run regen.sh; if regen.sh is failing, then manually patch sql/civcrm_generated.mysql)
  • Upgrade (e.g. UPDATE civicrm_option_group SET data_type = 'Integer' WHERE name = 'event_type';)

@yashodha
Copy link
Contributor

@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.

@seamuslee001
Copy link
Contributor Author

@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',);
Copy link
Contributor

@yashodha yashodha Jul 13, 2016

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);
Copy link
Contributor

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().

@AkA84
Copy link

AkA84 commented Jul 20, 2016

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(
Copy link

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) {
    // ...
  }

 //..
}

@AkA84
Copy link

AkA84 commented Jul 20, 2016

Anyway this PR still has some issues unsolved and the branch has conflicts that need to be fixed if we want to merge it

@seamuslee001
Copy link
Contributor Author

@AkA84 Hi Allesandro, The idea of soft Validation came from @totten . I would be in favor of more harder failure but Tim suggested that we should do soft validation.

@seamuslee001 seamuslee001 force-pushed the CRM-18651 branch 2 times, most recently from 4d189e7 to d4c966c Compare July 21, 2016 00:12
@AkA84
Copy link

AkA84 commented Jul 25, 2016

hi @seamuslee001 , is this ready to be reviewed again?

@totten
Copy link
Member

totten commented Jul 25, 2016

+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).

@seamuslee001 seamuslee001 force-pushed the CRM-18651 branch 3 times, most recently from 2bd9c67 to bc1924b Compare August 31, 2016 00:13
@seamuslee001
Copy link
Contributor Author

@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);
Copy link
Contributor

@jitendrapurohit jitendrapurohit Sep 2, 2016

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.

@jitendrapurohit
Copy link
Contributor

Found a CiviCRM_API3_Exception: "DB Error: no such field" when editing an event type option after applying the changes.

$optionGroup = civicrm_api3('OptionGroup', 'get', array(
'sequential' => 1,
'name' => $optionGroupName,
));
Copy link
Contributor

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');

@jitendrapurohit
Copy link
Contributor

jitendrapurohit commented Sep 7, 2016

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 activity_type option value even though there's no value field present on the form.

@seamuslee001
Copy link
Contributor Author

@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

@seamuslee001
Copy link
Contributor Author

Jenkins test this please

@seamuslee001
Copy link
Contributor Author

thanks @jitendrapurohit I have fixed up the code now as per your comments and tested locally

@seamuslee001
Copy link
Contributor Author

@jitendrapurohit Jitendra would you be able to test this again?

@jitendrapurohit
Copy link
Contributor

@seamuslee001 Yes, I'll test this very soon :-)

@jitendrapurohit
Copy link
Contributor

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.

@totten
Copy link
Member

totten commented Sep 13, 2016

Jenkins reports one test failure which is pre-existing/not-relevant.

@totten totten merged commit 121e6fd into civicrm:master Sep 13, 2016
@seamuslee001 seamuslee001 deleted the CRM-18651 branch April 29, 2019 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants