From 47e5bbbbb59233cdcb27fca6b9aca2434a8294e2 Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Fri, 28 May 2021 16:41:22 +0530 Subject: [PATCH] Cannot remove Group Organisation selection in multisite setup --- CRM/Contact/BAO/Group.php | 21 +++++++++++++++------ CRM/Group/Form/Edit.php | 4 ++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 48e5802ab2..87fa70e076 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -477,12 +477,21 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } if (!empty($params['organization_id'])) { - // dev/core#382 Keeping the id here can cause db errors as it tries to update the wrong record in the Organization table - $groupOrg = [ - 'group_id' => $group->id, - 'organization_id' => $params['organization_id'], - ]; - CRM_Contact_BAO_GroupOrganization::add($groupOrg); + if ($params['organization_id'] == 'null') { + $groupOrganization = []; + CRM_Contact_BAO_GroupOrganization::retrieve($group->id, $groupOrganization); + if (!empty($groupOrganization['group_organization'])) { + CRM_Contact_BAO_GroupOrganization::deleteGroupOrganization($groupOrganization['group_organization']); + } + } + else { + // dev/core#382 Keeping the id here can cause db errors as it tries to update the wrong record in the Organization table + $groupOrg = [ + 'group_id' => $group->id, + 'organization_id' => $params['organization_id'], + ]; + CRM_Contact_BAO_GroupOrganization::add($groupOrg); + } } self::flushCaches(); diff --git a/CRM/Group/Form/Edit.php b/CRM/Group/Form/Edit.php index 801342f9e0..0b080cefdf 100644 --- a/CRM/Group/Form/Edit.php +++ b/CRM/Group/Form/Edit.php @@ -365,6 +365,10 @@ WHERE title = %1 'Group' ); + if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) { + $params['organization_id'] = empty($params['organization_id']) ? 'null' : $params['organization_id']; + } + $group = CRM_Contact_BAO_Group::create($params); // Set the entity id so it is available to postProcess hook consumers $this->setEntityId($group->id); -- 2.25.1