Skip to content
Snippets Groups Projects
Unverified Commit 743f8b1c authored by colemanw's avatar colemanw Committed by GitHub
Browse files

Merge pull request #23760 from eileenmcnaughton/validate_fields

#3511 Improve handling of invalid saved mapping fields
parents 8dcf392f e077bdea
Branches
Tags 5.81.1
No related merge requests found
......@@ -439,13 +439,23 @@ class CRM_Import_ImportProcessor {
'mapping_id' => $this->getMappingID(),
'options' => ['limit' => 0],
])['values'];
$skipped = [];
foreach ($fields as $index => $field) {
if (!$this->isValidField($field['name'])) {
// This scenario could occur if the name of a saved mapping field
// changed or became unavailable https://lab.civicrm.org/dev/core/-/issues/3511.
$skipped[] = $field['name'];
$fields[$index]['name'] = $field['name'] = 'do_not_import';
}
$fieldSpec = $this->getFieldMetadata($field['name']);
$fields[$index]['label'] = $fieldSpec['title'];
if (empty($field['location_type_id']) && !empty($fieldSpec['hasLocationType'])) {
$fields[$index]['location_type_id'] = 'Primary';
}
}
if (!empty($skipped)) {
CRM_Core_Session::setStatus(ts('Invalid saved mappings were skipped') . ':' . implode(', ', $skipped));
}
$this->mappingFields = $this->rekeyBySortedColumnNumbers($fields);
}
......@@ -460,6 +470,19 @@ class CRM_Import_ImportProcessor {
return $this->getMetadata()[$fieldName] ?? CRM_Contact_BAO_Contact::importableFields('All')[$fieldName];
}
/**
* Is the field valid for this import.
*
* If not defined in metadata is is not valid.
*
* @param string $fieldName
*
* @return bool
*/
public function isValidField(string $fieldName): bool {
return isset($this->getMetadata()[$fieldName]) || isset(CRM_Contact_BAO_Contact::importableFields('All')[$fieldName]);
}
/**
* Load the mapping from the database into the pre-5.50 format.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment