Skip to content

Commit

Permalink
Merge pull request #27383 from larssandergreen/Fix-SearchDisplay-totals
Browse files Browse the repository at this point in the history
dev/core#4559 Don't include test, template, deleted entities in SearchDisplay totals
  • Loading branch information
colemanw authored Sep 10, 2023
2 parents 545f1d1 + 01dd6e5 commit 5f7e0d7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Civi/Api4/Generic/AbstractGetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function selectRowCount() {
*
* @throws \CRM_Core_Exception
*/
protected function setDefaultWhereClause() {
public function setDefaultWhereClause() {
if (!$this->_itemsToGet('id')) {
$fields = $this->entityFields();
foreach ($fields as $field) {
Expand Down
1 change: 1 addition & 0 deletions ext/search_kit/Civi/Api4/Action/SearchDisplay/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected function processResult(\Civi\Api4\Result\SearchDisplayRunResult $resul
case 'tally':
unset($apiParams['orderBy'], $apiParams['limit']);
$api = Request::create($entityName, 'get', $apiParams);
$api->setDefaultWhereClause();
$query = new Api4SelectQuery($api);
$query->forceSelectId = FALSE;
$sql = $query->getSql();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,48 @@ public function testContributionAggregateCurrency():void {
$this->assertEquals('$250.00', $result[3]['columns'][0]['val']);
}

public function testContributionTotalCountWithTestAndTemplateContributions():void {
// Add a source here for the where below, as if we use id, we get the test and template contributions
$contributions = $this->saveTestRecords('Contribution', [
'records' => [
['is_test' => TRUE, 'source' => 'TestTemplate'],
['is_template' => TRUE, 'source' => 'TestTemplate'],
['source' => 'TestTemplate'],
],
]);

$params = [
'checkPermissions' => FALSE,
'return' => 'page:1',
'savedSearch' => [
'api_entity' => 'Contribution',
'api_params' => [
'version' => 4,
'select' => ['id'],
'where' => [['source', '=', 'TestTemplate']],
],
],
'display' => [
'settings' => [
'columns' => [
[
'type' => 'field',
'key' => 'id',
'tally' => [
'fn' => 'COUNT',
],
],
],
],
],
];

$return = civicrm_api4('SearchDisplay', 'run', $params);
$params['return'] = 'tally';
$total = civicrm_api4('SearchDisplay', 'run', $params);
$this->assertEquals($return->rowCount, $total[0]['id']);
}

public function testSelectEquations() {
$activities = $this->saveTestRecords('Activity', [
'records' => [
Expand Down

0 comments on commit 5f7e0d7

Please sign in to comment.