Skip to content

Commit

Permalink
Reduce number of API queries and use IN on the status check as per co…
Browse files Browse the repository at this point in the history
…mment from Eileen
  • Loading branch information
seamuslee001 committed Feb 7, 2017
1 parent 518dd0e commit 4f6fd3a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions api/v3/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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');
Expand Down

0 comments on commit 4f6fd3a

Please sign in to comment.