From 9e0836216f8b2882726f44a0e5358b9cc65d81e0 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 21 Feb 2019 22:33:59 +1300 Subject: [PATCH] [REF] minor cleanup of groupBy definition. If you read the code the groupBy statement creation can go with 'its friends' and the groupBy in the removed line is overwritten. I'll extract this next .... --- CRM/Contact/BAO/Query.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 7c4d39a275..103a55f5ef 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4889,7 +4889,6 @@ civicrm_relationship.start_date > {$today} $groupBy = $groupByCols = NULL; if (!$count) { if (isset($this->_groupByComponentClause)) { - $groupBy = $this->_groupByComponentClause; $groupByCols = preg_replace('/^GROUP BY /', '', trim($this->_groupByComponentClause)); $groupByCols = explode(', ', $groupByCols); } @@ -4900,6 +4899,9 @@ civicrm_relationship.start_date > {$today} if ($this->_mode & CRM_Contact_BAO_Query::MODE_ACTIVITY && (!$count)) { $groupByCols = array('civicrm_activity.id'); } + if (!empty($groupByCols)) { + $groupBy = " GROUP BY " . implode(', ', $groupByCols); + } $order = $orderBy = $limit = ''; if (!$count) { @@ -4916,7 +4918,7 @@ civicrm_relationship.start_date > {$today} // MySQL expect the columns present in GROUP BY, must be present in SELECT clause and that results into error, needless to have other columns. // 2. When GROUP BY columns are present then disable FGB otherwise it demands to add ORDER BY columns in GROUP BY and eventually in SELECT // clause. This will impact the search query output. - $disableFullGroupByMode = ($sortByChar || !empty($groupByCols) || $groupContacts); + $disableFullGroupByMode = ($sortByChar || !empty($groupBy) || $groupContacts); if ($disableFullGroupByMode) { CRM_Core_DAO::disableFullGroupByMode(); @@ -4930,10 +4932,6 @@ civicrm_relationship.start_date > {$today} list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts, $onlyDeleted); - if (!empty($groupByCols)) { - $groupBy = " GROUP BY " . implode(', ', $groupByCols); - } - if ($additionalWhereClause) { $where = $where . ' AND ' . $additionalWhereClause; } -- 2.25.1