From e8fe2f63c7adfeb6596579106dd7814e19dcc457 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 18 Apr 2023 07:15:59 -0400 Subject: [PATCH] Clarify not-so-great code in the Group BAO --- CRM/Contact/BAO/Group.php | 15 ++++++++------- settings/Multisite.setting.php | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index c718b3ce44..245f183f2f 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -429,19 +429,20 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } - // make the group, child of domain/site group by default. - $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); - if (CRM_Utils_Array::value('no_parent', $params) !== 1) { - if (empty($params['parents']) && + // 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 && - Civi::settings()->get('is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id) ) { - // if no parent present and the group doesn't already have any parents, - // make sure site group goes as parent $params['parents'] = [$domainGroupID]; } + // FIXME: Only allows adding parents, cannot remove them if (!CRM_Utils_System::isNull($params['parents'])) { foreach ($params['parents'] as $parentId) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { diff --git a/settings/Multisite.setting.php b/settings/Multisite.setting.php index 64e06b9ad8..8069378c9f 100644 --- a/settings/Multisite.setting.php +++ b/settings/Multisite.setting.php @@ -20,6 +20,7 @@ */ return [ + // FIXME: This is arguably the worst name for a setting ever 'is_enabled' => [ 'group_name' => 'Multi Site Preferences', 'group' => 'multisite', -- 2.25.1