From 23d1a064cf1b756c5628d41f434856ca310f40f5 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 10 Feb 2023 17:49:06 +1300 Subject: [PATCH] Use provided params not POST --- CRM/Core/BAO/UFMatch.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/CRM/Core/BAO/UFMatch.php b/CRM/Core/BAO/UFMatch.php index 8100e72a3172..0d8ece931b64 100644 --- a/CRM/Core/BAO/UFMatch.php +++ b/CRM/Core/BAO/UFMatch.php @@ -179,16 +179,16 @@ public static function &synchronizeUFMatch(&$user, $userKey, $uniqId, $uf, $stat $dao = NULL; if (!empty($_POST) && !$isLogin) { - $params = $_POST; - $params['email'] = $uniqId; + $dedupeParameters = $_POST; + $dedupeParameters['email'] = $uniqId; // dev/core#1858 Ensure that if we have a contactID parameter which is set in the Create user Record contact task form - // That this contacID value is passed through as the contact_id to the get duplicate contacts function. This is necessary because for Drupal 8 this function gets invoked + // That this contactID value is passed through as the contact_id to the get duplicate contacts function. This is necessary because for Drupal 8 this function gets invoked // Before the civicrm_uf_match record is added where as in D7 it isn't called until the user tries to actually login. - if (!empty($params['contactID'])) { - $params['contact_id'] = $params['contactID']; + if (!empty($dedupeParameters['contactID'])) { + $dedupeParameters['contact_id'] = $dedupeParameters['contactID']; } - $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, 'Individual', 'Unsupervised', [], FALSE); + $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($dedupeParameters, 'Individual', 'Unsupervised', [], FALSE); if (!empty($ids) && Civi::settings()->get('uniq_email_per_site')) { // restrict dupeIds to ones that belong to current domain/site. @@ -235,6 +235,7 @@ public static function &synchronizeUFMatch(&$user, $userKey, $uniqId, $uf, $stat } if (!$found) { + $contactParameters = []; // Not sure why we're testing for this. Is there ever a case // in which $user is not an object? if (is_object($user)) { @@ -247,36 +248,39 @@ public static function &synchronizeUFMatch(&$user, $userKey, $uniqId, $uf, $stat else { $primary_email = $user->email; } - $params['email'] = $primary_email; + $contactParameters['email'] = $primary_email; + } + else { + CRM_Core_Error::deprecatedWarning('please log how you hit this...'); } if ($ctype === 'Organization') { - $params['organization_name'] = $uniqId; + $contactParameters['organization_name'] = $uniqId; } elseif ($ctype === 'Household') { - $params['household_name'] = $uniqId; + $contactParameters['household_name'] = $uniqId; } - $params['contact_type'] = $ctype ?? 'Individual'; + $contactParameters['contact_type'] = $ctype ?? 'Individual'; // extract first / middle / last name // for joomla if ($uf === 'Joomla' && $user->name) { - CRM_Utils_String::extractName($user->name, $params); + CRM_Utils_String::extractName($user->name, $dedupeParameters); } if ($uf === 'WordPress') { if ($user->first_name) { - $params['first_name'] = $user->first_name; + $contactParameters['first_name'] = $user->first_name; } if ($user->last_name) { - $params['last_name'] = $user->last_name; + $contactParameters['last_name'] = $user->last_name; } } - $contactId = civicrm_api3('Contact', 'create', $params)['id']; - $ufmatch->contact_id = $contactId; + $contactID = civicrm_api3('Contact', 'create', $contactParameters)['id']; + $ufmatch->contact_id = $contactID; $ufmatch->uf_name = $uniqId; }