Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where getsingle calls chained actions twice #13406

Merged
merged 2 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Civi/API/Provider/MagicFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ public function invoke($apiRequest) {
// Unlike normal API implementations, generic implementations require explicit
// knowledge of the entity and action (as well as $params). Bundle up these bits
// into a convenient data structure.
if ($apiRequest['action'] === 'getsingle') {
// strip any api nested parts here as otherwise chaining may happen twice
// see https://lab.civicrm.org/dev/core/issues/643
// testCreateBAODefaults fails without this.
foreach ($apiRequest['params'] as $key => $param) {
if ($key !== 'api.has_parent' && substr($key, 0, 4) === 'api.' || substr($key, 0, 4) === 'api_') {
unset($apiRequest['params'][$key]);
}
}
}
$result = $function($apiRequest);

}
elseif ($apiRequest['function'] && !$apiRequest['is_generic']) {
$result = $function($apiRequest['params']);
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function civicrm_api3_contribution_delete($params) {
return civicrm_api3_create_success(array($contributionID => 1));
}
else {
return civicrm_api3_create_error('Could not delete contribution');
throw new API_Exception('Could not delete contribution');
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,19 @@ public function testCreateBAODefaults() {
));
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('Check', $contribution['payment_instrument']);
$this->callAPISuccessGetCount('Contribution', ['id' => $contribution['id']], 0);
}

/**
* Test that getsingle can be chained with delete.
*/
public function testDeleteChainedGetSingle() {
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
$contribution = $this->callAPISuccess('contribution', 'getsingle', array(
'id' => $contribution['id'],
'api.contribution.delete' => 1,
));
$this->callAPISuccessGetCount('Contribution', ['id' => $contribution['id']], 0);
}

/**
Expand Down