From 46b98e87a0e6bc96ea6c36c3e0d1e4f8ce5a9052 Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 26 May 2023 08:15:24 -0400 Subject: [PATCH] Group - Add missing metadata for 'children' column --- CRM/Contact/BAO/GroupContactCache.php | 7 +++--- CRM/Contact/DAO/Group.php | 25 ++++++++++++++----- .../CRM/Contact/BAO/GroupContactTest.php | 5 ---- tests/phpunit/api/v4/Entity/GroupTest.php | 23 ++++++++++++++--- xml/schema/Contact/Group.xml | 19 +++++++++++--- 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 6c451f8bc6..02f1dce5b7 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -781,12 +781,12 @@ ORDER BY gc.contact_id, g.children * @param string $tempTableName * @param int $groupID * @param int|null $savedSearchID - * @param string|null $children + * @param int[]|null $children * * @return void * @throws \CRM_Core_Exception */ - protected static function insertGroupContactsIntoTempTable(string $tempTableName, int $groupID, ?int $savedSearchID, ?string $children): void { + protected static function insertGroupContactsIntoTempTable(string $tempTableName, int $groupID, ?int $savedSearchID, ?array $children): void { if ($savedSearchID) { $savedSearch = SavedSearch::get(FALSE) ->addWhere('id', '=', $savedSearchID) @@ -835,8 +835,7 @@ AND civicrm_group_contact.group_id = $groupID "; $removed_contacts[] = $dao->contact_id; } - $childrenIDs = explode(',', $children); - foreach ($childrenIDs as $childID) { + foreach ($children as $childID) { $contactIDs = CRM_Contact_BAO_Group::getMember($childID, FALSE); // Unset each contact that is removed from the parent group foreach ($removed_contacts as $removed_contact) { diff --git a/CRM/Contact/DAO/Group.php b/CRM/Contact/DAO/Group.php index dc12c1e579..9eaf90901f 100644 --- a/CRM/Contact/DAO/Group.php +++ b/CRM/Contact/DAO/Group.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/Group.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:727ab4665b20bc8f541a0b3348fa17c5) + * (GenCodeChecksum:e98767d560ee98268e800a2aec983cea) */ /** @@ -184,7 +184,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { public $refresh_date; /** - * IDs of the parent(s) + * List of parent groups * * @var string|null * (SQL type: text) @@ -193,7 +193,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { public $parents; /** - * IDs of the child(ren) + * List of child groups (calculated) * * @var string|null * (SQL type: text) @@ -610,7 +610,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'name' => 'parents', 'type' => CRM_Utils_Type::T_TEXT, 'title' => ts('Group Parents'), - 'description' => ts('IDs of the parent(s)'), + 'description' => ts('List of parent groups'), 'usage' => [ 'import' => FALSE, 'export' => FALSE, @@ -625,7 +625,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'serialize' => self::SERIALIZE_COMMA, 'html' => [ 'type' => 'EntityRef', - 'label' => ts("Parent Group(s)"), + 'label' => ts("Parent Groups"), ], 'pseudoconstant' => [ 'table' => 'civicrm_group', @@ -640,7 +640,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'name' => 'children', 'type' => CRM_Utils_Type::T_TEXT, 'title' => ts('Group Children'), - 'description' => ts('IDs of the child(ren)'), + 'description' => ts('List of child groups (calculated)'), 'usage' => [ 'import' => FALSE, 'export' => FALSE, @@ -652,6 +652,19 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'entity' => 'Group', 'bao' => 'CRM_Contact_BAO_Group', 'localizable' => 0, + 'serialize' => self::SERIALIZE_COMMA, + 'html' => [ + 'type' => 'EntityRef', + 'label' => ts("Child Groups"), + ], + 'pseudoconstant' => [ + 'table' => 'civicrm_group', + 'keyColumn' => 'id', + 'labelColumn' => 'title', + 'nameColumn' => 'name', + 'prefetch' => 'FALSE', + ], + 'readonly' => TRUE, 'add' => '2.1', ], 'is_hidden' => [ diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php index 8047ad5012..4587bc7e64 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactTest.php @@ -99,11 +99,6 @@ class CRM_Contact_BAO_GroupContactTest extends CiviUnitTestCase { 'parents' => $parentGroup['id'], ]); - $this->callAPISuccess('Group', 'create', [ - 'id' => $parentGroup['id'], - 'children' => implode(',', [$childGroup['id'], $childSmartGroup['id']]), - ]); - // Create a contact within parent group $parentContactParams = [ 'first_name' => 'Parent1 Fname', diff --git a/tests/phpunit/api/v4/Entity/GroupTest.php b/tests/phpunit/api/v4/Entity/GroupTest.php index bfe4ab1c49..798541ad48 100644 --- a/tests/phpunit/api/v4/Entity/GroupTest.php +++ b/tests/phpunit/api/v4/Entity/GroupTest.php @@ -91,22 +91,39 @@ class GroupTest extends Api4TestBase { $parent2 = Group::create(FALSE) ->addValue('title', uniqid()) ->execute()->single(); - $child = Group::create(FALSE) + $child1 = Group::create(FALSE) ->addValue('title', uniqid()) ->addValue('parents', [$parent1['id'], $parent2['id']]) ->execute()->single(); + $child2 = Group::create(FALSE) + ->addValue('title', uniqid()) + ->addValue('parents', [$parent2['id']]) + ->execute()->single(); $get = Group::get(FALSE) - ->addWhere('id', '=', $child['id']) + ->addWhere('id', '=', $child1['id']) ->addSelect('parents') ->execute()->single(); $this->assertEquals([$parent1['id'], $parent2['id']], $get['parents']); $get = Group::get(FALSE) - ->addWhere('id', '=', $child['id']) + ->addWhere('id', '=', $child1['id']) ->addSelect('parents:label') ->execute()->single(); $this->assertEquals([$parent1['title'], $parent2['title']], $get['parents:label']); + + $get = Group::get(FALSE) + ->addWhere('id', '=', $parent1['id']) + ->addSelect('children') + ->execute()->single(); + $this->assertEquals([$child1['id']], $get['children']); + + $get = Group::get(FALSE) + ->addWhere('id', '=', $parent2['id']) + ->addSelect('children:label') + ->execute()->single(); + $this->assertEquals([$child1['title'], $child2['title']], $get['children:label']); + } } diff --git a/xml/schema/Contact/Group.xml b/xml/schema/Contact/Group.xml index c4403364f7..704d14f78a 100644 --- a/xml/schema/Contact/Group.xml +++ b/xml/schema/Contact/Group.xml @@ -184,7 +184,7 @@ parents text Group Parents - IDs of the parent(s) + List of parent groups 2.1 COMMA @@ -196,15 +196,28 @@ EntityRef - + children text Group Children - IDs of the child(ren) + List of child groups (calculated) 2.1 + COMMA + true + + civicrm_group
+ id + name + title + FALSE +
+ + EntityRef + +
is_hidden -- 2.25.1