public $_pseudoConstantsSelect = array();
+ public $_groupUniqueKey = NULL;
+
/**
* Class constructor which also does all the work.
*
//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) {
}
}
+ public function getGroupCacheTableKey() {
+ return $this->_groupUniqueKey;
+ }
+
/**
* Function translates selection of group type into a list of groups.
* @param $value
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}");
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}");
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})");
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})");
}