Skip to content

Commit

Permalink
Deprecate no return on activity get
Browse files Browse the repository at this point in the history
It turns out that the area most causey of civicrm#18968
is activity get calls with no 'return' - which should be less that the contact.get
ones so trying to deprecate no-return
  • Loading branch information
eileenmcnaughton committed Jun 16, 2021
1 parent df67838 commit 37167f0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions Civi/Test/Api3TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function callAPISuccess($entity, $action, $params = [], $checkAgainst = N
$params = array_merge([
'version' => $this->_apiversion,
'debug' => 1,
'return' => 'id',
],
$params
);
Expand Down
5 changes: 4 additions & 1 deletion api/v3/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ function civicrm_api3_activity_get($params) {
$options['return']['status_id'] = $options['return']['activity_date_time'] = 1;
$params['return'] = array_keys($options['return']);
}

if (!isset($params['return']) && !$options['is_count']) {
// https://github.com/civicrm/civicrm-core/pull/18968
CRM_Core_Error::deprecatedWarning('Not setting a return array is deprecated as it will fail on complex sites.');
}
$activities = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Activity', $sql);
if ($options['is_count']) {
return civicrm_api3_create_success($activities, $params, 'Activity', 'get');
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/ACLPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function setUpEntities($entity) {
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testGetActivityNoPermissions($version) {
public function testGetActivityNoPermissions(int $version): void {
$this->_apiversion = $version;
$this->setPermissions([]);
$this->callAPISuccess('Activity', 'get');
Expand All @@ -620,7 +620,7 @@ public function testGetActivityNoPermissions($version) {
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityViewAllActivitiesDoesntCutItAnymore($version) {
public function testGetActivityViewAllActivitiesDoesntCutItAnymore(int $version): void {
$this->_apiversion = $version;
$activity = $this->activityCreate();
$this->setPermissions(['view all activities', 'access CiviCRM']);
Expand Down
18 changes: 11 additions & 7 deletions tests/phpunit/api/v3/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1311,15 +1311,17 @@ public function testActivityUpdateKeepSource() {

/**
* Test civicrm_activities_contact_get()
*
* @throws \CRM_Core_Exception
*/
public function testActivitiesContactGet() {
public function testActivitiesContactGet(): void {
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
$activity2 = $this->callAPISuccess('activity', 'create', $this->_params2);
// Get activities associated with contact $this->_contactID.
$params = [
$result = $this->callAPISuccess('Activity', 'get', [
'contact_id' => $this->_contactID,
];
$result = $this->callAPISuccess('activity', 'get', $params);
'return' => ['activity_type_id', 'activity_name'],
]);

$this->assertEquals(2, $result['count']);
$this->assertEquals($this->test_activity_type_value, $result['values'][$activity['id']]['activity_type_id']);
Expand All @@ -1329,11 +1331,13 @@ public function testActivitiesContactGet() {

/**
* Test chained Activity format.
*
* @throws \CRM_Core_Exception
*/
public function testChainedActivityGet() {
public function testChainedActivityGet(): void {

$activity = $this->callAPISuccess('Contact', 'Create', [
'display_name' => "bob brown",
'display_name' => 'bob brown',
'contact_type' => 'Individual',
'api.activity_type.create' => [
'weight' => '2',
Expand All @@ -1349,7 +1353,7 @@ public function testChainedActivityGet() {
],
]);

$result = $this->callAPISuccess('Activity', 'Get', [
$this->callAPISuccess('Activity', 'Get', [
'id' => $activity['id'],
'return.assignee_contact_id' => 1,
'api.contact.get' => ['api.pledge.get' => 1],
Expand Down

0 comments on commit 37167f0

Please sign in to comment.