[REF] Fix import signature on activity parser, add preliminary test
authoreileen <emcnaughton@wikimedia.org>
Fri, 1 Jan 2021 21:28:46 +0000 (10:28 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 1 Jan 2021 21:28:46 +0000 (10:28 +1300)
The construct class does not need to receive mapperKeys as a reference - this
was removed for Membership Parser here https://github.com/civicrm/civicrm-core/commit/14b9e069607c6cbcbbaf21a209f647ba422b8e04#diff-36f5db3555445d26df2de015a18598fd5d5682b76c62aee4f14dde95b7948274L65

In addition 2 places that instantiate this class pass in unused params (go copy & paste) so
that is removed. The test tests very little so far....

CRM/Activity/Import/Form/MapField.php
CRM/Activity/Import/Form/Preview.php
CRM/Activity/Import/Parser/Activity.php

index a0688d9cffcc5d22456c4cf2894d53c86f625c9e..17f034a6081e29a86dc682df2a9403576494ce16 100644 (file)
@@ -357,26 +357,10 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField {
     $mapper = [];
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = [];
-    $mapperLocType = [];
-    $mapperPhoneType = [];
 
     for ($i = 0; $i < $this->_columnCount; $i++) {
       $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
       $mapperKeysMain[$i] = $mapperKeys[$i][0];
-
-      if ((CRM_Utils_Array::value(1, $mapperKeys[$i])) && (is_numeric($mapperKeys[$i][1]))) {
-        $mapperLocType[$i] = $mapperKeys[$i][1];
-      }
-      else {
-        $mapperLocType[$i] = NULL;
-      }
-
-      if ((CRM_Utils_Array::value(2, $mapperKeys[$i])) && (!is_numeric($mapperKeys[$i][2]))) {
-        $mapperPhoneType[$i] = $mapperKeys[$i][2];
-      }
-      else {
-        $mapperPhoneType[$i] = NULL;
-      }
     }
 
     $this->set('mapper', $mapper);
@@ -430,7 +414,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField {
       $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
 
-    $parser = new CRM_Activity_Import_Parser_Activity($mapperKeysMain, $mapperLocType, $mapperPhoneType);
+    $parser = new CRM_Activity_Import_Parser_Activity($mapperKeysMain);
     $parser->run($fileName, $separator, $mapper, $skipColumnHeader,
       CRM_Import_Parser::MODE_PREVIEW
     );
index 718f30626e4c092d912dacce5426321eb36d524e..3b3de7d38e49c0a9d8663d3658bceb6313a8818f 100644 (file)
@@ -100,28 +100,12 @@ class CRM_Activity_Import_Form_Preview extends CRM_Import_Form_Preview {
 
     $mapper = $this->controller->exportValue('MapField', 'mapper');
     $mapperKeys = [];
-    $mapperLocType = [];
-    $mapperPhoneType = [];
 
     foreach ($mapper as $key => $value) {
       $mapperKeys[$key] = $mapper[$key][0];
-
-      if (!empty($mapper[$key][1]) && is_numeric($mapper[$key][1])) {
-        $mapperLocType[$key] = $mapper[$key][1];
-      }
-      else {
-        $mapperLocType[$key] = NULL;
-      }
-
-      if (!empty($mapper[$key][2]) && (!is_numeric($mapper[$key][2]))) {
-        $mapperPhoneType[$key] = $mapper[$key][2];
-      }
-      else {
-        $mapperPhoneType[$key] = NULL;
-      }
     }
 
-    $parser = new CRM_Activity_Import_Parser_Activity($mapperKeys, $mapperLocType, $mapperPhoneType);
+    $parser = new CRM_Activity_Import_Parser_Activity($mapperKeys);
 
     $mapFields = $this->get('fields');
 
index cccd68e0dbfe97933800c26ba1443df54ecea943..e38432cff8e266bdeed869cd99239f2a4b76d259 100644 (file)
@@ -40,9 +40,9 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser {
    *
    * @param array $mapperKeys
    */
-  public function __construct(&$mapperKeys) {
+  public function __construct($mapperKeys) {
     parent::__construct();
-    $this->_mapperKeys = &$mapperKeys;
+    $this->_mapperKeys = $mapperKeys;
   }
 
   /**