Skip to content

Commit

Permalink
Merge pull request #10808 from jmcclelland/CRM-20790
Browse files Browse the repository at this point in the history
CRM-20790 - ensure relationships are created on import
  • Loading branch information
eileenmcnaughton authored Aug 3, 2017
2 parents b52e215 + 0e08076 commit d7b136b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d7b136b

Please sign in to comment.