Merge pull request #6496 from totten/master-regen-leak
[civicrm-core.git] / CRM / Contact / BAO / GroupContact.php
index 90609af0833a92a9afa8b60a31d02c270bc86dba..da7ebc36040a4ac9af093f45d19b4f22c4b1db1d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
@@ -351,7 +351,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
                     civicrm_subscription_history.method as method';
     }
 
-    $where = " WHERE contact_a.id = %1 AND civicrm_group.is_active = 1 ";
+    $where = " WHERE contact_a.id = %1 AND civicrm_group.is_active = 1";
 
     if ($excludeHidden) {
       $where .= " AND civicrm_group.is_hidden = 0 ";
@@ -381,6 +381,10 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
 
     $from = CRM_Contact_BAO_Query::fromClause($tables);
 
+    //CRM-16945: seems hackish but as per CRM-16483 of using group criteria for Search Builder it is mandatory
+    //to include group_contact_cache clause when group table is present, so following code remove duplicacy
+    $from = str_replace("OR civicrm_group.id = civicrm_group_contact_cache.group_id", 'AND civicrm_group.saved_search_id IS NULL', $from);
+
     $where .= " AND $permission ";
 
     if ($onlyPublicGroups) {