Commit c35a8074 authored by Monish Deb's avatar Monish Deb Committed by GitHub

Merge pull request #10738 from eileenmcnaughton/prim_address

CRM-20759 (follow up fix) Primary address is 'distributed' over sever…
parents bc5238e9 c77e8e33
......@@ -2467,17 +2467,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
$params['address'] = array();
}
$addressCnt = 1;
foreach ($params['address'] as $cnt => $addressBlock) {
if (CRM_Utils_Array::value('location_type_id', $values) ==
CRM_Utils_Array::value('location_type_id', $addressBlock)
) {
$addressCnt = $cnt;
break;
}
$addressCnt++;
}
if (!array_key_exists('Address', $fields)) {
$fields['Address'] = CRM_Core_DAO_Address::fields();
}
......@@ -2530,7 +2519,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
$values = $newValues;
}
_civicrm_api3_store_values($fields['Address'], $values, $params['address'][$addressCnt]);
_civicrm_api3_store_values($fields['Address'], $values, $params['address'][$values['location_type_id']]);
$addressFields = array(
'county',
......@@ -2547,7 +2536,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
if (!array_key_exists('address', $params)) {
$params['address'] = array();
}
$params['address'][$addressCnt][$field] = $values[$field];
$params['address'][$values['location_type_id']][$field] = $values[$field];
}
}
......@@ -2556,14 +2545,9 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
$primary = civicrm_api3('Address', 'get', array('return' => 'location_type_id', 'contact_id' => $params['id'], 'is_primary' => 1, 'sequential' => 1));
}
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
$params['address'][$addressCnt]['location_type_id'] = (isset($primary) && $primary['count']) ? $primary['values'][0]['location_type_id'] : $defaultLocationType->id;
$params['address'][$addressCnt]['is_primary'] = 1;
}
if ($addressCnt == 1) {
$params['address'][$values['location_type_id']]['location_type_id'] = (isset($primary) && $primary['count']) ? $primary['values'][0]['location_type_id'] : $defaultLocationType->id;
$params['address'][$values['location_type_id']]['is_primary'] = 1;
$params['address'][$addressCnt]['is_primary'] = TRUE;
}
return TRUE;
}
......
......@@ -175,6 +175,7 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase {
$this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
$address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
$this->assertEquals(1, $address['location_type_id']);
$this->assertEquals(1, $address['is_primary']);
$phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '12334'));
$this->assertEquals(1, $phone['location_type_id']);
......@@ -290,12 +291,14 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase {
$contactValues['nick_name'] = 'Old Bill';
$contactValues['external_identifier'] = 'android';
$contactValues['street_address'] = 'Big Mansion';
$contactValues['city'] = 'Big City';
$contactID = $this->callAPISuccessGetValue('Contact', array('external_identifier' => 'android', 'return' => 'id'));
$originalAddress = $this->callAPISuccess('Address', 'create', array('location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID));
$this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary'));
$this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
$address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
$this->assertEquals(2, $address['location_type_id']);
$this->assertEquals($originalAddress['id'], $address['id']);
$this->assertEquals('Big City', $address['city']);
$this->callAPISuccessGetSingle('Contact', $contactValues);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment