From fbbd2be102a810a5fadb712965806177e2a4bfab Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Tue, 6 Mar 2018 12:58:57 +0530 Subject: [PATCH] CRM-21806: Fix issues is search form when FULL_GROUP_BY_MODE enabled --- CRM/Contact/BAO/Query.php | 5 ++++- CRM/Contact/Selector.php | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 4dfcde1e36..df6aa40b97 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4890,7 +4890,10 @@ civicrm_relationship.is_permission_a_b = 0 list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts, $onlyDeleted); if (!empty($groupByCols)) { - $select = self::appendAnyValueToSelect($this->_select, $groupByCols, 'GROUP_CONCAT'); + // It doesn't matter to include columns in SELECT clause, which are present in GROUP BY when we just want the contact IDs + if (!$groupContacts) { + $select = self::appendAnyValueToSelect($this->_select, $groupByCols, 'GROUP_CONCAT'); + } $groupBy = " GROUP BY " . implode(', ', $groupByCols); if (!empty($order)) { // retrieve order by columns from ORDER BY clause diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index d0f5b4a85a..b4135b7185 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -1012,7 +1012,6 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $sql = $this->_query->searchQuery($start, $end, $sort, FALSE, $this->_query->_includeContactIds, FALSE, TRUE, TRUE); } - $replaceSQL = $this->_query->getSelect(); // CRM-9096 // due to limitations in our search query writer, the above query does not work @@ -1025,10 +1024,10 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se $insertSQL = " INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data ) -SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.display_name +SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.sort_name "; - $sql = str_replace($replaceSQL, $insertSQL, $sql); + $sql = str_replace(array("SELECT contact_a.id as contact_id", "SELECT contact_a.id as id"), $insertSQL, $sql); try { CRM_Core_DAO::executeQuery($sql); } -- 2.25.1