-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Ensure custom group name does not conflict with existing field #20694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,14 +142,16 @@ public static function create(&$params) { | |
$group->created_id = $params['created_id'] ?? NULL; | ||
$group->created_date = $params['created_date'] ?? NULL; | ||
|
||
// we do this only once, so name never changes | ||
if (isset($params['name'])) { | ||
$group->name = CRM_Utils_String::munge($params['name'], '_', 64); | ||
// Process name only during create, so it never changes | ||
if (!empty($params['name'])) { | ||
$group->name = CRM_Utils_String::munge($params['name']); | ||
} | ||
else { | ||
$group->name = CRM_Utils_String::munge($group->title, '_', 64); | ||
$group->name = CRM_Utils_String::munge($group->title); | ||
} | ||
|
||
self::validateCustomGroupName($group); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colemanw should this only be run on creation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right I see that now |
||
|
||
if (isset($params['table_name'])) { | ||
$tableName = $params['table_name']; | ||
|
||
|
@@ -225,6 +227,22 @@ public static function retrieve(&$params, &$defaults) { | |
return CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomGroup', $params, $defaults); | ||
} | ||
|
||
/** | ||
* Ensure group name does not conflict with an existing field | ||
* | ||
* @param CRM_Core_DAO_CustomGroup $group | ||
*/ | ||
public static function validateCustomGroupName(CRM_Core_DAO_CustomGroup $group) { | ||
$extends = in_array($group->extends, CRM_Contact_BAO_ContactType::basicTypes(TRUE)) ? 'Contact' : $group->extends; | ||
$extendsDAO = CRM_Core_DAO_AllCoreTables::getFullName($extends); | ||
if ($extendsDAO) { | ||
$fields = array_column($extendsDAO::fields(), 'name'); | ||
if (in_array($group->name, $fields)) { | ||
$group->name .= '0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colemanw what happens if you try to create a 2nd ActivityType Custom Group? i.e. one already has a 0 on it would that be an issue (this is probably quite the edge case but just thinking) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current behavior is that if you try to create a custom group with a duplicate name (or for that matter, a duplicate title) then you'll get a DB error due to the unique key constraints. This PR doesn't alter that. |
||
} | ||
} | ||
} | ||
|
||
/** | ||
* Update the is_active flag in the db. | ||
* | ||
|
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.
Just noting the default max length is 63 so this will work with the current table definition
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.
Yes this PR changes it from 64 down to 63 (which happens to be the default for that function) to accommodate the potential extra character inserted during validation.