Skip to content
Snippets Groups Projects
Commit fe23695a authored by colemanw's avatar colemanw
Browse files

Api3 - Delete old GroupContact API functions (deprecated since 2014)

parent f8d10b75
No related branches found
No related tags found
No related merge requests found
......@@ -120,62 +120,6 @@ function civicrm_api3_group_contact_create($params) {
return _civicrm_api3_group_contact_common($params, $action);
}
/**
* Delete group contact record.
*
* @param array $params
* @return array
* @throws CRM_Core_Exception
* @throws CRM_Core_Exception
* @deprecated
*/
function civicrm_api3_group_contact_delete($params) {
$checkParams = $params;
if (!empty($checkParams['status']) && in_array($checkParams['status'], ['Removed', 'Deleted'])) {
$checkParams['status'] = ['IN' => ['Added', 'Pending']];
}
elseif (!empty($checkParams['status']) && $checkParams['status'] == 'Added') {
$checkParams['status'] = ['IN' => ['Pending', 'Removed']];
}
elseif (!empty($checkParams['status'])) {
unset($checkParams['status']);
}
$groupContact = civicrm_api3('GroupContact', 'get', $checkParams);
if ($groupContact['count'] == 0 && !empty($params['skip_undelete'])) {
$checkParams['status'] = ['IN' => ['Removed', 'Pending']];
}
$groupContact2 = civicrm_api3('GroupContact', 'get', $checkParams);
if ($groupContact['count'] == 0 && $groupContact2['count'] == 0) {
throw new CRM_Core_Exception('Cannot Delete GroupContact');
}
$params['status'] = CRM_Utils_Array::value('status', $params, empty($params['skip_undelete']) ? 'Removed' : 'Deleted');
// "Deleted" isn't a real option so skip the api wrapper to avoid pseudoconstant validation
return civicrm_api3_group_contact_create($params);
}
/**
* Adjust metadata.
*
* @param array $params
*/
function _civicrm_api3_group_contact_delete_spec(&$params) {
// set as not required no either/or std yet
$params['id']['api.required'] = 0;
}
/**
* Get pending group contacts.
*
* @param array $params
*
* @return array|int
* @deprecated
*/
function civicrm_api3_group_contact_pending($params) {
$params['status'] = 'Pending';
return civicrm_api('GroupContact', 'Create', $params);
}
/**
* Group contact helper function.
*
......@@ -256,43 +200,3 @@ function _civicrm_api3_group_contact_common($params, $op = 'Added') {
$dao = NULL;
return civicrm_api3_create_success(1, $params, 'GroupContact', 'create', $dao, $extraReturnValues);
}
/**
* Update group contact status.
*
* @deprecated - this should be part of create but need to know we aren't missing something
*
* @param array $params
*
* @return bool
* @throws \CRM_Core_Exception
*/
function civicrm_api3_group_contact_update_status($params) {
civicrm_api3_verify_mandatory($params, NULL, ['contact_id', 'group_id']);
CRM_Contact_BAO_GroupContact::addContactsToGroup(
[$params['contact_id']],
$params['group_id'],
$params['method'] ?? 'API',
'Added',
$params['tracking'] ?? NULL
);
return TRUE;
}
/**
* Deprecated function notices.
*
* @deprecated api notice
* @return array
* Array of deprecated actions
*/
function _civicrm_api3_group_contact_deprecation() {
return [
'delete' => 'GroupContact "delete" action is deprecated in favor of "create".',
'pending' => 'GroupContact "pending" action is deprecated in favor of "create".',
'update_status' => 'GroupContact "update_status" action is deprecated in favor of "create".',
];
}
......@@ -9,8 +9,6 @@
+--------------------------------------------------------------------+
*/
use Civi\Api4\SubscriptionHistory;
/**
* Class api_v3_GroupContactTest
* @group headless
......@@ -143,141 +141,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase {
$this->assertEquals(2, $result['total_count']);
}
/**
* Test GroupContact.delete by contact+group ID.
*/
public function testDelete(): void {
$params = [
'contact_id' => $this->contactID,
'group_id' => $this->groupID1,
];
$result = $this->callAPISuccess('group_contact', 'delete', $params);
$this->assertEquals(1, $result['removed']);
$this->assertEquals(1, $result['total_count']);
}
public function testDeletePermanent(): void {
$result = $this->callAPISuccess('group_contact', 'get', ['contact_id' => $this->contactID]);
$params = [
'id' => $result['id'],
'skip_undelete' => TRUE,
];
$this->callAPISuccess('group_contact', 'delete', $params);
$result = $this->callAPISuccess('group_contact', 'get', $params);
$this->assertEquals(0, $result['count']);
$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(): void {
$groupContactParams = [
'contact_id' => $this->contactID,
'group_id' => $this->groupID1,
];
$groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams);
$params = [
'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(): void {
$groupContactParams = [
'contact_id' => $this->contactID,
'group_id' => $this->groupID1,
];
$groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams);
$params = [
'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, ['status' => 'Added']);
$result2 = $this->callAPISuccess('group_contact', 'delete', $params);
$this->assertEquals($result2['added'], 1);
$this->assertEquals($result2['total_count'], 1);
}
/**
* CRM-19979 test that group contact delete action works when contact is in
* status of pending.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testDeleteWithPending(int $version): void {
$this->_apiversion = $version;
$groupId3 = $this->groupCreate([
'name' => 'Test Group 3',
'domain_id' => 1,
'title' => 'New Test Group3 Created',
'description' => 'New Test Group3 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
]);
$groupContactCreateParams = [
'contact_id' => $this->contactID,
'group_id' => $groupId3,
'status' => 'Pending',
];
$this->callAPISuccess('GroupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('GroupContact', 'get', $groupContactCreateParams);
$history = SubscriptionHistory::get()
->addSelect('*')
->addWhere('group_id', '=', $groupId3)
->addWhere('status', '=', 'Pending')
->addWhere('contact_id', '=', $this->contactID)
->execute();
$this->assertCount(1, $history);
if ($version === 3) {
$this->callAPISuccess('GroupContact', 'delete', [
'id' => $groupGetContact['id'],
'status' => 'Removed',
]);
}
$this->callAPISuccess('GroupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]);
$this->callAPISuccess('Group', 'delete', ['id' => $groupId3]);
}
/**
* CRM-19979 test that group cotnact delete action works when contact is in status of pendin and is a permanent delete.
*/
public function testPermanentDeleteWithPending(): void {
$groupId3 = $this->groupCreate([
'name' => 'Test Group 3',
'domain_id' => 1,
'title' => 'New Test Group3 Created',
'description' => 'New Test Group3 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
]);
$groupContactCreateParams = [
'contact_id' => $this->contactID,
'group_id' => $groupId3,
'status' => 'Pending',
];
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
$this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]);
$this->callAPISuccess('group', 'delete', ['id' => $groupId3]);
}
/**
* CRM-16945 duplicate groups are showing up when contacts are hard-added to child groups or smart groups.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment