Skip to content

Commit

Permalink
Merge pull request #10181 from jmcclelland/CRM-20381
Browse files Browse the repository at this point in the history
CRM-20381 - ensure option to NOT geocode on imports is respected.
  • Loading branch information
totten authored Jun 4, 2017
2 parents dd285a5 + 31466f3 commit 6038bae
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function import($onDuplicate, &$values, $doGeocodeAddress = FALSE) {
$this->_unparsedStreetAddressContacts = array();
if (!$doGeocodeAddress) {
// CRM-5854, reset the geocode method to null to prevent geocoding
$config->geocodeMethod = NULL;
$config->geocodeMethod = '';
}

// first make sure this is a valid line
Expand Down
5 changes: 4 additions & 1 deletion CRM/Core/Config/MagicMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ public function __set($k, $v) {
}
unset($this->cache[$k]);
$type = $this->map[$k][0];
$name = isset($this->map[$k][1]) ? $this->map[$k][1] : $k;

// If foreign name is set, use that name (except with callback types because
// their second parameter is the object, not the foreign name).
$name = isset($this->map[$k][1]) && $type != 'callback' ? $this->map[$k][1] : $k;

switch ($type) {
case 'setting':
Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/CRM/Utils/GeocodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,39 @@ public function testStateProvinceFormat() {
$this->assertApproxEquals('-94.68', $params['geo_code_2'], 1);
}

public function testGeocodeMethodOff() {
// Set a geocoding provider.
$result = civicrm_api3('Setting', 'create', array(
'geoProvider' => "Google",
));

// Save a contact without disabling geo coding.
$params = array(
'first_name' => 'Abraham',
'last_name' => 'Lincoln',
'contact_type' => 'Individual',
'api.Address.create' => array(
'street_address' => '1600 Pennsylvania Avenue',
'city' => 'Washington',
'state_province' => 'DC',
'location_type_id' => 1,
),
);
$result = civicrm_api3('Contact', 'create', $params);
$contact_values = array_pop($result['values']);
$address_values = array_pop($contact_values['api.Address.create']['values']);
// We should get a geo code setting.
$this->assertApproxEquals('38.89', $address_values['geo_code_1'], 1);

// Set geocodeMethod to empty.
$config = CRM_Core_Config::singleton();
$config->geocodeMethod = '';

// Do it again. This time, we should not geocode.
$new_result = civicrm_api3('Contact', 'create', $params);
$new_contact_values = array_pop($new_result['values']);
$new_address_values = array_pop($new_contact_values['api.Address.create']['values']);
$this->assertArrayNotHasKey('geo_code_1', $new_address_values, 'No geocoding when geocodeMethod is empty');
}

}

0 comments on commit 6038bae

Please sign in to comment.