Skip to content

Commit

Permalink
Merge pull request #25639 from eileenmcnaughton/import_validate
Browse files Browse the repository at this point in the history
dev/core#4132 Fix import for multi-custom boxes
  • Loading branch information
totten authored Mar 1, 2023
2 parents d16ea4e + 6d10f1d commit d99e835
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 1 addition & 6 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion ext/civiimport/Civi/Api4/Import/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions ext/civiimport/Civi/Api4/Import/ImportProcessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d99e835

Please sign in to comment.