Skip to content

Commit

Permalink
Cleanup towards CRM-20759, define variables more legibly & consistently.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Jun 23, 2017
1 parent 613a881 commit e884fae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 6 additions & 8 deletions CRM/Contact/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
7 changes: 3 additions & 4 deletions CRM/Contact/Import/ImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class CRM_Contact_Import_ImportJob {
protected $_mapperLocTypes;
protected $_mapperPhoneTypes;
protected $_mapperImProviders;
protected $_mapperWebsiteTypes;
protected $_mapperRelated;
protected $_mapperRelatedContactType;
protected $_mapperRelatedContactDetails;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'][$i] = $selOne;
}
else {
$header[] = $locationTypes[$selOne];
Expand Down Expand Up @@ -283,7 +282,7 @@ public function runImport(&$form, $timeout = 55) {
$this->_mapperRelatedContactLocType,
$this->_mapperRelatedContactPhoneType,
$this->_mapperRelatedContactImProvider,
$this->_mapperWebsiteTypes,
$parserParameters['mapperWebsiteType'],
$this->_mapperRelatedContactWebsiteType
);

Expand Down

0 comments on commit e884fae

Please sign in to comment.