From aff4f4e986bbc12781b88a43754970839c1d0c70 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 31 May 2022 14:13:51 +1200 Subject: [PATCH] Import - ensure userID is set on parser --- CRM/Activity/Import/Form/MapField.php | 3 ++- CRM/Activity/Import/Form/Preview.php | 2 +- CRM/Contact/Import/Form/DataSource.php | 24 ++--------------- CRM/Contribute/Import/Form/Preview.php | 2 +- CRM/Custom/Import/Form/Preview.php | 1 + CRM/Event/Import/Form/Preview.php | 2 +- CRM/Import/Form/DataSource.php | 36 +++++++++++++++++++++----- 7 files changed, 38 insertions(+), 32 deletions(-) diff --git a/CRM/Activity/Import/Form/MapField.php b/CRM/Activity/Import/Form/MapField.php index 2dc0f5ce5d..e9b6c65106 100644 --- a/CRM/Activity/Import/Form/MapField.php +++ b/CRM/Activity/Import/Form/MapField.php @@ -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 ); diff --git a/CRM/Activity/Import/Form/Preview.php b/CRM/Activity/Import/Form/Preview.php index f26d7f67f6..16f5087d4e 100644 --- a/CRM/Activity/Import/Form/Preview.php +++ b/CRM/Activity/Import/Form/Preview.php @@ -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) { diff --git a/CRM/Contact/Import/Form/DataSource.php b/CRM/Contact/Import/Form/DataSource.php index 01ee130fc5..fb4c8dcbf5 100644 --- a/CRM/Contact/Import/Form/DataSource.php +++ b/CRM/Contact/Import/Form/DataSource.php @@ -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(); } /** diff --git a/CRM/Contribute/Import/Form/Preview.php b/CRM/Contribute/Import/Form/Preview.php index 4bb5a55b4c..f496b167b9 100644 --- a/CRM/Contribute/Import/Form/Preview.php +++ b/CRM/Contribute/Import/Form/Preview.php @@ -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) { diff --git a/CRM/Custom/Import/Form/Preview.php b/CRM/Custom/Import/Form/Preview.php index a9a01a528f..a86abbb7fe 100644 --- a/CRM/Custom/Import/Form/Preview.php +++ b/CRM/Custom/Import/Form/Preview.php @@ -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'); diff --git a/CRM/Event/Import/Form/Preview.php b/CRM/Event/Import/Form/Preview.php index 7456aee920..f099472742 100644 --- a/CRM/Event/Import/Form/Preview.php +++ b/CRM/Event/Import/Form/Preview.php @@ -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) { diff --git a/CRM/Import/Form/DataSource.php b/CRM/Import/Form/DataSource.php index 558104298a..19fea5947c 100644 --- a/CRM/Import/Form/DataSource.php +++ b/CRM/Import/Form/DataSource.php @@ -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(); + } + } -- 2.25.1