Merge pull request #23636 from eileenmcnaughton/import_contact_type
authorcolemanw <coleman@civicrm.org>
Wed, 1 Jun 2022 02:10:46 +0000 (22:10 -0400)
committerGitHub <noreply@github.com>
Wed, 1 Jun 2022 02:10:46 +0000 (22:10 -0400)
Import - ensure userID is set on parser

CRM/Activity/Import/Form/MapField.php
CRM/Activity/Import/Form/Preview.php
CRM/Contact/Import/Form/DataSource.php
CRM/Contribute/Import/Form/Preview.php
CRM/Custom/Import/Form/Preview.php
CRM/Event/Import/Form/Preview.php
CRM/Import/Form/DataSource.php

index 2dc0f5ce5d6262d8ebfeae4efe557994915b25ea..e9b6c651063ab6558150305da44544d0318b425f 100644 (file)
@@ -324,8 +324,8 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField {
       $this->controller->resetPage($this->_name);
       return;
     }
+    $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
 
-    $mapperKeys = [];
     $mapper = [];
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = [];
@@ -387,6 +387,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField {
     }
 
     $parser = new CRM_Activity_Import_Parser_Activity($mapperKeysMain);
+    $parser->setUserJobID($this->getUserJobID());
     $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapper, $this->getSubmittedValue('skipColumnHeader'),
       CRM_Import_Parser::MODE_PREVIEW
     );
index f26d7f67f6f716c25c79ed5947a95589eace3114..16f5087d4e91d7dcf5ede8d2c603c4fa15afb25b 100644 (file)
@@ -78,7 +78,7 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview {
     }
 
     $parser = new CRM_Activity_Import_Parser_Activity($mapperKeys);
-
+    $parser->setUserJobID($this->getUserJobID());
     $mapFields = $this->get('fields');
 
     foreach ($mapper as $key => $value) {
index 01ee130fc57be9fa1180614e40643ed69f6f92bc..fb4c8dcbf5aa7410efa4566f99a2ebbaa342cf45 100644 (file)
@@ -18,7 +18,7 @@
 /**
  * This class delegates to the chosen DataSource to grab the data to be imported.
  */
-class CRM_Contact_Import_Form_DataSource extends CRM_Import_Forms {
+class CRM_Contact_Import_Form_DataSource extends CRM_Import_Form_DataSource {
 
   /**
    * Get any smarty elements that may not be present in the form.
@@ -172,14 +172,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Import_Forms {
    */
   public function postProcess() {
     $this->controller->resetPage('MapField');
-    if (!$this->getUserJobID()) {
-      $this->createUserJob();
-    }
-    else {
-      $this->flushDataSource();
-      $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
-    }
-
+    $this->processDatasource();
     // @todo - this params are being set here because they were / possibly still
     // are in some places being accessed by forms later in the flow
     // ie CRM_Contact_Import_Form_MapField, CRM_Contact_Import_Form_Preview
@@ -201,19 +194,6 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Import_Forms {
     }
     CRM_Core_Session::singleton()->set('dateTypes', $storeParams['dateFormats']);
 
-    $this->instantiateDataSource();
-  }
-
-  /**
-   * Instantiate the datasource.
-   *
-   * This gives the datasource a chance to do any table creation etc.
-   *
-   * @throws \API_Exception
-   * @throws \CRM_Core_Exception
-   */
-  private function instantiateDataSource(): void {
-    $this->getDataSourceObject()->initialize();
   }
 
   /**
index 4bb5a55b4c419e0446bd01fb476b01631e86bf43..f496b167b9ad524c35374f74d815a013eda2002c 100644 (file)
@@ -90,7 +90,7 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview {
     }
 
     $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeys, $mapperSoftCredit, $mapperPhoneType, $mapperSoftCreditType);
-
+    $parser->setUserJobID($this->getUserJobID());
     $mapFields = $this->get('fields');
 
     foreach ($mapper as $key => $value) {
index a9a01a528fe745bedb28b9a3c297fdf7f0f62ee5..a86abbb7fee9d0e9ec16536bba9db6c6f8e8089f 100644 (file)
@@ -69,6 +69,7 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview {
     }
 
     $parser = new $this->_parser($mapperKeys);
+    $parser->setUserJobID($this->getUserJobID());
     $parser->setEntity($entity);
 
     $mapFields = $this->get('fields');
index 7456aee9200a87e7aa7722de191958594258edd7..f099472742e0891d31f7558da34e81ce8e6b4a8b 100644 (file)
@@ -83,7 +83,7 @@ class CRM_Event_Import_Form_Preview extends CRM_Import_Form_Preview {
     }
 
     $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
-
+    $parser->setUserJobID($this->getUserJobID());
     $mapFields = $this->get('fields');
 
     foreach ($mapper as $key => $value) {
index 558104298af3bc912be86ed7cc107857df2b5353..19fea5947c19202fc3ed50c75719d0774a8b1bd8 100644 (file)
@@ -157,12 +157,7 @@ abstract class CRM_Import_Form_DataSource extends CRM_Import_Forms {
   protected function submitFileForMapping($parserClassName, $entity = NULL) {
     $this->controller->resetPage('MapField');
     CRM_Core_Session::singleton()->set('dateTypes', $this->getSubmittedValue('dateFormats'));
-    if (!$this->getUserJobID()) {
-      $this->createUserJob();
-    }
-    else {
-      $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
-    }
+    $this->processDatasource();
 
     $mapper = [];
 
@@ -194,4 +189,33 @@ abstract class CRM_Import_Form_DataSource extends CRM_Import_Forms {
     return ts('Upload Data');
   }
 
+  /**
+   * Process the datasource submission - setting up the job and data source.
+   *
+   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
+   */
+  protected function processDatasource(): void {
+    if (!$this->getUserJobID()) {
+      $this->createUserJob();
+    }
+    else {
+      $this->flushDataSource();
+      $this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
+    }
+    $this->instantiateDataSource();
+  }
+
+  /**
+   * Instantiate the datasource.
+   *
+   * This gives the datasource a chance to do any table creation etc.
+   *
+   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
+   */
+  private function instantiateDataSource(): void {
+    $this->getDataSourceObject()->initialize();
+  }
+
 }