From dba9288a0ebfcf0a6eb0c5fbe08fe008fee033d4 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 3 May 2022 14:31:35 +1200 Subject: [PATCH] [REF] [Import] Stop passing submittedValues as parameters These parameters are all availabe via --- CRM/Contact/Import/Parser/Contact.php | 23 ++++++------------- .../CRM/Contact/Import/Form/MapFieldTest.php | 1 + .../CRM/Contact/Import/Parser/ContactTest.php | 1 + 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 78138d4a25..75ab6ce1d7 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -465,8 +465,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { * @param array $values * The array of values belonging to this line. * - * @param bool $doGeocodeAddress - * * @return bool * the result of this processing * @@ -474,9 +472,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { * @throws \CRM_Core_Exception * @throws \API_Exception */ - public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) { + public function import($onDuplicate, &$values) { $this->_unparsedStreetAddressContacts = []; - if (!$doGeocodeAddress) { + if (!$this->getSubmittedValue('doGeocodeAddress')) { // CRM-5854, reset the geocode method to null to prevent geocoding CRM_Utils_GeocodeProvider::disableForSession(); } @@ -2541,12 +2539,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { * @param int $onDuplicate * @param int $statusID * @param int $totalRowCount - * @param bool $doGeocodeAddress - * @param int $timeout - * @param string $contactSubType - * @param int $dedupeRuleGroupID * * @return mixed + * @throws \API_Exception */ public function run( $tableName, @@ -2557,16 +2552,12 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $statusFieldName = '_status', $onDuplicate = self::DUPLICATE_SKIP, $statusID = NULL, - $totalRowCount = NULL, - $doGeocodeAddress = FALSE, - $timeout = CRM_Contact_Import_Parser_Contact::DEFAULT_TIMEOUT, - $contactSubType = NULL, - $dedupeRuleGroupID = NULL + $totalRowCount = NULL ) { // TODO: Make the timeout actually work - $this->_onDuplicate = $onDuplicate; - $this->_dedupeRuleGroupID = $dedupeRuleGroupID; + $this->_onDuplicate = $onDuplicate = $this->getSubmittedValue('onDuplicate'); + $this->_dedupeRuleGroupID = $this->getSubmittedValue('dedupe_rule_id'); // Since $this->_contactType is still being called directly do a get call // here to make sure it is instantiated. $this->getContactType(); @@ -2640,7 +2631,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } elseif ($mode == self::MODE_IMPORT) { try { - $returnCode = $this->import($onDuplicate, $values, $doGeocodeAddress); + $returnCode = $this->import($onDuplicate, $values); } catch (CiviCRM_API3_Exception $e) { // When we catch errors here we are not adding to the errors array - mostly diff --git a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php index 4e2ec24ac9..6766156045 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php @@ -149,6 +149,7 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { 'contactSubType' => '', 'dataSource' => 'CRM_Import_DataSource_SQL', 'sqlQuery' => 'SELECT * FROM civicrm_tmp_d_import_job_xxx', + 'dedupe_rule_id' => '', 'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE, ], $submittedValues); $userJobID = UserJob::create()->setValues([ diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index c6229cd2ab..ed5b6b18d2 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -1059,6 +1059,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { 'submitted_values' => array_merge([ 'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL, 'contactSubType' => '', + 'doGeocodeAddress' => 0, ], $submittedValues), ], 'status_id:name' => 'draft', -- 2.25.1