From: Eileen McNaughton Date: Sat, 8 Jan 2022 01:01:55 +0000 (+1300) Subject: Increase GroupContact:create deprecation X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9fcf2eac63757b92de974810519ec016d3896adf;p=civicrm-core.git Increase GroupContact:create deprecation Note the v3 api does not call this & no-where in core calls it directly. --- diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index b6219c0bad..b1a900783d 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -487,61 +487,20 @@ SELECT * } /** - * 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); } /**