Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase GroupContact:create deprecation #22416

Merged
merged 1 commit into from
Jan 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 8 additions & 49 deletions CRM/Contact/BAO/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,61 +487,20 @@ public static function getGroupId($groupContactID) {
}

/**
* Creates / removes contacts from the groups
* Deprecated create function.
*
* @deprecated
*
* @param array $params
* Name/value pairs.
* @param int $contactId
* Contact id.
* @param bool $ignorePermission
* if ignorePermission is true we are coming in via profile mean $method = 'Web'
* @param string $method
*
* @return CRM_Contact_BAO_GroupContact|void
* @return CRM_Contact_BAO_GroupContact
*/
public static function create($params, $contactId, $ignorePermission = FALSE, $method = 'Admin') {
if (empty($contactId)) {
return self::add($params);
}

public static function create(array $params) {
// @fixme create was only called from CRM_Contact_BAO_Contact::createProfileContact
// Now it's not called from anywhere so we can remove the below code after some time
CRM_Core_Error::deprecatedFunctionWarning('Use the GroupContact API');

$contactIds = [$contactId];
$contactGroup = [];

if ($contactId) {
$contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added',
NULL, FALSE, $ignorePermission
);
if (is_array($contactGroupList)) {
foreach ($contactGroupList as $key) {
$groupId = $key['group_id'];
$contactGroup[$groupId] = $groupId;
}
}
}

// get the list of all the groups
$allGroup = CRM_Contact_BAO_GroupContact::getGroupList(0, $ignorePermission);
// As of Aug 2020 it's not called from anywhere so we can remove the below code after some time

// this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
if (!is_array($params)) {
$params = [];
}

// check which values has to be add/remove contact from group
foreach ($allGroup as $key => $varValue) {
if (!empty($params[$key]) && !array_key_exists($key, $contactGroup)) {
// add contact to group
CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method);
}
elseif (empty($params[$key]) && array_key_exists($key, $contactGroup)) {
// remove contact from group
CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method);
}
}
CRM_Core_Error::deprecatedFunctionWarning('Use the GroupContact API');
return self::add($params);
}

/**
Expand Down