diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 139f0ea6a958..84d03ee297d4 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -1297,6 +1297,8 @@ public static function addGeocoderData(&$params) { // ensure that if the geocoding provider (Google, OSM etc) has returned the string 'null' because they can't geocode, ensure that contacts are not placed on null island 0,0 if ($params[$geocode] !== 'null') { $params[$geocode] = (float) substr($params[$geocode], 0, 14); + //set manual_geo_code to 0 + $params['manual_geo_code'] = false; } } } diff --git a/CRM/Utils/Address/BatchUpdate.php b/CRM/Utils/Address/BatchUpdate.php index e00460b9900f..84f23557d0da 100644 --- a/CRM/Utils/Address/BatchUpdate.php +++ b/CRM/Utils/Address/BatchUpdate.php @@ -131,6 +131,10 @@ public function processContacts($processGeocode, $parseStreetAddress) { if ($processGeocode) { $clause[] = '( a.geo_code_1 is null OR a.geo_code_1 = 0 )'; $clause[] = '( a.geo_code_2 is null OR a.geo_code_2 = 0 )'; + /** + * the scheduled job is ignoring trying to geocode addresses where manual_geocode is 1 + */ + $clause[] = '( a.manual_geo_code = 0 )'; $clause[] = '( a.country_id is not null )'; } @@ -164,6 +168,7 @@ public function processContacts($processGeocode, $parseStreetAddress) { $dao = CRM_Core_DAO::executeQuery($query, $params); $unparseableContactAddress = []; + while ($dao->fetch()) { $totalAddresses++; $params = [ @@ -211,6 +216,12 @@ public function processContacts($processGeocode, $parseStreetAddress) { $totalGeocoded++; $addressParams = $params; } + else { + // If an address has failed in the geocoding scheduled job i.e. no lat/long is fetched, we will update the manual_geocode field to 1. + $addressParams['manual_geo_code'] = TRUE; + $addressParams['geo_code_1'] = 0; + $addressParams['geo_code_2'] = 0; + } } // parse street address @@ -222,7 +233,6 @@ public function processContacts($processGeocode, $parseStreetAddress) { if (empty($parsedFields['street_name']) || empty($parsedFields['street_number'])) { $success = FALSE; } - // do check for all elements. if ($success) { $totalAddressParsed++;