From 37167f0de1c5682c972b0f3439ed775074c655f4 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 16 Jun 2021 15:41:50 +1200 Subject: [PATCH] Deprecate no return on activity get It turns out that the area most causey of https://github.com/civicrm/civicrm-core/pull/18968 is activity get calls with no 'return' - which should be less that the contact.get ones so trying to deprecate no-return --- Civi/Test/Api3TestTrait.php | 1 + api/v3/Activity.php | 5 ++++- tests/phpunit/api/v3/ACLPermissionTest.php | 4 ++-- tests/phpunit/api/v3/ActivityTest.php | 18 +++++++++++------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index f544be76f255..131e982a1c2e 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -159,6 +159,7 @@ public function callAPISuccess($entity, $action, $params = [], $checkAgainst = N $params = array_merge([ 'version' => $this->_apiversion, 'debug' => 1, + 'return' => 'id', ], $params ); diff --git a/api/v3/Activity.php b/api/v3/Activity.php index 422ebff5905d..20a34a7e382d 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -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'); diff --git a/tests/phpunit/api/v3/ACLPermissionTest.php b/tests/phpunit/api/v3/ACLPermissionTest.php index 35ef4147be83..bcc478035b25 100644 --- a/tests/phpunit/api/v3/ACLPermissionTest.php +++ b/tests/phpunit/api/v3/ACLPermissionTest.php @@ -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'); @@ -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']); diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index 082f14271446..732d57127f8d 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -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']); @@ -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', @@ -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],