Skip to content

Commit

Permalink
Merge pull request #23634 from eileenmcnaughton/import_unreach
Browse files Browse the repository at this point in the history
Remove legacy calls to `civicrm_error`, unpack return
  • Loading branch information
eileenmcnaughton authored May 31, 2022
2 parents 8b6aa95 + 085927a commit 7b9c5c9
Showing 1 changed file with 15 additions and 40 deletions.
55 changes: 15 additions & 40 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function import($onDuplicate, &$values) {
$this->_retCode = CRM_Import_Parser::VALID;
}
}
elseif (CRM_Core_Error::isAPIError($newContact, CRM_Core_Error::DUPLICATE_CONTACT)) {
elseif (is_array($newContact)) {
// if duplicate, no need of further processing
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
$errorMessage = "Skipping duplicate record";
Expand Down Expand Up @@ -372,7 +372,7 @@ public function import($onDuplicate, &$values) {
}

$primaryContactId = NULL;
if (CRM_Core_Error::isAPIError($newContact, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
if (is_array($newContact)) {
if ($dupeCount == 1 && CRM_Utils_Rule::integer($contactID)) {
$primaryContactId = $contactID;
}
Expand All @@ -381,7 +381,7 @@ public function import($onDuplicate, &$values) {
$primaryContactId = $newContact->id;
}

if ((CRM_Core_Error::isAPIError($newContact, CRM_Core_ERROR::DUPLICATE_CONTACT) || is_a($newContact, 'CRM_Contact_BAO_Contact')) && $primaryContactId) {
if ((is_array($newContact) || is_a($newContact, 'CRM_Contact_BAO_Contact')) && $primaryContactId) {

//relationship contact insert
foreach ($this->getRelatedContactsParams($params) as $key => $field) {
Expand Down Expand Up @@ -419,18 +419,10 @@ public function import($onDuplicate, &$values) {
$matchedIDs = [];
// To update/fill contact, get the matching contact Ids if duplicate contact found
// 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 = $relatedNewContact['error_message']['params'][0];
if (!is_array($matchedIDs)) {
$matchedIDs = explode(',', $matchedIDs);
}
}
else {
$errorMessage = $relatedNewContact['error_message'];
array_unshift($values, $errorMessage);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;
if (is_array($relatedNewContact)) {
$matchedIDs = $relatedNewContact['error_message']['params'][0];
if (!is_array($matchedIDs)) {
$matchedIDs = explode(',', $matchedIDs);
}
}
else {
Expand All @@ -454,11 +446,11 @@ public function import($onDuplicate, &$values) {
return CRM_Import_Parser::NO_MATCH;
}
else {
$updatedContact = $this->createContact($formatting, $contactFields, $onDuplicate, $matchedIDs[0]);
$this->createContact($formatting, $contactFields, $onDuplicate, $matchedIDs[0]);
}
}
static $relativeContact = [];
if (CRM_Core_Error::isAPIError($relatedNewContact, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
if (is_array($relatedNewContact)) {
if (count($matchedIDs) >= 1) {
$relContactId = $matchedIDs[0];
//add relative contact to count during update & fill mode.
Expand All @@ -480,7 +472,7 @@ public function import($onDuplicate, &$values) {
$this->_newRelatedContacts[] = $relativeContact[] = $relContactId;
}

if (CRM_Core_Error::isAPIError($relatedNewContact, CRM_Core_ERROR::DUPLICATE_CONTACT) || ($relatedNewContact instanceof CRM_Contact_BAO_Contact)) {
if (is_array($relatedNewContact) || ($relatedNewContact instanceof CRM_Contact_BAO_Contact)) {
//fix for CRM-1993.Checks for duplicate related contacts
if (count($matchedIDs) >= 1) {
//if more than one duplicate contact
Expand Down Expand Up @@ -543,18 +535,8 @@ public function import($onDuplicate, &$values) {
return $this->processMessage($values, $this->_retCode);
}
//dupe checking
if (is_array($newContact) && civicrm_error($newContact)) {
$code = NULL;

if (($code = CRM_Utils_Array::value('code', $newContact['error_message'])) && ($code == CRM_Core_Error::DUPLICATE_CONTACT)) {
return $this->handleDuplicateError($newContact, $values, $onDuplicate, $formatted, $contactFields);
}
// Not a dupe, so we had an error
$errorMessage = $newContact['error_message'];
array_unshift($values, $errorMessage);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;

if (is_array($newContact)) {
return $this->handleDuplicateError($newContact, $values, $onDuplicate, $formatted, $contactFields);
}

if (empty($this->_unparsedStreetAddressContacts)) {
Expand Down Expand Up @@ -1141,7 +1123,8 @@ public static function addToErrorMsg($errorName, &$errorMessage) {
* @param bool $requiredCheck
* @param int $dedupeRuleGroupID
*
* @return array|bool|\CRM_Contact_BAO_Contact|\CRM_Core_Error|null
* @return array|\CRM_Contact_BAO_Contact
* If a duplicate is found an array is returned, otherwise CRM_Contact_BAO_Contact
*/
public function createContact(&$formatted, &$contactFields, $onDuplicate, $contactId = NULL, $requiredCheck = TRUE, $dedupeRuleGroupID = NULL) {
$dupeCheck = FALSE;
Expand Down Expand Up @@ -1784,15 +1767,7 @@ private function handleDuplicateError(array $newContact, array $values, int $onD
$newContact = CRM_Contact_BAO_Contact::retrieve($contact, $defaults);
}

if (civicrm_error($newContact)) {
if (empty($newContact['error_message']['params'])) {
// different kind of error other than DUPLICATE
$errorMessage = $newContact['error_message'];
array_unshift($values, $errorMessage);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;
}

if (is_array($newContact)) {
$contactID = $newContact['error_message']['params'][0];
if (is_array($contactID)) {
$contactID = array_pop($contactID);
Expand Down

0 comments on commit 7b9c5c9

Please sign in to comment.