-
-
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
Fix problem with group.update api #26260
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 |
---|---|---|
|
@@ -334,6 +334,10 @@ public function addSelectWhereClause() { | |
* The new group BAO (if created) | ||
*/ | ||
public static function create(&$params) { | ||
|
||
// only check if we need to remove parents if a params was provided | ||
$parentsParamProvided = array_key_exists('parents', $params); | ||
|
||
$params += [ | ||
'group_type' => NULL, | ||
'parents' => NULL, | ||
|
@@ -382,8 +386,12 @@ public static function create(&$params) { | |
$params['name'] = CRM_Utils_String::titleToVar($params['title']); | ||
} | ||
|
||
if (!CRM_Utils_System::isNull($params['parents'])) { | ||
if ($parentsParamProvided) { | ||
$params['parents'] = CRM_Utils_Array::convertCheckboxFormatToArray((array) $params['parents']); | ||
// failsafe: forbid adding itself as parent | ||
if (!empty($params['id']) && ($key = array_search($params['id'], $params['parents'])) !== FALSE) { | ||
unset($params['parents'][$key]); | ||
} | ||
} | ||
|
||
// convert params if array type | ||
|
@@ -448,7 +456,7 @@ public static function create(&$params) { | |
} | ||
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. This block (see above) will actually force in a 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. Ok, any preference ? we could also go back to a safer approach where the cache is updated no matter what. |
||
|
||
// first deal with removed parents | ||
if (array_key_exists('parents', $params) && !empty($currentParentGroupIDs)) { | ||
if ($parentsParamProvided && !empty($currentParentGroupIDs)) { | ||
foreach ($currentParentGroupIDs as $parentGroupId) { | ||
// no more parents or not in the new list, let's remove | ||
if (empty($params['parents']) || !in_array($parentGroupId, $params['parents'])) { | ||
|
@@ -466,9 +474,10 @@ public static function create(&$params) { | |
} | ||
} | ||
|
||
// this is always required, since we don't know when a | ||
// parent group is removed | ||
CRM_Contact_BAO_GroupNestingCache::update(); | ||
// refresh cache if parents param was provided | ||
if ($parentsParamProvided || !empty($params['parents'])) { | ||
CRM_Contact_BAO_GroupNestingCache::update(); | ||
} | ||
|
||
// update group contact cache for all parent groups | ||
$parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); | ||
|
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.
Refactoring note: not a blocker for this PR, but this function really shouldn't be called from the BAO as it's only needed on the quickform.