Skip to content

Commit

Permalink
[#44] fixed cached address issue (important), merged issue/44
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Dec 9, 2021
2 parents 06db17f + e84a8a9 commit 156849f
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions CRM/I3val/Handler/AddressUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,28 +517,25 @@ protected function getCountryList() {
*/
protected function getExistingAddresses($contact_id) {
// load all addresses
static $addresses = NULL;
if ($addresses === NULL) {
try {
$query = civicrm_api3('Address', 'get', [
'contact_id' => $contact_id,
'option.limit' => 0,
'option.sort' => 'is_primary desc',
'sequential' => 1]);
$addresses = [];

// enrich data
foreach ($query['values'] as $address) {
$this->resolveFields($address);
if (isset($addresses[$address['location_type_id']])) {
throw new Exception("Contact [{$contact_id}] has multiple addresses for location type '{$address['location_type']}'. Please fix!");
} else {
$addresses[$address['location_type_id']] = $address;
}
$addresses = [];
try {
$query = civicrm_api3('Address', 'get', [
'contact_id' => $contact_id,
'option.limit' => 0,
'option.sort' => 'is_primary desc',
'sequential' => 1]);

// enrich data
foreach ($query['values'] as $address) {
$this->resolveFields($address);
if (isset($addresses[$address['location_type_id']])) {
throw new Exception("Contact [{$contact_id}] has multiple addresses for location type '{$address['location_type']}'. Please fix!");
} else {
$addresses[$address['location_type_id']] = $address;
}
} catch (Exception $ex) {
throw new Exception("Error while loading addresses for contact [{$contact_id}]: " . $ex->getMessage());
}
} catch (Exception $ex) {
throw new Exception("Error while loading addresses for contact [{$contact_id}]: " . $ex->getMessage());
}
return $addresses;
}
Expand Down

0 comments on commit 156849f

Please sign in to comment.