From 7d03e8d641ca40381814f45068d4d33a8601859b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 18 May 2022 12:13:50 +1200 Subject: [PATCH] Fold array building in --- CRM/Contact/Import/Parser/Contact.php | 36 +++++++++++---------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 7cd690e084..cf14e61840 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -2336,33 +2336,25 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } $locationFields = ['location_type_id', 'phone_type_id', 'provider_id', 'website_type_id']; - $value = array_filter(array_intersect_key($mappedField, array_fill_keys($locationFields, 1))); - 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])) { - $params[$fieldName] = []; - } - $params[$fieldName][] = $value; - } + $locationValues = array_filter(array_intersect_key($mappedField, array_fill_keys($locationFields, 1))); - if (!isset($params[$fieldName])) { - $params[$fieldName] = $importedValue; + $contactArray = &$params; + if ($relatedContactKey) { + if (!isset($params[$relatedContactKey])) { + $params[$relatedContactKey] = ['contact_type' => $this->getRelatedContactType($mappedField['relationship_type_id'], $mappedField['relationship_direction'])]; } + $contactArray = &$params[$relatedContactKey]; + } + if (!empty($locationValues)) { + $locationValues[$fieldName] = $importedValue; + $contactArray[$fieldName] = (array) ($contactArray[$fieldName] ?? []); + $contactArray[$fieldName][] = $locationValues; } else { - if (!empty($value)) { - $params[$relatedContactKey][$fieldName][] = $importedValue ? [] : $value; - } - else { - $params[$relatedContactKey][$fieldName] = $importedValue; - } + // @todo - this is really the best point to convert labels + // to values. + $contactArray[$fieldName] = $importedValue; } } -- 2.25.1