Add extra shared import functions
[civicrm-core.git] / CRM / Import / Form / MapField.php
index 11581f2a4699395d8bb50520d111de74667f78e1..26f90307782bcf46b62090b1e708cbe3f25f3fcd 100644 (file)
@@ -76,6 +76,22 @@ abstract class CRM_Import_Form_MapField extends CRM_Import_Forms {
     parent::preProcess();
   }
 
+  /**
+   * Process the mapped fields and map it into the uploaded file
+   * preview the file and extract some summary statistics
+   *
+   * @return void
+   * @noinspection PhpDocSignatureInspection
+   * @noinspection PhpUnhandledExceptionInspection
+   */
+  public function postProcess() {
+    $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
+    $this->saveMapping($this->getMappingTypeName());
+    $parser = $this->getParser();
+    $parser->init();
+    $parser->validate();
+  }
+
   /**
    * Attempt to match header labels with our mapper fields.
    *
@@ -230,6 +246,9 @@ abstract class CRM_Import_Form_MapField extends CRM_Import_Forms {
   protected function saveMappingField(int $mappingID, int $columnNumber, bool $isUpdate = FALSE): void {
     $fieldMapping = (array) $this->getSubmittedValue('mapper')[$columnNumber];
     $mappedField = $this->getMappedField($fieldMapping, $mappingID, $columnNumber);
+    if (empty($mappedField['name'])) {
+      $mappedField['name'] = 'do_not_import';
+    }
     if ($isUpdate) {
       Civi\Api4\MappingField::update(FALSE)
         ->setValues($mappedField)