Set up related Contact Key earlier
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 18 May 2022 00:02:50 +0000 (12:02 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 18 May 2022 00:02:50 +0000 (12:02 +1200)
CRM/Contact/Import/Parser/Contact.php

index b3cf391dc183e9757be47513cee08c5ac2f4fdba..7cd690e084a468d3bffa6ea778b42e15210aef0e 100644 (file)
@@ -2340,6 +2340,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
       if (!empty($value)) {
         $value[$fieldName] = $importedValue;
       }
+      if ($relatedContactKey && !isset($params[$relatedContactKey])) {
+        $params[$relatedContactKey] = ['contact_type' => $this->getRelatedContactType($mappedField['relationship_type_id'], $mappedField['relationship_direction'])];
+      }
       if (!$relatedContactKey) {
         if (!empty($value)) {
           if (!isset($params[$fieldName])) {
@@ -2354,10 +2357,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
 
       }
       else {
-        if (!isset($params[$relatedContactKey])) {
-          $params[$relatedContactKey] = ['contact_type' => $this->getRelatedContactType($mappedField['relationship_type_id'], $mappedField['relationship_direction'])];
-        }
-
         if (!empty($value)) {
           $params[$relatedContactKey][$fieldName][] = $importedValue ? [] : $value;
         }