Decommission loadSavedMapping now it is all cleaned up
authoreileen <emcnaughton@wikimedia.org>
Fri, 6 Sep 2019 00:13:57 +0000 (12:13 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 6 Sep 2019 01:47:12 +0000 (13:47 +1200)
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

CRM/Contact/Import/Form/MapField.php
tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php

index a3bd19c53fa793a6c0c47791cb8772a51b4c9c51..79bd3321a45ffa2b3713d79556b1a87b6ec00139 100644 (file)
@@ -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];
-  }
-
 }
index 48feff3235d235dade439562754000286d44d26a..ceea85bb7f141fdae9fb30927b05f6a5dfad027e 100644 (file)
@@ -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];
   }
 
   /**