diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 0485f70ff044780474f0babc8c443a69bdac887f..a93c1fb192ab3341a95fbc0086beb83b46651a42 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -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; }