Skip to content
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

Following PR-25994 and PR-26074 #26200

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ public static function create(&$params) {
}
}

// dev/core#287 Disable child groups if all parents are disabled.
if (!empty($params['id'])) {
// dev/core#287 Disable child groups if all parents are disabled.
$allChildGroupIds = self::getChildGroupIds($params['id']);
foreach ($allChildGroupIds as $childKey => $childValue) {
$parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($childValue);
Expand All @@ -370,7 +370,12 @@ public static function create(&$params) {
self::setIsActive($childValue, (int) ($params['is_active'] ?? 1));
}
}

// get current parents for removal if not in the list anymore
$parents = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $params['id'], 'parents');
$currentParentGroupIDs = $parents ? explode(',', $parents) : [];
}

// form the name only if missing: CRM-627
$nameParam = $params['name'] ?? NULL;
if (!$nameParam && empty($params['id'])) {
Expand Down Expand Up @@ -442,7 +447,17 @@ public static function create(&$params) {
$params['parents'] = [$domainGroupID];
}

// FIXME: Only allows adding parents, cannot remove them
// first deal with removed parents
if (array_key_exists('parents', $params) && !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)) {
Expand Down
14 changes: 0 additions & 14 deletions CRM/Group/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,6 @@ public function postProcess() {
$group = CRM_Contact_BAO_Group::create($params);
// Set the entity id so it is available to postProcess hook consumers
$this->setEntityId($group->id);
//Remove any parent groups requested to be removed
if (!empty($this->_groupValues['parents'])) {
$parentGroupIds = explode(',', $this->_groupValues['parents']);
foreach ($parentGroupIds as $parentGroupId) {
if (isset($params["remove_parent_group_$parentGroupId"])) {
CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $group->id);
$updateNestingCache = TRUE;
}
}
}

CRM_Core_Session::setStatus(ts('The Group \'%1\' has been saved.', array(1 => $group->title)), ts('Group Saved'), 'success');

Expand All @@ -392,10 +382,6 @@ public function postProcess() {
}
}

// update the nesting cache
if ($updateNestingCache) {
CRM_Contact_BAO_GroupNestingCache::update();
}
}

/**
Expand Down