From a7b1e2835ed091f5e7a96a6e4fd16ac370a79fb4 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 8 Dec 2022 19:46:18 +1300 Subject: [PATCH] Stop using single hard-coded value array --- CRM/Contact/Import/Parser/Contact.php | 36 ++++++++++----------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 49c14051ce..91af59cd8a 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -900,7 +900,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { * @param int $cid * contact id. */ - public function formatParams(&$params, $cid) { + private function formatParams(&$params, $cid) { if ($this->isSkipDuplicates()) { return; } @@ -917,18 +917,10 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { $groupTree = CRM_Core_BAO_CustomGroup::getTree($params['contact_type'], NULL, $cid, 0, NULL); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults, FALSE, FALSE); - $locationFields = [ - 'address' => 'address', - ]; - $contact = get_object_vars($contactObj); foreach ($params as $key => $value) { - if ($key == 'id' || $key == 'contact_type') { - continue; - } - - if (array_key_exists($key, $locationFields)) { + if ($key === 'id' || $key === 'contact_type' || $key === 'address') { continue; } @@ -953,24 +945,22 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser { } } - foreach ($locationFields as $locKeys) { - if (isset($params[$locKeys]) && is_array($params[$locKeys])) { - foreach ($params[$locKeys] as $key => $value) { - if ($modeFill) { - $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $locKeys); + if (isset($params['address']) && is_array($params['address'])) { + foreach ($params['address'] as $key => $value) { + if ($modeFill) { + $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, 'address'); - if (isset($getValue)) { - foreach ($getValue as $cnt => $values) { - if ((!empty($getValue[$cnt]['location_type_id']) && !empty($params[$locKeys][$key]['location_type_id'])) && $getValue[$cnt]['location_type_id'] == $params[$locKeys][$key]['location_type_id']) { - unset($params[$locKeys][$key]); - } + if (isset($getValue)) { + foreach ($getValue as $cnt => $values) { + if ((!empty($getValue[$cnt]['location_type_id']) && !empty($params['address'][$key]['location_type_id'])) && $getValue[$cnt]['location_type_id'] == $params['address'][$key]['location_type_id']) { + unset($params['address'][$key]); } } } } - if (count($params[$locKeys]) == 0) { - unset($params[$locKeys]); - } + } + if (count($params['address']) == 0) { + unset($params['address']); } } } -- 2.25.1