From d7a896b4ae53357064936464a1983dd102905151 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 7 Jul 2019 18:25:19 +1200 Subject: [PATCH] dev/core#1081 fix for error on contribution detail when using custom data order by without select --- CRM/Report/Form.php | 2 +- CRM/Report/Form/Contribute/Summary.php | 2 ++ .../CRMTraits/Custom/CustomDataTrait.php | 1 + tests/phpunit/api/v3/ReportTemplateTest.php | 23 ++++++++++++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 8ee80e9800..b1e0a06d3f 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -5929,7 +5929,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a if ($this->groupConcatTested && (!empty($this->_groupByArray) || $this->isForceGroupBy)) { if ((empty($field['statistics']) || in_array('GROUP_CONCAT', $field['statistics']))) { $label = CRM_Utils_Array::value('title', $field); - $alias = "{$tableName}_{$fieldName}"; + $alias = $field['tplField'] ?? "{$tableName}_{$fieldName}"; $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $label; $this->_selectAliases[] = $alias; if (empty($this->_groupByArray[$tableName . '_' . $fieldName])) { diff --git a/CRM/Report/Form/Contribute/Summary.php b/CRM/Report/Form/Contribute/Summary.php index e6756091e1..e193637490 100644 --- a/CRM/Report/Form/Contribute/Summary.php +++ b/CRM/Report/Form/Contribute/Summary.php @@ -740,7 +740,9 @@ ROUND(AVG({$this->_aliases['civicrm_contribution_soft']}.amount), 2) as civicrm_ * @param array $rows */ public function buildRows($sql, &$rows) { + CRM_Core_DAO::disableFullGroupByMode(); $dao = CRM_Core_DAO::executeQuery($sql); + CRM_Core_DAO::reenableFullGroupByMode(); $this->addToDeveloperTab($sql); if (!is_array($rows)) { $rows = array(); diff --git a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php index 541abd0b10..af0e193684 100644 --- a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php +++ b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php @@ -223,6 +223,7 @@ trait CRMTraits_Custom_CustomDataTrait { 'weight' => 1, 'is_required' => 1, 'sequential' => 1, + 'is_searchable' => 1, ], $params); return $this->callAPISuccess('CustomField', 'create', $params)['values'][0]; diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index eb87d944b7..beae3d5b16 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -36,6 +36,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { use CRMTraits_ACL_PermissionTrait; use CRMTraits_PCP_PCPTestTrait; + use CRMTraits_Custom_CustomDataTrait; protected $contactIDs = []; @@ -46,7 +47,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_group', 'civicrm_saved_search', 'civicrm_group_contact', 'civicrm_group_contact_cache', 'civicrm_group')); + $this->quickCleanup(['civicrm_group', 'civicrm_saved_search', 'civicrm_group_contact', 'civicrm_group_contact_cache', 'civicrm_group'], TRUE); parent::tearDown(); } @@ -913,6 +914,26 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { } } + /** + * Test the custom data order by works when not in select. + * + * @dataProvider getMembershipAndContributionReportTemplatesForGroupTests + * + * @param string $template + * Report template unique identifier. + * + * @throws \CRM_Core_Exception + */ + public function testReportsCustomDataOrderBy($template) { + $this->entity = 'Contact'; + $this->createCustomGroupWithFieldOfType(); + $this->callAPISuccess('report_template', 'getrows', [ + 'report_id' => $template, + 'contribution_or_soft_value' => 'contributions_only', + 'order_bys' => [['column' => 'custom_' . $this->ids['CustomField']['text'], 'order' => 'ASC']], + ]); + } + /** * Test the group filter works on the various reports. * -- 2.25.1