CRM-13216 fix
authormonishdeb <monish.deb@webaccess.co.in>
Wed, 21 Aug 2013 14:00:25 +0000 (19:30 +0530)
committermonishdeb <monish.deb@webaccess.co.in>
Wed, 21 Aug 2013 14:00:25 +0000 (19:30 +0530)
----------------------------------------
* CRM-13216: Advanced Search shows deleted contacts
  http://issues.civicrm.org/jira/browse/CRM-13216

CRM/Contact/BAO/Query.php

index 0485f70ff044780474f0babc8c443a69bdac887f..a93c1fb192ab3341a95fbc0086beb83b46651a42 100644 (file)
@@ -4198,17 +4198,6 @@ civicrm_relationship.start_date > {$today}
     }
     $this->generatePermissionClause($onlyDeleted, $count);
 
-    if (empty($where)) {
-      $where = "WHERE $this->_permissionWhereClause";
-    }
-    else {
-      $where = "$where AND $this->_permissionWhereClause";
-    }
-
-    if ($additionalWhereClause) {
-      $where = $where . ' AND ' . $additionalWhereClause;
-    }
-
     // building the query string
     $groupBy = NULL;
     if (!$count) {
@@ -4310,7 +4299,20 @@ civicrm_relationship.start_date > {$today}
 
     list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts);
 
-    //additional from clause should be w/ proper joins.
+    if(!empty($this->_permissionWhereClause)){
+      if (empty($where)) {
+        $where = "WHERE $this->_permissionWhereClause";
+      }
+      else {
+        $where = "$where AND $this->_permissionWhereClause";
+      }
+    }
+
+    if ($additionalWhereClause) {
+      $where = $where . ' AND ' . $additionalWhereClause;
+    }
+
+     //additional from clause should be w/ proper joins.
     if ($additionalFromClause) {
       $from .= "\n" . $additionalFromClause;
     }