Skip to content

Commit

Permalink
Merge pull request #13667 from seamuslee001/5_10_746
Browse files Browse the repository at this point in the history
Deploy hotfix to fix dev/core#746 until tests can be written for fix
  • Loading branch information
eileenmcnaughton authored Feb 22, 2019
2 parents 1f3f647 + 8966cd1 commit ee70496
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 9 additions & 2 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ class CRM_Contact_BAO_Query {

public $_pseudoConstantsSelect = array();

public $_groupUniqueKey = NULL;

/**
* Class constructor which also does all the work.
*
Expand Down Expand Up @@ -3038,12 +3040,13 @@ public function group($values) {
//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) {
Expand All @@ -3069,6 +3072,10 @@ public function group($values) {
}
}

public function getGroupCacheTableKey() {
return $this->_groupUniqueKey;
}

/**
* Function translates selection of group type into a list of groups.
* @param $value
Expand Down
12 changes: 8 additions & 4 deletions tests/phpunit/CRM/Contact/BAO/GroupContactCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ public function testSmartGroupSearchBuilder() {
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}");

Expand All @@ -452,8 +453,9 @@ public function testSmartGroupSearchBuilder() {
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}");

Expand All @@ -464,7 +466,8 @@ public function testSmartGroupSearchBuilder() {
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})");

Expand All @@ -475,7 +478,8 @@ public function testSmartGroupSearchBuilder() {
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})");
}
Expand Down

0 comments on commit ee70496

Please sign in to comment.