From e96ee3a2af9741540f3fe3feb39b0d3c06693c32 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 15 Jan 2015 14:08:41 -0500 Subject: [PATCH] CRM-15820 - Exclude deleted contacts from group counts ---------------------------------------- * CRM-15820: Manage Groups contact summary also counts contacts in trash https://issues.civicrm.org/jira/browse/CRM-15820 --- CRM/Contact/BAO/Group.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 1ad8a313b8..b0cea18aa8 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -965,13 +965,15 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } } - // Get group counts + // Get group counts - executes one query for regular groups and another for smart groups foreach ($groupsToCount as $table => $groups) { - $where = "group_id IN (" . implode(',', $groups) . ")"; + $where = "g.group_id IN (" . implode(',', $groups) . ")"; if ($table == 'civicrm_group_contact') { - $where .= " AND status = 'Added'"; + $where .= " AND g.status = 'Added'"; } - $dao = CRM_Core_DAO::executeQuery("SELECT group_id, COUNT(id) as `count` FROM $table WHERE $where GROUP BY group_id"); + // Exclude deleted contacts + $where .= " and c.id = g.contact_id AND c.is_deleted = 0"; + $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT(g.id) as `count` FROM $table g, civicrm_contact c WHERE $where GROUP BY g.group_id"); while ($dao->fetch()) { $values[$dao->group_id]['count'] = $dao->count; } -- 2.25.1