Skip to content

Commit

Permalink
Merge pull request #19842 from eileenmcnaughton/task
Browse files Browse the repository at this point in the history
[unreleased regression] Fix export contribution to share tasktrait
  • Loading branch information
colemanw authored Mar 21, 2021
2 parents 38a9df9 + 5b43eb5 commit 1c63499
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CRM/Contribute/Export/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
*/
class CRM_Contribute_Export_Form_Select extends CRM_Export_Form_Select {

use CRM_Contribute_Form_Task_TaskTrait;

/**
* Call the pre-processing function.
*
* @throws \CRM_Core_Exception
*/
protected function callPreProcessing(): void {
CRM_Contribute_Form_Task::preProcessCommon($this);
Expand Down
56 changes: 2 additions & 54 deletions CRM/Contribute/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {

use CRM_Contribute_Form_Task_TaskTrait;

/**
* The array that holds all the contribution ids.
*
Expand All @@ -42,60 +44,6 @@ class CRM_Contribute_Form_Task extends CRM_Core_Form_Task {
*/
public $_includesSoftCredits = FALSE;

/**
* Get the results from the BAO_Query object based search.
*
* @return CRM_Core_DAO
*
* @throws \CRM_Core_Exception
*/
public function getSearchQueryResults(): CRM_Core_DAO {
$form = $this;
$queryParams = $form->get('queryParams');
$isTest = FALSE;
if (is_array($queryParams)) {
foreach ($queryParams as $fields) {
if ($fields[0] === 'contribution_test') {
$isTest = TRUE;
break;
}
}
}
if (!$isTest) {
$queryParams[] = [
'contribution_test',
'=',
0,
0,
0,
];
}
$returnProperties = ['contribution_id' => 1];
$sortOrder = $sortCol = NULL;
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
//Include sort column in select clause.
$sortCol = trim(str_replace(['`', 'asc', 'desc'], '', $sortOrder));
$returnProperties[$sortCol] = 1;
}

$form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CONTRIBUTE
);
// @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this
// can we remove? if not why not?
if ($form->_includesSoftCredits) {
$query->_rowCountClause = " count(civicrm_contribution.id)";
$query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
}
else {
$query->_distinctComponentClause = ' civicrm_contribution.id';
$query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id ';
}
return $query->searchQuery(0, 0, $sortOrder);
}

/**
* Build all the data structures needed to build the form.
*/
Expand Down
77 changes: 77 additions & 0 deletions CRM/Contribute/Form/Task/TaskTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* This class provides shared contribution task functionality.
*/
trait CRM_Contribute_Form_Task_TaskTrait {

/**
* Get the results from the BAO_Query object based search.
*
* @return CRM_Core_DAO
*
* @throws \CRM_Core_Exception
*/
public function getSearchQueryResults(): CRM_Core_DAO {
$form = $this;
$queryParams = $form->get('queryParams');
$isTest = FALSE;
if (is_array($queryParams)) {
foreach ($queryParams as $fields) {
if ($fields[0] === 'contribution_test') {
$isTest = TRUE;
break;
}
}
}
if (!$isTest) {
$queryParams[] = [
'contribution_test',
'=',
0,
0,
0,
];
}
$returnProperties = ['contribution_id' => 1];
$sortOrder = $sortCol = NULL;
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
//Include sort column in select clause.
$sortCol = trim(str_replace(['`', 'asc', 'desc'], '', $sortOrder));
$returnProperties[$sortCol] = 1;
}

$form->_includesSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
$query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CONTRIBUTE
);
// @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this
// can we remove? if not why not?
if ($form->_includesSoftCredits) {
$query->_rowCountClause = " count(civicrm_contribution.id)";
$query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
}
else {
$query->_distinctComponentClause = ' civicrm_contribution.id';
$query->_groupByComponentClause = ' GROUP BY civicrm_contribution.id ';
}
return $query->searchQuery(0, 0, $sortOrder);
}

}

0 comments on commit 1c63499

Please sign in to comment.