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-21809: 'Advance search' group by issue #11728

Merged
merged 1 commit into from
Feb 27, 2018
Merged
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
7 changes: 4 additions & 3 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4710,7 +4710,7 @@ public static function filterCountryFromValuesIfStateExists(&$formValues) {
public static function appendAnyValueToSelect($selectClauses, $groupBy, $aggregateFunction = 'ANY_VALUE') {
if (!CRM_Utils_SQL::disableFullGroupByMode()) {
$groupBy = array_map('trim', (array) $groupBy);
$aggregateFunctions = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN)\(/i';
$aggregateFunctions = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN|IF)[[:blank:]]*\(/i';
foreach ($selectClauses as $key => &$val) {
list($selectColumn, $alias) = array_pad(preg_split('/ as /i', $val), 2, NULL);
// append ANY_VALUE() keyword
Expand Down Expand Up @@ -4761,7 +4761,7 @@ public static function getGroupByFromSelectColumns($selectClauses, $groupBy = NU

//return if ONLY_FULL_GROUP_BY is not enabled.
if (CRM_Utils_SQL::supportsFullGroupBy() && !empty($sqlMode) && in_array('ONLY_FULL_GROUP_BY', explode(',', $sqlMode))) {
$regexToExclude = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN)\(/i';
$regexToExclude = '/(ROUND|AVG|COUNT|GROUP_CONCAT|SUM|MAX|MIN|IF)[[:blank:]]*\(/i';
foreach ($selectClauses as $key => $val) {
$aliasArray = preg_split('/ as /i', $val);
// if more than 1 alias we need to split by ','.
Expand Down Expand Up @@ -4961,7 +4961,8 @@ public function getCachedContacts($cacheKey, $offset, $rowCount, $includeContact
$from = " FROM civicrm_prevnext_cache pnc INNER JOIN civicrm_contact contact_a ON contact_a.id = pnc.entity_id1 AND pnc.cacheKey = '$cacheKey' " . substr($from, 31);
$order = " ORDER BY pnc.id";
$groupByCol = array('contact_a.id', 'pnc.id');
$groupBy = self::getGroupByFromSelectColumns($this->_select, $groupByCol);
$select = self::appendAnyValueToSelect($this->_select, $groupByCol, 'GROUP_CONCAT');
$groupBy = " GROUP BY " . implode(', ', $groupByCol);
$limit = " LIMIT $offset, $rowCount";
$query = "$select $from $where $groupBy $order $limit";

Expand Down