From: eileen Date: Fri, 6 Sep 2019 00:13:57 +0000 (+1200) Subject: Decommission loadSavedMapping now it is all cleaned up X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a5eb54c56bd6643da6a625b8ea3eba65d48f6bde;p=civicrm-core.git Decommission loadSavedMapping now it is all cleaned up The final result is that the 134 lines here https://github.com/civicrm/civicrm-core/blob/5.16/CRM/Contact/Import/Form/MapField.php#L407-L543 are now just 2 lines & we don't need a separte function Although this does now free us to replace the 30 lines above with a call to the shared function --- diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index a3bd19c53f..79bd3321a4 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -402,8 +402,9 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { for ($i = 0; $i < $this->_columnCount; $i++) { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); - if ($this->get('savedMapping')) { - list($defaults, $js) = $this->loadSavedMapping($processor, $i, $defaults, $js, $hasColumnNames); + if ($this->get('savedMapping') && $processor->getFieldName($i)) { + $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i); + $js .= $processor->getQuickFormJSForField($i); } else { $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n"; @@ -839,35 +840,4 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { return $saveMappingFields->mapping_id; } - /** - * @param \CRM_Import_ImportProcessor $processor - * @param $mappingName - * @param int $i - * @param array $defaults - * @param string $js - * @param bool $hasColumnNames - * - * @return array - * @throws \CiviCRM_API3_Exception - */ - public function loadSavedMapping($processor, $i, $defaults, $js, $hasColumnNames) { - $formName = $processor->getFormName(); - if ($processor->getFieldName($i)) { - $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i); - $js .= $processor->getQuickFormJSForField($i); - } - else { - // this load section to help mapping if we ran out of saved columns when doing Load Mapping - $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n"; - - if ($hasColumnNames) { - $defaults["mapper[$i]"] = [$this->defaultFromColumnName($this->_columnNames[$i])]; - } - else { - $defaults["mapper[$i]"] = [$this->defaultFromData($this->getDataPatterns(), $i)]; - } - } - return [$defaults, $js]; - } - } diff --git a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php index 48feff3235..ceea85bb7f 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php @@ -176,7 +176,7 @@ class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase { $mapping = $this->callAPISuccess('Mapping', 'create', ['name' => 'my test']); $this->callAPISuccess('MappingField', 'create', array_merge(['mapping_id' => $mapping['id']], $fieldSpec)); - $result = $this->loadSavedMapping($this->form, $mapping['id'], $fieldSpec['column_number']); + $result = $this->loadSavedMapping($mapping['id'], $fieldSpec['column_number']); $this->assertEquals($expectedJS, $result['js']); $this->assertEquals($expectedDefaults, $result['defaults']); } @@ -374,19 +374,18 @@ document.forms.MapField['mapper[0][3]'].style.display = 'none';\n", * * @throws \CiviCRM_API3_Exception */ - protected function loadSavedMapping($form, $mappingID, $columnNumber) { - $defaults = []; - - $js = ''; - $hasColumnNames = TRUE; + protected function loadSavedMapping($mappingID, $columnNumber) { $processor = new CRM_Import_ImportProcessor(); $processor->setMappingID($mappingID); $processor->setFormName('document.forms.MapField'); $processor->setMetadata($this->getContactImportMetadata()); $processor->setContactTypeByConstant(CRM_Import_Parser::CONTACT_INDIVIDUAL); - $return = $form->loadSavedMapping($processor, $columnNumber, $defaults, $js, $hasColumnNames); - return ['defaults' => $return[0], 'js' => $return[1]]; + $defaults = []; + $defaults["mapper[$columnNumber]"] = $processor->getSavedQuickformDefaultsForColumn($columnNumber); + $js = $processor->getQuickFormJSForField($columnNumber); + + return ['defaults' => $defaults, 'js' => $js]; } /**