Skip to content

Commit

Permalink
Use provided params not POST
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Feb 17, 2023
1 parent 9eb4138 commit 23d1a06
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions CRM/Core/BAO/UFMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 23d1a06

Please sign in to comment.