* @deprecated
*/
function civicrm_api3_group_contact_delete($params) {
- $groupContact = civicrm_api3('GroupContact', 'get', $params);
- if ($groupContact['count'] == 0) {
+ $checkParams = $params;
+ if (!empty($checkParams['status']) && in_array($checkParams['status'], array('Removed', 'Deleted'))) {
+ $checkParams['status'] = 'Added';
+ }
+ elseif (!empty($checkParams['status']) && $checkParams['status'] == 'Added') {
+ $checkParams['status'] = 'Removed';
+ }
+ elseif (!empty($checkParams['status'])) {
+ unset($checkParams['status']);
+ }
+ $groupContact = civicrm_api3('GroupContact', 'get', $checkParams);
+ if ($groupContact['count'] == 0 && !empty($params['skip_undelete'])) {
+ $checkParams['status'] = 'removed';
+ }
+ $groupContact2 = civicrm_api3('GroupContact', 'get', $checkParams);
+ 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');
$this->assertArrayNotHasKey('id', $result);
}
+ /**
+ * CRM-19496 When id is used rather than contact_id and group_id ensure that remove function still works.
+ *
+ */
+ public function testDeleteWithId() {
+ $groupContactParams = array(
+ 'contact_id' => $this->_contactId,
+ 'group_id' => $this->_groupId1,
+ );
+ $groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams);
+ $params = array(
+ 'id' => $groupContact['id'],
+ 'status' => 'Removed',
+ );
+ $result = $this->callAPISuccess('group_contact', 'delete', $params);
+ $this->assertEquals($result['removed'], 1);
+ $this->assertEquals($result['total_count'], 1);
+ }
+
+ /**
+ * CRM-19496 When id is used rather than contact_id and group_id ensure that remove function still works.
+ *
+ */
+ public function testDeleteAndReAddWithId() {
+ $groupContactParams = array(
+ 'contact_id' => $this->_contactId,
+ 'group_id' => $this->_groupId1,
+ );
+ $groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams);
+ $params = array(
+ 'id' => $groupContact['id'],
+ 'status' => 'Removed',
+ );
+ $result = $this->callAPISuccess('group_contact', 'delete', $params);
+ $this->assertEquals($result['removed'], 1);
+ $this->assertEquals($result['total_count'], 1);
+ $params = array_merge($params, array('status' => 'Added'));
+ $result2 = $this->callAPISuccess('group_contact', 'delete', $params);
+ $this->assertEquals($result2['added'], 1);
+ $this->assertEquals($result2['total_count'], 1);
+ }
+
/**
* CRM-16945 duplicate groups are showing up when contacts are hard-added to child groups or smart groups.
*