Skip to content

Commit

Permalink
CRM-19830 removing cruft from query object forces it into the api som…
Browse files Browse the repository at this point in the history
…etimes.

Honour test contract
  • Loading branch information
eileenmcnaughton committed Jan 4, 2017
1 parent 859f195 commit c582a7d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 0 additions & 2 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,6 @@ public function selectClause($apiEntity = NULL) {
(substr($name, 0, 12) == 'participant_') ||
(substr($name, 0, 7) == 'pledge_') ||
(substr($name, 0, 5) == 'case_') ||
(substr($name, 0, 13) == 'contribution_' &&
(strpos($name, 'source') !== FALSE && strpos($name, 'recur') !== FALSE)) ||
(substr($name, 0, 8) == 'payment_')
) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public static function defaultReturnProperties($mode, $includeCustomFields = TRU
// kittens
'payment_instrument_id' => 1,
// argh
'check_number' => 1,
'contribution_check_number' => 1,
// no
'non_deductible_amount' => 1,
// not
Expand Down
27 changes: 26 additions & 1 deletion api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ function _civicrm_api3_contribution_delete_spec(&$params) {
function civicrm_api3_contribution_get($params) {

$mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
$additionalOptions = _civicrm_api3_contribution_get_support_nonunique_returns($params);
$returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode);

$contributions = _civicrm_api3_get_using_query_object('Contribution', $params, array(), NULL, $mode, $returnProperties);
$contributions = _civicrm_api3_get_using_query_object('Contribution', $params, $additionalOptions, NULL, $mode, $returnProperties);

foreach ($contributions as $id => $contribution) {
$softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id, TRUE);
Expand All @@ -255,6 +256,30 @@ function civicrm_api3_contribution_get($params) {
return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get');
}

/**
* Fix the return values to reflect cases where the schema has been changed.
*
* At the query object level using uniquenames dismbiguates between tables.
*
* However, adding uniquename can change inputs accepted by the api, so we need
* to ensure we are asking for the unique name return fields.
*
* @param array $additionalOptions
*
* @return array
* @throws \API_Exception
*/
function _civicrm_api3_contribution_get_support_nonunique_returns($params) {
$additionalOptions = array();
$options = _civicrm_api3_get_options_from_params($params, TRUE);
foreach (array('check_number', 'address_id') as $changedVariable) {
if (isset($options['return']) && !empty($options['return'][$changedVariable])) {
$additionalOptions['return']['contribution_' . $changedVariable] = 1;
}
}
return $additionalOptions;
}

/**
* Support for supported output variables.
*
Expand Down

0 comments on commit c582a7d

Please sign in to comment.