From 5e8faabcdc3872097edbcc1ea3b564ff05408dbc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 12 Apr 2022 11:42:04 +1200 Subject: [PATCH] Simplify value retrieval --- CRM/Activity/Import/Form/MapField.php | 6 +----- CRM/Activity/Import/Form/Preview.php | 5 +++-- CRM/Contribute/Import/Form/MapField.php | 13 +++++++------ CRM/Contribute/Import/Form/Preview.php | 5 +++-- CRM/Custom/Import/Form/MapField.php | 5 +---- CRM/Custom/Import/Form/Preview.php | 5 ++--- CRM/Import/Form/DataSource.php | 15 +++++---------- CRM/Import/Form/MapField.php | 2 +- CRM/Import/Forms.php | 2 ++ CRM/Member/Import/Form/MapField.php | 6 +----- CRM/Member/Import/Form/Preview.php | 5 ++--- 11 files changed, 28 insertions(+), 41 deletions(-) diff --git a/CRM/Activity/Import/Form/MapField.php b/CRM/Activity/Import/Form/MapField.php index 215ec9ecca..8008bc0412 100644 --- a/CRM/Activity/Import/Form/MapField.php +++ b/CRM/Activity/Import/Form/MapField.php @@ -325,10 +325,6 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { return; } - $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - $mapperKeys = []; $mapper = []; $mapperKeys = $this->controller->exportValue($this->_name, 'mapper'); @@ -391,7 +387,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { } $parser = new CRM_Activity_Import_Parser_Activity($mapperKeysMain); - $parser->run($fileName, $separator, $mapper, $skipColumnHeader, + $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 0526eb4338..6ce5e0d849 100644 --- a/CRM/Activity/Import/Form/Preview.php +++ b/CRM/Activity/Import/Form/Preview.php @@ -82,7 +82,6 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview { */ public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -105,7 +104,9 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview { } $mapperFields[] = implode(' - ', $header); } - $parser->run($fileName, $separator, + $parser->run( + $this->getSubmittedValue('uploadFile'), + $this->getSubmittedValue('fieldSeparator'), $mapperFields, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index 8b20bb9793..5297f4fd5b 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -423,10 +423,6 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { return; } - $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - $mapper = $mapperKeys = $mapperKeysMain = $mapperSoftCredit = $softCreditFields = $mapperPhoneType = $mapperSoftCreditType = []; $mapperKeys = $this->controller->exportValue($this->_name, 'mapper'); @@ -511,8 +507,13 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { } $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeysMain, $mapperSoftCredit, $mapperPhoneType); - $parser->run($fileName, $separator, $mapper, $skipColumnHeader, - CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType') + $parser->run( + $this->getSubmittedValue('uploadFile'), + $this->getSubmittedValue('fieldSeparator'), + $mapper, + $this->getSubmittedValue('skipColumnHeader'), + CRM_Import_Parser::MODE_PREVIEW, + $this->get('contactType') ); // add all the necessary variables to the form diff --git a/CRM/Contribute/Import/Form/Preview.php b/CRM/Contribute/Import/Form/Preview.php index d71fccf323..b9abde34ac 100644 --- a/CRM/Contribute/Import/Form/Preview.php +++ b/CRM/Contribute/Import/Form/Preview.php @@ -84,7 +84,6 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { */ public function postProcess() { $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -117,7 +116,9 @@ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { } $mapperFields[] = implode(' - ', $header); } - $parser->run($fileName, $separator, + $parser->run( + $this->getSubmittedValue('uploadFile'), + $this->getSubmittedValue('fieldSeparator'), $mapperFields, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, diff --git a/CRM/Custom/Import/Form/MapField.php b/CRM/Custom/Import/Form/MapField.php index 64cc0c6287..e7d6cd7558 100644 --- a/CRM/Custom/Import/Form/MapField.php +++ b/CRM/Custom/Import/Form/MapField.php @@ -144,9 +144,6 @@ class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField { return; } - $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); $this->_entity = $this->controller->exportValue('DataSource', 'entity'); $mapper = []; @@ -211,7 +208,7 @@ class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField { $parser = new $this->_parser($mapperKeysMain); $parser->setEntity($this->_multipleCustomData); - $parser->run($fileName, $separator, $mapper, $skipColumnHeader, + $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapper, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType') ); // add all the necessary variables to the form diff --git a/CRM/Custom/Import/Form/Preview.php b/CRM/Custom/Import/Form/Preview.php index cc77ef8a70..d7604a66a3 100644 --- a/CRM/Custom/Import/Form/Preview.php +++ b/CRM/Custom/Import/Form/Preview.php @@ -71,8 +71,7 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview { * @return void */ public function postProcess() { - $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); + $fileName = $this->getSubmittedValue('uploadFile'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -97,7 +96,7 @@ class CRM_Custom_Import_Form_Preview extends CRM_Import_Form_Preview { } $mapperFields[] = implode(' - ', $header); } - $parser->run($fileName, $separator, + $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapperFields, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, diff --git a/CRM/Import/Form/DataSource.php b/CRM/Import/Form/DataSource.php index 36de82c71f..78c7d2c35b 100644 --- a/CRM/Import/Form/DataSource.php +++ b/CRM/Import/Form/DataSource.php @@ -17,7 +17,7 @@ /** * Base class for upload-only import forms (all but Contact import). */ -abstract class CRM_Import_Form_DataSource extends CRM_Core_Form { +abstract class CRM_Import_Form_DataSource extends CRM_Import_Forms { /** * Set variables up before form is built. @@ -132,15 +132,9 @@ abstract class CRM_Import_Form_DataSource extends CRM_Core_Form { */ protected function submitFileForMapping($parserClassName, $entity = NULL) { $this->controller->resetPage('MapField'); - - $fileName = $this->controller->exportValue($this->_name, 'uploadFile'); - $skipColumnHeader = $this->controller->exportValue($this->_name, 'skipColumnHeader'); - $session = CRM_Core_Session::singleton(); $session->set("dateTypes", $this->get('dateFormats')); - $separator = $this->controller->exportValue($this->_name, 'fieldSeparator'); - $mapper = []; $parser = new $parserClassName($mapper); @@ -148,10 +142,11 @@ abstract class CRM_Import_Form_DataSource extends CRM_Core_Form { $parser->setEntity($this->get($entity)); } $parser->setMaxLinesToProcess(100); - $parser->run($fileName, - $separator, + $parser->run( + $this->getSubmittedValue('uploadFile'), + $this->getSubmittedValue('fieldSeparator'), [], - $skipColumnHeader, + $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_MAPFIELD, $this->get('contactType') ); diff --git a/CRM/Import/Form/MapField.php b/CRM/Import/Form/MapField.php index 7fba797c8c..083f4aceb7 100644 --- a/CRM/Import/Form/MapField.php +++ b/CRM/Import/Form/MapField.php @@ -19,7 +19,7 @@ * * TODO: CRM-11254 - There's still a lot of duplicate code in the 5 child classes that should be moved here */ -abstract class CRM_Import_Form_MapField extends CRM_Core_Form { +abstract class CRM_Import_Form_MapField extends CRM_Import_Forms { /** * Cache of preview data values diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index c1fcd9ed1e..2e08493e39 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -29,6 +29,8 @@ class CRM_Import_Forms extends CRM_Core_Form { public function getSubmittedValue(string $fieldName) { $mappedValues = [ 'skipColumnHeader' => 'DataSource', + 'fieldSeparator' => 'DataSource', + 'uploadFile' => 'DataSource', ]; if (array_key_exists($fieldName, $mappedValues)) { return $this->controller->exportValue($mappedValues[$fieldName], $fieldName); diff --git a/CRM/Member/Import/Form/MapField.php b/CRM/Member/Import/Form/MapField.php index 352cc47458..d73c996e3f 100644 --- a/CRM/Member/Import/Form/MapField.php +++ b/CRM/Member/Import/Form/MapField.php @@ -392,10 +392,6 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { return; } - $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); - $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - $mapperKeys = []; $mapper = []; $mapperKeys = $this->controller->exportValue($this->_name, 'mapper'); @@ -472,7 +468,7 @@ class CRM_Member_Import_Form_MapField extends CRM_Import_Form_MapField { } $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain, $mapperLocType, $mapperPhoneType); - $parser->run($fileName, $separator, $mapper, $skipColumnHeader, + $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapper, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType') ); // add all the necessary variables to the form diff --git a/CRM/Member/Import/Form/Preview.php b/CRM/Member/Import/Form/Preview.php index 6502770d7a..91959809ad 100644 --- a/CRM/Member/Import/Form/Preview.php +++ b/CRM/Member/Import/Form/Preview.php @@ -85,8 +85,7 @@ class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview { * @return void */ public function postProcess() { - $fileName = $this->controller->exportValue('DataSource', 'uploadFile'); - $separator = $this->controller->exportValue('DataSource', 'fieldSeparator'); + $fileName = $this->getSubmittedValue('uploadFile'); $invalidRowCount = $this->get('invalidRowCount'); $conflictRowCount = $this->get('conflictRowCount'); $onDuplicate = $this->get('onDuplicate'); @@ -128,7 +127,7 @@ class CRM_Member_Import_Form_Preview extends CRM_Import_Form_Preview { } $mapperFields[] = implode(' - ', $header); } - $parser->run($fileName, $separator, + $parser->run($this->getSubmittedValue('uploadFile'), $this->getSubmittedValue('fieldSeparator'), $mapperFields, $this->getSubmittedValue('skipColumnHeader'), CRM_Import_Parser::MODE_IMPORT, -- 2.25.1