From 0e0807631a44e97da509cc11f4317fb1a3b6f2de Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Wed, 2 Aug 2017 13:54:20 -0400 Subject: [PATCH] CRM-20790 - ensure relationships are created on import --- CRM/Contact/Import/Parser/Contact.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 3f220681481..064fd3c07b8 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -560,7 +560,12 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) { // check for the contact_id & type. $error = _civicrm_api3_deprecated_duplicate_formatted_contact($formatted); if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) { - $matchedIDs = explode(',', $error['error_message']['params'][0]); + if (is_array($error['error_message']['params'][0])) { + $matchedIDs = $error['error_message']['params'][0]; + } + else { + $matchedIDs = explode(',', $error['error_message']['params'][0]); + } if (count($matchedIDs) >= 1) { $updateflag = TRUE; foreach ($matchedIDs as $contactId) { @@ -736,8 +741,8 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) { if ($relationship) { $primaryContactId = NULL; if (CRM_Core_Error::isAPIError($newContact, CRM_Core_ERROR::DUPLICATE_CONTACT)) { - if (CRM_Utils_Rule::integer($newContact['error_message']['params'][0])) { - $primaryContactId = $newContact['error_message']['params'][0]; + if ($dupeCount == 1 && CRM_Utils_Rule::integer($contactID)) { + $primaryContactId = $contactID; } } else { @@ -851,7 +856,10 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) { // otherwise get contact Id from object of related contact if (is_array($relatedNewContact) && civicrm_error($relatedNewContact)) { if (CRM_Core_Error::isAPIError($relatedNewContact, CRM_Core_ERROR::DUPLICATE_CONTACT)) { - $matchedIDs = explode(',', $relatedNewContact['error_message']['params'][0]); + $matchedIDs = $relatedNewContact['error_message']['params'][0]; + if (!is_array($matchedIDs)) { + $matchedIDs = explode(',', $matchedIDs); + } } else { $errorMessage = $relatedNewContact['error_message']; @@ -1050,6 +1058,9 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) { } $contactID = $newContact['error_message']['params'][0]; + if (is_array($contactID)) { + $contactID = array_pop($contactID); + } if (!in_array($contactID, $this->_newContacts)) { $this->_newContacts[] = $contactID; }