From 416d6fa9b01670f5d90b82ce9229348ed34d27f2 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 22 Feb 2023 13:24:52 +1300 Subject: [PATCH 1/2] 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 9b909411f064..6ad0e41dddf9 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -2548,16 +2548,20 @@ protected function getDedupeRules(array $dedupeRuleIDs, $contact_type) { /** * @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 60099303bd80..4a152d255faa 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 c60a4d5b4e21..71f91e7ffd16 100644 --- a/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php +++ b/ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php @@ -66,6 +66,7 @@ protected function getImportRows(Result $result): void { ->indexBy('name')); $importFields[] = '_id'; $importFields[] = '_entity_id'; + $importFields[] = '_status'; $this->setSelect($importFields); parent::_run($result); foreach ($result as &$row) { From 6d10f1dd0217f6f2747b7d0bfaba4a5cbc4d61d3 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Fri, 4 Nov 2022 11:36:24 -0400 Subject: [PATCH 2/2] ensure checkbox imports work on contacts See https://lab.civicrm.org/dev/core/-/issues/3850 --- CRM/Contact/Import/Parser/Contact.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 523924c4c405..f1b7b92b0e96 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -420,12 +420,7 @@ private function formatCommonData($params, &$formatted) { if ((strtolower($v2['label']) == strtolower(trim($v1))) || (strtolower($v2['value']) == strtolower(trim($v1))) ) { - if ($htmlType == 'CheckBox') { - $params[$key][$v2['value']] = $formatted[$key][$v2['value']] = 1; - } - else { - $params[$key][] = $formatted[$key][] = $v2['value']; - } + $params[$key][] = $formatted[$key][] = $v2['value']; } } }