[REF] Import - make condition clearer
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 5 May 2022 22:48:28 +0000 (10:48 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 9 May 2022 10:28:35 +0000 (22:28 +1200)
The mapping of fields basically breaks down into 'has a relationship' - in which
case fieldName is empy and does not have a relationship - in which
case field name is not empy. This makes that explicit -
specifically referring to relatedContactKey rather than
relying on the person reading the code
understanding that the presence of fieldName implies
whether it is a relationship

CRM/Contact/Import/Parser/Contact.php

index bd2117ad8b3527ffa276fb91e4f0536922672cf8..8e369a0e779d76b873b0f6357903706ef453576f 100644 (file)
@@ -2637,44 +2637,45 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
       $importedValue = $this->_activeFields[$i]->_value;
 
       if (isset($importedValue)) {
-        if (isset($locationTypeID)) {
-          if (!isset($params[$fieldName])) {
-            $params[$fieldName] = [];
-          }
+        if (!$relatedContactKey) {
+          if (isset($locationTypeID)) {
+            if (!isset($params[$fieldName])) {
+              $params[$fieldName] = [];
+            }
 
-          $value = [
-            $fieldName => $importedValue,
-            'location_type_id' => $locationTypeID,
-          ];
+            $value = [
+              $fieldName => $importedValue,
+              'location_type_id' => $locationTypeID,
+            ];
 
-          if (isset($phoneTypeID)) {
-            $value['phone_type_id'] = $phoneTypeID;
-          }
+            if (isset($phoneTypeID)) {
+              $value['phone_type_id'] = $phoneTypeID;
+            }
 
-          // get IM service Provider type id
-          if (isset($imProviderID)) {
-            $value['provider_id'] = $imProviderID;
-          }
+            // get IM service Provider type id
+            if (isset($imProviderID)) {
+              $value['provider_id'] = $imProviderID;
+            }
 
-          $params[$fieldName][] = $value;
-        }
-        elseif (isset($websiteTypeID)) {
-          $value = [
-            $fieldName => $importedValue,
-            'website_type_id' => $websiteTypeID,
-          ];
+            $params[$fieldName][] = $value;
+          }
+          elseif (isset($websiteTypeID)) {
+            $value = [
+              $fieldName => $importedValue,
+              'website_type_id' => $websiteTypeID,
+            ];
 
-          $params[$fieldName][] = $value;
-        }
+            $params[$fieldName][] = $value;
+          }
 
-        if (!isset($params[$fieldName])) {
-          if (!isset($relatedContactKey)) {
-            $params[$fieldName] = $importedValue;
+          if (!isset($params[$fieldName])) {
+            if (!isset($relatedContactKey)) {
+              $params[$fieldName] = $importedValue;
+            }
           }
-        }
 
-        //minor fix for CRM-4062
-        if (isset($relatedContactKey)) {
+        }
+        else {
           if (!isset($params[$relatedContactKey])) {
             $params[$relatedContactKey] = [];
           }