From 8f09975a425a71251bd95eed881e285199b17614 Mon Sep 17 00:00:00 2001 From: Jimmy Huang Date: Fri, 11 Oct 2024 17:21:53 +0800 Subject: [PATCH] refs #41550, fixes api group by should respect search mode --- CRM/Contact/BAO/Query.php | 7 ++++++- api/v3/Contribution.php | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index fcdb4b17b..1a9aa0403 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -3939,7 +3939,12 @@ static function apiQuery($params = NULL, $sql = "$select $from $where $having"; // add group by if ($query->_useGroupBy || $groupBy) { - $sql .= ' GROUP BY contact_a.id'; + if (isset($query->_groupByComponentClause) && !empty($query->_groupByComponentClause)) { + $sql .= $query->_groupByComponentClause; + } + else { + $sql .= ' GROUP BY contact_a.id'; + } } if (!empty($sort)) { $sql .= " ORDER BY $sort "; diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 31204a586..5eed0e088 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -155,10 +155,9 @@ function civicrm_api3_contribution_get($params) { $mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE; $additionalOptions = _civicrm_api3_get_options_from_params($params, TRUE); $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode); - $groupBy = 'civicrm_contribution.id'; // Get the contributions based on parameters passed in - $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, $additionalOptions, NULL, $mode, $returnProperties, $groupBy); + $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, $additionalOptions, NULL, $mode, $returnProperties, TRUE); if (!empty($contributions)) { foreach ($contributions as $id => $contribution) { $soft_params = array('contribution_id' => $id);