From ed17b5e2602484efc7a1a2c05777f575627185a3 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 22 Feb 2019 12:11:53 +1100 Subject: [PATCH] Deploy hotfix to fix dev/core#746 until tests can be written for fix Fix GroupContactCacheTest --- CRM/Contact/BAO/Query.php | 11 +++++++++-- .../CRM/Contact/BAO/GroupContactCacheTest.php | 12 ++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index a935ca96d2..cdd3f47618 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -412,6 +412,8 @@ class CRM_Contact_BAO_Query { public $_pseudoConstantsSelect = array(); + public $_groupUniqueKey = NULL; + /** * Class constructor which also does all the work. * @@ -3038,12 +3040,13 @@ class CRM_Contact_BAO_Query { //CRM-19589: contact(s) removed from a Smart Group, resides in civicrm_group_contact table $groupContactCacheClause = ''; if (count($smartGroupIDs) || empty($value)) { - $gccTableAlias = "civicrm_group_contact_cache"; + $this->_groupUniqueKey = uniqid(); + $gccTableAlias = "civicrm_group_contact_cache_{$this->_groupUniqueKey}"; $groupContactCacheClause = $this->addGroupContactCache($smartGroupIDs, $gccTableAlias, "contact_a", $op); if (!empty($groupContactCacheClause)) { if ($isNotOp) { $groupIds = implode(',', (array) $smartGroupIDs); - $gcTable = "civicrm_group_contact"; + $gcTable = "civicrm_group_contact_{$this->_groupUniqueKey}"; $joinClause = array("contact_a.id = {$gcTable}.contact_id"); $this->_tables[$gcTable] = $this->_whereTables[$gcTable] = " LEFT JOIN civicrm_group_contact {$gcTable} ON (" . implode(' AND ', $joinClause) . ")"; if (strpos($op, 'IN') !== FALSE) { @@ -3069,6 +3072,10 @@ class CRM_Contact_BAO_Query { } } + public function getGroupCacheTableKey() { + return $this->_groupUniqueKey; + } + /** * Function translates selection of group type into a list of groups. * @param $value diff --git a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php index 893390f190..fc1acf50a6 100644 --- a/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php +++ b/tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php @@ -441,7 +441,8 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { FALSE, FALSE, FALSE, TRUE, FALSE ); - $expectedWhere = "civicrm_group_contact_cache.group_id IN (\"{$group2->id}\")"; + $key = $query->getGroupCacheTableKey(); + $expectedWhere = "civicrm_group_contact_cache_{$key}.group_id IN (\"{$group2->id}\")"; $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id = {$group2->id}"); @@ -452,8 +453,9 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { FALSE, FALSE, FALSE ); + $key = $query->getGroupCacheTableKey(); //Assert if proper where clause is present. - $expectedWhere = "civicrm_group_contact.group_id != {$group->id} AND civicrm_group_contact_cache.group_id IS NULL OR ( civicrm_group_contact_cache.contact_id NOT IN (SELECT contact_id FROM civicrm_group_contact_cache cgcc WHERE cgcc.group_id IN ( {$group->id} ) ) )"; + $expectedWhere = "civicrm_group_contact_{$key}.group_id != {$group->id} AND civicrm_group_contact_cache_{$key}.group_id IS NULL OR ( civicrm_group_contact_cache_{$key}.contact_id NOT IN (SELECT contact_id FROM civicrm_group_contact_cache cgcc WHERE cgcc.group_id IN ( {$group->id} ) ) )"; $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id != {$group->id}"); @@ -464,7 +466,8 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { FALSE, FALSE, FALSE ); - $expectedWhere = "civicrm_group_contact_cache.group_id IN (\"{$group->id}\", \"{$group2->id}\")"; + $key = $query->getGroupCacheTableKey(); + $expectedWhere = "civicrm_group_contact_cache_{$key}.group_id IN (\"{$group->id}\", \"{$group2->id}\")"; $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id IN ({$group->id}, {$group2->id})"); @@ -475,7 +478,8 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase { FALSE, FALSE, FALSE ); - $expectedWhere = "civicrm_group_contact.group_id NOT IN ( {$group->id} ) AND civicrm_group_contact_cache.group_id IS NULL OR ( civicrm_group_contact_cache.contact_id NOT IN (SELECT contact_id FROM civicrm_group_contact_cache cgcc WHERE cgcc.group_id IN ( {$group->id} ) ) )"; + $key = $query->getGroupCacheTableKey(); + $expectedWhere = "civicrm_group_contact_{$key}.group_id NOT IN ( {$group->id} ) AND civicrm_group_contact_cache_{$key}.group_id IS NULL OR ( civicrm_group_contact_cache_{$key}.contact_id NOT IN (SELECT contact_id FROM civicrm_group_contact_cache cgcc WHERE cgcc.group_id IN ( {$group->id} ) ) )"; $this->assertContains($expectedWhere, $query->_whereClause); $this->_assertContactIds($query, "group_id NOT IN ({$group->id})"); } -- 2.25.1