Skip to content

Commit

Permalink
Merge pull request #23293 from eileenmcnaughton/import_deprecated
Browse files Browse the repository at this point in the history
[REF] [Import] call non-deprecated function instead of deprecated
  • Loading branch information
seamuslee001 authored Apr 27, 2022
2 parents 67f1753 + 12d121e commit 3826621
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 69 deletions.
78 changes: 12 additions & 66 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
$statusFieldName = $this->_statusFieldName;

if ($response != CRM_Import_Parser::VALID) {
$importRecordParams = [
$statusFieldName => 'INVALID',
"${statusFieldName}Msg" => "Invalid (Error Code: $response)",
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'Invalid', "Invalid (Error Code: $response)");
return $response;
}

Expand Down Expand Up @@ -506,11 +502,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
else {
$errorMessage = ts('External ID already exists in Database.');
array_unshift($values, $errorMessage);
$importRecordParams = [
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::DUPLICATE;
}
}
Expand Down Expand Up @@ -547,7 +539,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;
}
foreach ($possibleMatches as $possibleID) {
Expand Down Expand Up @@ -704,11 +696,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
$errorMessage = "Skipping duplicate record";
array_unshift($values, $errorMessage);
$importRecordParams = [
$statusFieldName => 'DUPLICATE',
"${statusFieldName}Msg" => $errorMessage,
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'DUPLICATE', $errorMessage);
return CRM_Import_Parser::DUPLICATE;
}

Expand Down Expand Up @@ -865,11 +853,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
else {
$errorMessage = $relatedNewContact['error_message'];
array_unshift($values, $errorMessage);
$importRecordParams = [
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;
}
}
Expand Down Expand Up @@ -993,11 +977,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
// Not a dupe, so we had an error
$errorMessage = $newContact['error_message'];
array_unshift($values, $errorMessage);
$importRecordParams = [
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;

}
Expand Down Expand Up @@ -2091,9 +2071,7 @@ public static function formatCustomDate(&$params, &$formatted, $dateType, $dateP
*/
public function processMessage(&$values, $statusFieldName, $returnCode) {
if (empty($this->_unparsedStreetAddressContacts)) {
$importRecordParams = [
$statusFieldName => 'IMPORTED',
];
$this->setImportStatus((int) ($values[count($values) - 1]), 'IMPORTED', '');
}
else {
$errorMessage = ts("Record imported successfully but unable to parse the street address: ");
Expand All @@ -2102,13 +2080,9 @@ public function processMessage(&$values, $statusFieldName, $returnCode) {
$errorMessage .= "\n Contact ID:" . $contactValue['id'] . " <a href=\"$contactUrl\"> " . $contactValue['streetAddress'] . "</a>";
}
array_unshift($values, $errorMessage);
$importRecordParams = [
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];
$returnCode = CRM_Import_Parser::UNPARSED_ADDRESS_WARNING;
$this->setImportStatus((int) ($values[count($values) - 1]), 'ERROR', $errorMessage);
}
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
return $returnCode;
}

Expand Down Expand Up @@ -2303,15 +2277,10 @@ protected function handleDuplicateError(array $newContact, $statusFieldName, arr
// If we duplicate more than one record, skip no matter what
if (count($cids) > 1) {
$errorMessage = ts('Record duplicates multiple contacts');
$importRecordParams = [
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];

//combine error msg to avoid mismatch between error file columns.
$errorMessage .= "\n" . $url_string;
array_unshift($values, $errorMessage);
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;
}

Expand Down Expand Up @@ -2342,11 +2311,7 @@ protected function handleDuplicateError(array $newContact, $statusFieldName, arr
// different kind of error other than DUPLICATE
$errorMessage = $newContact['error_message'];
array_unshift($values, $errorMessage);
$importRecordParams = [
$statusFieldName => 'ERROR',
"${statusFieldName}Msg" => $errorMessage,
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'ERROR', $errorMessage);
return CRM_Import_Parser::ERROR;
}

Expand All @@ -2361,18 +2326,11 @@ protected function handleDuplicateError(array $newContact, $statusFieldName, arr
//CRM-262 No Duplicate Checking
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
array_unshift($values, $url_string);
$importRecordParams = [
$statusFieldName => 'DUPLICATE',
"${statusFieldName}Msg" => "Skipping duplicate record",
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'DUPLICATE', 'Skipping duplicate record');
return CRM_Import_Parser::DUPLICATE;
}

$importRecordParams = [
$statusFieldName => 'IMPORTED',
];
$this->updateImportRecord($values[count($values) - 1], $importRecordParams);
$this->setImportStatus((int) $values[count($values) - 1], 'Imported', '');
//return warning if street address is not parsed, CRM-5886
return $this->processMessage($values, $statusFieldName, CRM_Import_Parser::VALID);
}
Expand Down Expand Up @@ -3141,18 +3099,6 @@ public static function exportCSV($fileName, $header, $data) {
fclose($fd);
}

/**
* Update the record with PK $id in the import database table.
*
* @deprecated - call setImportStatus directly as the parameters are simpler,
*
* @param int $id
* @param array $params
*/
public function updateImportRecord($id, $params): void {
$this->setImportStatus((int) $id, $params[$this->_statusFieldName] ?? '', $params["{$this->_statusFieldName}Msg"] ?? '');
}

/**
* Set the import status for the given record.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function testImportParserWithEmployeeOfRelationship(): void {
'legal_name' => 'Agileware',
]);
$contactImportValues = [
"first_name" => "Alok",
"last_name" => "Patel",
"Employee of" => "Agileware",
'first_name' => 'Alok',
'last_name' => 'Patel',
'Employee of' => 'Agileware',
];

$fields = array_keys($contactImportValues);
Expand Down

0 comments on commit 3826621

Please sign in to comment.