From 74af530e117b501ba6f79fa69fe5afca1f9bd2ff Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 21 Jun 2022 15:36:11 +1200 Subject: [PATCH] dev/core#3673 do not attempt to report empty related contact --- CRM/Contact/Import/Parser/Contact.php | 16 +++++++++------- .../Form/data/individual_related_create.csv | 2 ++ .../CRM/Contact/Import/Parser/ContactTest.php | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index a64158677a..50fd3d3696 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -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); diff --git a/tests/phpunit/CRM/Contact/Import/Form/data/individual_related_create.csv b/tests/phpunit/CRM/Contact/Import/Form/data/individual_related_create.csv index 4ae1fb27dd..f3bed8b730 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/data/individual_related_create.csv +++ b/tests/phpunit/CRM/Contact/Import/Form/data/individual_related_create.csv @@ -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,, diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 210a085cdb..2cdf6d492e 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -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']); } /** -- 2.25.1