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

Fix filtering when using a smart group #30

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
13 changes: 7 additions & 6 deletions CRM/Xdedupe/Filter/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ public function addJOINS(&$joins)
$is_smart_group = CRM_Core_DAO::singleValueQuery(
"SELECT saved_search_id FROM civicrm_group WHERE id = %1",
[1 => [$this->group_id, 'Integer']]);
$table = 'civicrm_group_contact';
if ($is_smart_group) {
CRM_Contact_BAO_GroupContactCache::loadAll($this->group_id);
CRM_Contact_BAO_GroupContactCache::loadAll([$this->group_id]);
$table = 'civicrm_group_contact_cache';
}

// finally: add the join
$joins[] = "LEFT JOIN civicrm_group_contact {$this->alias} ON {$this->alias}.contact_id = contact.id
AND {$this->alias}.group_id = {$this->group_id}
AND {$this->alias}.status = 'Added'";
$joins[] = "LEFT JOIN {$table} {$this->alias} ON {$this->alias}.contact_id = contact.id
AND {$this->alias}.group_id = {$this->group_id}" . ($is_smart_group ? '' : " AND {$this->alias}.status = 'Added'");
}
}

Expand All @@ -85,9 +86,9 @@ public function addJOINS(&$joins)
public function addWHERES(&$wheres)
{
if ($this->include) {
$wheres[] = "{$this->alias}.id IS NOT NULL";
$wheres[] = "{$this->alias}.contact_id IS NOT NULL";
} else {
$wheres[] = "{$this->alias}.id IS NULL";
$wheres[] = "{$this->alias}.contact_id IS NULL";
}
}
}