From 4e5d12a13979fadc365f134d2e6ef68f59605090 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 7 Feb 2017 11:12:27 +1100 Subject: [PATCH] Reduce number of API queries and use IN on the status check as per comment from Eileen --- api/v3/GroupContact.php | 7 +++---- tests/phpunit/api/v3/GroupContactTest.php | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/api/v3/GroupContact.php b/api/v3/GroupContact.php index 79e9e351e1..2528c827cb 100644 --- a/api/v3/GroupContact.php +++ b/api/v3/GroupContact.php @@ -148,10 +148,10 @@ function civicrm_api3_group_contact_create($params) { function civicrm_api3_group_contact_delete($params) { $checkParams = $params; if (!empty($checkParams['status']) && in_array($checkParams['status'], array('Removed', 'Deleted'))) { - $checkParams['status'] = 'Added'; + $checkParams['status'] = array('IN' => array('Added', 'Pending')); } elseif (!empty($checkParams['status']) && $checkParams['status'] == 'Added') { - $checkParams['status'] = 'Removed'; + $checkParams['status'] = array('IN' => array('Pending', 'Removed')); } elseif (!empty($checkParams['status'])) { unset($checkParams['status']); @@ -161,8 +161,7 @@ function civicrm_api3_group_contact_delete($params) { $checkParams['status'] = 'removed'; } $groupContact2 = civicrm_api3('GroupContact', 'get', $checkParams); - $groupContact3 = civicrm_api3('GroupContact', 'get', array_merge($checkParams, array('status' => 'Pending'))); - if ($groupContact['count'] == 0 && $groupContact2['count'] == 0 && $groupContact3['count'] == 0) { + if ($groupContact['count'] == 0 && $groupContact2['count'] == 0) { throw new API_Exception('Cannot Delete GroupContact'); } $params['status'] = CRM_Utils_Array::value('status', $params, empty($params['skip_undelete']) ? 'Removed' : 'Deleted'); diff --git a/tests/phpunit/api/v3/GroupContactTest.php b/tests/phpunit/api/v3/GroupContactTest.php index f32317bb76..c2c686871c 100644 --- a/tests/phpunit/api/v3/GroupContactTest.php +++ b/tests/phpunit/api/v3/GroupContactTest.php @@ -260,7 +260,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'status' => 'Removed')); } - /** * CRM-16945 duplicate groups are showing up when contacts are hard-added to child groups or smart groups. * -- 2.25.1