Skip to content

Commit

Permalink
Merge pull request #26623 from colemanw/secretGroup
Browse files Browse the repository at this point in the history
Group BAO - Remove secret param that was breaking groupNesting
  • Loading branch information
eileenmcnaughton authored Jun 23, 2023
2 parents 3867a13 + b721149 commit 29c9576
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,48 +441,35 @@ public static function create(&$params) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id);
}

// Secret `no_parent` param is used by the multisite extension to prevent default behavior.
if (empty($params['no_parent'])) {
$domainGroupID = CRM_Core_BAO_Domain::getGroupId();
// If multi-site is_enabled, no parent selected and the group doesn't already have any parents,
// set parent to the domain group
if (Civi::settings()->get('is_enabled') &&
empty($params['parents']) &&
$domainGroupID != $group->id &&
!CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)
) {
$params['parents'] = [$domainGroupID];
}

// first deal with removed parents
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'])) {
CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $params['id']);
}
// Process group nesting
// first deal with removed parents
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'])) {
CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $params['id']);
}
}
}

// then add missing parents
if (!CRM_Utils_System::isNull($params['parents'])) {
foreach ($params['parents'] as $parentId) {
if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
}
// then add missing parents
if (!CRM_Utils_System::isNull($params['parents'])) {
foreach ($params['parents'] as $parentId) {
if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) {
CRM_Contact_BAO_GroupNesting::add($parentId, $group->id);
}
}
}

// refresh cache if parents param was provided
if ($parentsParamProvided || !empty($params['parents'])) {
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);
foreach ($parentIds as $parentId) {
CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($parentId);
}
// update group contact cache for all parent groups
$parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id);
foreach ($parentIds as $parentId) {
CRM_Contact_BAO_GroupContactCache::invalidateGroupContactCache($parentId);
}

if (!empty($params['organization_id'])) {
Expand Down

0 comments on commit 29c9576

Please sign in to comment.