From 416d6fa9b01670f5d90b82ce9229348ed34d27f2 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 22 Feb 2023 13:24:52 +1300 Subject: [PATCH] Fix import to retry invalid --- CRM/Import/Parser.php | 6 +++++- ext/civiimport/Civi/Api4/Import/Import.php | 4 +++- ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 9b909411f0..6ad0e41ddd 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -2548,16 +2548,20 @@ abstract class CRM_Import_Parser implements UserJobInterface { /** * @param array|null $row + * + * @return bool */ - public function validateRow(?array $row): void { + public function validateRow(?array $row): bool { try { $rowNumber = $row['_id']; $values = array_values($row); $this->validateValues($values); $this->setImportStatus($rowNumber, 'VALID', ''); + return TRUE; } catch (CRM_Core_Exception $e) { $this->setImportStatus($rowNumber, 'ERROR', $e->getMessage()); + return FALSE; } } diff --git a/ext/civiimport/Civi/Api4/Import/Import.php b/ext/civiimport/Civi/Api4/Import/Import.php index 60099303bd..4a152d255f 100644 --- a/ext/civiimport/Civi/Api4/Import/Import.php +++ b/ext/civiimport/Civi/Api4/Import/Import.php @@ -25,10 +25,12 @@ class Import extends DAOGetAction { public function _run(Result $result): void { $userJobID = (int) str_replace('Import_', '', $this->_entityName); $where = $this->where; - $this->addWhere('_status', 'IN', ['new', 'valid']); $this->getImportRows($result); $parser = $this->getParser($userJobID); foreach ($result as $row) { + if (!in_array($row['_status'], ['new', 'valid'], TRUE) && !$parser->validateRow($row)) { + continue; + } $parser->import(array_values($row)); } $parser->doPostImportActions(); diff --git a/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php b/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php index c60a4d5b4e..71f91e7ffd 100644 --- a/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php +++ b/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php @@ -66,6 +66,7 @@ trait ImportProcessTrait { ->indexBy('name')); $importFields[] = '_id'; $importFields[] = '_entity_id'; + $importFields[] = '_status'; $this->setSelect($importFields); parent::_run($result); foreach ($result as &$row) { -- 2.25.1