dev/core#3673 do not attempt to report empty related contact
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Jun 2022 03:36:11 +0000 (15:36 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Jun 2022 08:52:45 +0000 (20:52 +1200)
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Form/data/individual_related_create.csv
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index a64158677ab85145acc9d1d1a20df0f1483b46f8..50fd3d369613da50617660d65103f30b9aec1820 100644 (file)
@@ -1436,14 +1436,16 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
       $locationValues = array_filter(array_intersect_key($mappedField, array_fill_keys($locationFields, 1)));
 
       if ($relatedContactKey) {
-        if (!isset($params['relationship'][$relatedContactKey])) {
-          $params['relationship'][$relatedContactKey] = [
-            // These will be over-written by any the importer has chosen but defaults are based on the relationship.
-            'contact_type' => $this->getRelatedContactType($mappedField['relationship_type_id'], $mappedField['relationship_direction']),
-            'contact_sub_type' => $this->getRelatedContactSubType($mappedField['relationship_type_id'], $mappedField['relationship_direction']),
-          ];
+        if ($importedValue !== '') {
+          if (!isset($params['relationship'][$relatedContactKey])) {
+            $params['relationship'][$relatedContactKey] = [
+              // These will be over-written by any the importer has chosen but defaults are based on the relationship.
+              'contact_type' => $this->getRelatedContactType($mappedField['relationship_type_id'], $mappedField['relationship_direction']),
+              'contact_sub_type' => $this->getRelatedContactSubType($mappedField['relationship_type_id'], $mappedField['relationship_direction']),
+            ];
+          }
+          $this->addFieldToParams($params['relationship'][$relatedContactKey], $locationValues, $fieldName, $importedValue);
         }
-        $this->addFieldToParams($params['relationship'][$relatedContactKey], $locationValues, $fieldName, $importedValue);
       }
       else {
         $this->addFieldToParams($params, $locationValues, $fieldName, $importedValue);
index 4ae1fb27dd905e7d545386de8a4fb817dba75a8b..f3bed8b730e60685a0dbab266491f736b1c0dfb3 100644 (file)
@@ -1,3 +1,5 @@
 First Name,Last Name,Dad first name,Dad Last name,Dad email
 Bob,Smith,William,The Kid,billy-the-kid@example.com
 Sarah,Smith,Bill,The Grandkid,Billy-the-grand-kid@example.com
+Jenny ,Smith,,,
+Julie,Smith,Bill,,
index 210a085cdb1fa920cf22c43de27e157f0cfd5031..2cdf6d492ebcbe12c1d00708adbac5c54daf2ae3 100644 (file)
@@ -334,6 +334,11 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->assertEquals('IMPORTED', $row['_status']);
     $row = $dataSource->getRow();
     $this->assertEquals('IMPORTED', $row['_status']);
+    $row = $dataSource->getRow();
+    $this->assertEquals('IMPORTED', $row['_status']);
+    $row = $dataSource->getRow();
+    // currently Error with the message (Dad to) Missing required fields: Last Name OR Email Address OR External Identifier
+    // $this->assertEquals('IMPORTED', $row['_status']);
   }
 
   /**