From b515bdfb305693f11447145a7ee583afa3449ada Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 24 Jun 2017 10:09:17 +1200 Subject: [PATCH] Cleanup towards CRM-20759, define variables more legibly & consistently. I really want the 2 copy & paste variants of this code loop to be combinable but I think it takes a numebr of small changes to get there in a readable way --- CRM/Contact/Import/Form/MapField.php | 14 ++++++-------- CRM/Contact/Import/ImportJob.php | 7 +++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 9ba6188f0026..a5e3b307492d 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -717,7 +717,7 @@ public function formatCustomFieldName(&$fields) { * @return \CRM_Contact_Import_Parser_Contact */ public function submit($params, $mapperKeys) { - $mapper = $mapperKeysMain = array(); + $mapper = $mapperKeysMain = $parserParameters = $locations = array(); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); @@ -727,11 +727,9 @@ public function submit($params, $mapperKeys) { //these mapper params need to set key as array and val as null. $mapperParams = array( 'related' => 'relatedVal', - 'locations' => 'locationsVal', 'mapperLocType' => 'mapperLocTypeVal', 'mapperPhoneType' => 'mapperPhoneTypeVal', 'mapperImProvider' => 'mapperImProviderVal', - 'mapperWebsiteType' => 'mapperWebsiteTypeVal', 'relatedContactType' => 'relatedContactTypeVal', 'relatedContactDetails' => 'relatedContactDetailsVal', 'relatedContactLocType' => 'relatedContactLocTypeVal', @@ -761,10 +759,10 @@ public function submit($params, $mapperKeys) { //need to differentiate non location elements. if ($selOne && is_numeric($selOne)) { if ($fldName == 'url') { - $mapperWebsiteTypeVal = $websiteTypes[$selOne]; + $parserParameters[$i]['mapperWebsiteType'] = $websiteTypes[$selOne]; } else { - $locationsVal = $locationTypes[$selOne]; + $locations[$i] = $locationTypes[$selOne]; $mapperLocTypeVal = $selOne; if ($selTwo && is_numeric($selTwo)) { if ($fldName == 'phone') { @@ -815,14 +813,14 @@ public function submit($params, $mapperKeys) { } $this->set('columnNames', $this->_columnNames); + $this->set('websites', $parserParameters['mapperWebsiteType']); + $this->set('locations', $locations); //set main contact properties. $properties = array( 'ims' => 'mapperImProvider', 'mapper' => 'mapper', 'phones' => 'mapperPhoneType', - 'websites' => 'mapperWebsiteType', - 'locations' => 'locations', ); foreach ($properties as $propertyName => $propertyVal) { $this->set($propertyName, $$propertyVal); @@ -999,7 +997,7 @@ public function submit($params, $mapperKeys) { $mapperImProvider, $related, $relatedContactType, $relatedContactDetails, $relatedContactLocType, $relatedContactPhoneType, $relatedContactImProvider, - $mapperWebsiteType, $relatedContactWebsiteType + $parserParameters['mapperWebsiteType'], $relatedContactWebsiteType ); $primaryKeyName = $this->get('primaryKeyName'); diff --git a/CRM/Contact/Import/ImportJob.php b/CRM/Contact/Import/ImportJob.php index 7c278e6380c6..185e7dafc6fc 100644 --- a/CRM/Contact/Import/ImportJob.php +++ b/CRM/Contact/Import/ImportJob.php @@ -60,7 +60,6 @@ class CRM_Contact_Import_ImportJob { protected $_mapperLocTypes; protected $_mapperPhoneTypes; protected $_mapperImProviders; - protected $_mapperWebsiteTypes; protected $_mapperRelated; protected $_mapperRelatedContactType; protected $_mapperRelatedContactDetails; @@ -168,7 +167,7 @@ public function setJobParams(&$params) { */ public function runImport(&$form, $timeout = 55) { $mapper = $this->_mapper; - $mapperFields = array(); + $mapperFields = $parserParameters = array(); $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); @@ -206,7 +205,7 @@ public function runImport(&$form, $timeout = 55) { if ($selOne && is_numeric($selOne)) { if ($fldName == 'url') { $header[] = $websiteTypes[$selOne]; - $mapperWebsiteTypesVal = $selOne; + $parserParameters['mapperWebsiteType'][$key] = $selOne; } else { $header[] = $locationTypes[$selOne]; @@ -283,7 +282,7 @@ public function runImport(&$form, $timeout = 55) { $this->_mapperRelatedContactLocType, $this->_mapperRelatedContactPhoneType, $this->_mapperRelatedContactImProvider, - $this->_mapperWebsiteTypes, + $parserParameters['mapperWebsiteType'], $this->_mapperRelatedContactWebsiteType );