Reduce number of API queries and use IN on the status check as per comment from Eileen
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 7 Feb 2017 00:12:27 +0000 (11:12 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 7 Feb 2017 03:32:33 +0000 (14:32 +1100)
api/v3/GroupContact.php
tests/phpunit/api/v3/GroupContactTest.php

index 79e9e351e17e68600d774100cbdb5cf229b58248..2528c827cbb4254909a6bf45aff8ef2cb7d13375 100644 (file)
@@ -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');
index f32317bb767125ec01e15f161723c8a76f05e8b7..c2c686871c906a88d44e147d912a234a38514b0b 100644 (file)
@@ -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.
    *