Use provided params not POST
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 10 Feb 2023 04:49:06 +0000 (17:49 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 17 Feb 2023 02:23:57 +0000 (15:23 +1300)
CRM/Core/BAO/UFMatch.php

index 8100e72a3172c9a460521b97308fa5aa93299191..0d8ece931b645cfdf11608975b46b1c3daca03d7 100644 (file)
@@ -179,16 +179,16 @@ class CRM_Core_BAO_UFMatch extends CRM_Core_DAO_UFMatch {
 
       $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 @@ AND    domain_id = %2
       }
 
       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 @@ AND    domain_id = %2
           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;
       }