Skip to content

Commit

Permalink
Merge pull request #22416 from eileenmcnaughton/depit
Browse files Browse the repository at this point in the history
Increase GroupContact:create deprecation
  • Loading branch information
eileenmcnaughton authored Jan 8, 2022
2 parents 7d1a8cb + 9fcf2ea commit ec5b279
Showing 1 changed file with 8 additions and 49 deletions.
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

0 comments on commit ec5b279

Please sign in to comment.