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

CRM-21806 Search builder NOT Empty does not work #11746

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
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
20 changes: 15 additions & 5 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,11 +1444,7 @@ public function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALS
}
}

$select = "SELECT ";
if (isset($this->_distinctComponentClause)) {
$select .= "{$this->_distinctComponentClause}, ";
}
$select .= implode(', ', $this->_select);
$select = $this->getSelect();
$from = $this->_fromClause;
}

Expand Down Expand Up @@ -6542,4 +6538,18 @@ private function pseudoConstantNameIsInReturnProperties($field, $fieldName = NUL
return FALSE;
}

/**
* Get Select Clause.
*
* @return string
*/
public function getSelect() {
$select = "SELECT ";
if (isset($this->_distinctComponentClause)) {
$select .= "{$this->_distinctComponentClause}, ";
}
$select .= implode(', ', $this->_select);
return $select;
}

}
16 changes: 6 additions & 10 deletions CRM/Contact/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,15 +1005,14 @@ public function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = self::C
// For custom searches, use the contactIDs method
if (is_a($this, 'CRM_Contact_Selector_Custom')) {
$sql = $this->_search->contactIDs($start, $end, $sort, TRUE);
$replaceSQL = "SELECT contact_a.id as contact_id";
$coreSearch = FALSE;
}
// For core searches use the searchQuery method
else {
$sql = $this->_query->searchQuery($start, $end, $sort, FALSE, $this->_query->_includeContactIds,
FALSE, TRUE, TRUE);
$replaceSQL = "SELECT contact_a.id as id";
}
$replaceSQL = $this->_query->getSelect();

// CRM-9096
// due to limitations in our search query writer, the above query does not work
Expand All @@ -1030,20 +1029,17 @@ public function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = self::C
";

$sql = str_replace($replaceSQL, $insertSQL, $sql);

$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$result = CRM_Core_DAO::executeQuery($sql);
unset($errorScope);

if (is_a($result, 'DB_Error')) {
// check if we get error during core search
try {
CRM_Core_DAO::executeQuery($sql);
}
catch (CRM_Core_Exception $e) {
if ($coreSearch) {
// in the case of error, try rebuilding cache using full sql which is used for search selector display
// this fixes the bugs reported in CRM-13996 & CRM-14438
$this->rebuildPreNextCache($start, $end, $sort, $cacheKey);
}
else {
// return if above query fails
CRM_Core_Session::setStatus(ts('Query Failed'));
return;
}
}
Expand Down