CRM-19784: Updated direct usages of the geocoding provider to use the
authorFrank J. Gómez <frank@ginkgostreet.com>
Fri, 2 Feb 2018 14:02:21 +0000 (09:02 -0500)
committerFrank J. Gómez <frank@ginkgostreet.com>
Fri, 2 Feb 2018 23:17:43 +0000 (18:17 -0500)
new methods instead.

CRM/Contact/BAO/ProximityQuery.php
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Form/Search/Criteria.php
CRM/Contact/Form/Search/Custom/Proximity.php
CRM/Contact/Import/Form/DataSource.php
CRM/Core/BAO/Address.php
CRM/Utils/Address/BatchUpdate.php

index 0418f5ab2ea47f25682a76d14385e95d72b5b125..9e971404b635e025e7159f933d4b82d13c0da33e 100644 (file)
@@ -333,15 +333,12 @@ ACOS(
       )
     );
 
-    $fnName = isset($config->geocodeMethod) ? $config->geocodeMethod : NULL;
-    if (empty($fnName)) {
-      CRM_Core_Error::fatal(ts('Proximity searching requires you to set a valid geocoding provider'));
-    }
-
     $query->_tables['civicrm_address'] = $query->_whereTables['civicrm_address'] = 1;
 
-    require_once str_replace('_', DIRECTORY_SEPARATOR, $fnName) . '.php';
-    $fnName::format($proximityAddress);
+    if (!CRM_Core_BAO_Address::addGeocoderData($proximityAddress)) {
+      throw new CRM_Core_Exception(ts('Proximity searching requires you to set a valid geocoding provider'));
+    }
+
     if (
       !is_numeric(CRM_Utils_Array::value('geo_code_1', $proximityAddress)) ||
       !is_numeric(CRM_Utils_Array::value('geo_code_2', $proximityAddress))
index d7b0275ad92ea9b79414dd52201b9c371071f25d..c3da42fa62ce3ebba5f205d56a60aa44ea71f9f8 100644 (file)
@@ -153,7 +153,7 @@ class CRM_Contact_Form_Edit_Address {
 
     // CRM-11665 geocode override option
     $geoCode = FALSE;
-    if (!empty($config->geocodeMethod)) {
+    if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
       $geoCode = TRUE;
       $form->addElement('checkbox',
         "address[$blockId][manual_geo_code]",
index f876e40e81294ec5f3a283577e003559ae7aa4d9..8626b77483ee379de632b08958acd4f8e2e95944 100644 (file)
@@ -355,7 +355,7 @@ class CRM_Contact_Form_Search_Criteria {
     }
 
     // extend addresses with proximity search
-    if (!empty($config->geocodeMethod)) {
+    if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
       $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
       $form->addElement('select', 'prox_distance_unit', NULL, array(
         'miles' => ts('Miles'),
index 8375adee013f87b3c592de469543ab6fd317d3b6..5a86cebdd93083ba8de5ce94f28c422d8157274d 100644 (file)
@@ -64,13 +64,13 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C
       }
 
       // use the address to get the latitude and longitude
-      CRM_Utils_Geocode_Google::format($this->_formValues);
+      CRM_Core_BAO_Address::addGeocoderData($this->_formValues);
 
       if (!is_numeric(CRM_Utils_Array::value('geo_code_1', $this->_formValues)) ||
         !is_numeric(CRM_Utils_Array::value('geo_code_2', $this->_formValues)) ||
         !isset($this->_formValues['distance'])
       ) {
-        CRM_Core_Error::fatal(ts('Could not geocode input'));
+        throw new CRM_Core_Exception(ts('Could not geocode input'));
       }
 
       $this->_latitude = $this->_formValues['geo_code_1'];
index dbbf7d6abc2c6e741da5a0c72a4a90fdc5c36bd7..131c00fa7329833f19aa3506bb929a4c92bfbf9c 100644 (file)
@@ -203,7 +203,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form {
 
     $config = CRM_Core_Config::singleton();
     $geoCode = FALSE;
-    if (!empty($config->geocodeMethod)) {
+    if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
       $geoCode = TRUE;
       $this->addElement('checkbox', 'doGeocodeAddress', ts('Geocode addresses during import?'));
     }
index 801d8a041e0751ea636b83364d109c7f49e16de2..b66f01a11b05c3231287eede4e9766888aaac38d 100644 (file)
@@ -342,8 +342,6 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
       $params['country'] = CRM_Core_PseudoConstant::country($params['country_id']);
     }
 
-    $config = CRM_Core_Config::singleton();
-
     $asp = Civi::settings()->get('address_standardization_provider');
     // clean up the address via USPS web services if enabled
     if ($asp === 'USPS' &&
@@ -378,14 +376,12 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
       $params = array_merge($params, $parsedFields);
     }
 
-    // check if geocode should be skipped (can be forced with an optional parameter through the api)
-    $skip_geocode = (isset($params['skip_geocode']) && $params['skip_geocode']) ? TRUE : FALSE;
-
-    // add latitude and longitude and format address if needed
-    if (!$skip_geocode && !empty($config->geocodeMethod) && ($config->geocodeMethod != 'CRM_Utils_Geocode_OpenStreetMaps') && empty($params['manual_geo_code'])) {
-      $class = $config->geocodeMethod;
-      $class::format($params);
+    // skip_geocode is an optional parameter through the api.
+    // manual_geo_code is on the contact edit form. They do the same thing....
+    if (empty($params['skip_geocode']) && empty($params['manual_geo_code'])) {
+      self::addGeocoderData($params);
     }
+
   }
 
   /**
index 06b3839c37c51d98d1610e3c6f89358f70215d16..0433067848f697f7da46c3dc5e462706a004503c 100644 (file)
@@ -69,11 +69,9 @@ class CRM_Utils_Address_BatchUpdate {
    */
   public function run() {
 
-    $config = &CRM_Core_Config::singleton();
-
     // do check for geocoding.
     $processGeocode = FALSE;
-    if (empty($config->geocodeMethod)) {
+    if (!CRM_Utils_GeocodeProvider::getUsableClassName()) {
       if (CRM_Utils_String::strtobool($this->geocoding) === TRUE) {
         $this->returnMessages[] = ts('Error: You need to set a mapping provider under Administer > System Settings > Mapping and Geocoding');
         $this->returnError = 1;
@@ -120,20 +118,19 @@ class CRM_Utils_Address_BatchUpdate {
     }
 
     // do check for parse street address.
-    return $this->processContacts($config, $processGeocode, $parseStreetAddress);
+    return $this->processContacts($processGeocode, $parseStreetAddress);
   }
 
   /**
    * Process contacts.
    *
-   * @param CRM_Core_Config $config
    * @param bool $processGeocode
    * @param bool $parseStreetAddress
    *
    * @return array
    * @throws Exception
    */
-  public function processContacts(&$config, $processGeocode, $parseStreetAddress) {
+  public function processContacts($processGeocode, $parseStreetAddress) {
     // build where clause.
     $clause = array('( c.id = a.contact_id )');
     $params = array();
@@ -174,9 +171,6 @@ class CRM_Utils_Address_BatchUpdate {
     $totalGeocoded = $totalAddresses = $totalAddressParsed = 0;
 
     $dao = CRM_Core_DAO::executeQuery($query, $params);
-    if ($processGeocode) {
-      require_once str_replace('_', DIRECTORY_SEPARATOR, $config->geocodeMethod) . '.php';
-    }
 
     $unparseableContactAddress = array();
     while ($dao->fetch()) {
@@ -203,8 +197,7 @@ class CRM_Utils_Address_BatchUpdate {
             usleep(5000000);
           }
 
-          $className = $config->geocodeMethod;
-          $className::format($params, TRUE);
+          CRM_Core_BAO_Address::addGeocoderData($params);
 
           // see if we got a geocode error, in this case we'll trigger a fatal
           // CRM-13760
@@ -212,7 +205,7 @@ class CRM_Utils_Address_BatchUpdate {
             isset($params['geo_code_error']) &&
             $params['geo_code_error'] == 'OVER_QUERY_LIMIT'
           ) {
-            CRM_Core_Error::fatal('Aborting batch geocoding. Hit the over query limit on geocoder.');
+            throw new CRM_Core_Exception('Aborting batch geocoding. Hit the over query limit on geocoder.');
           }
 
           array_shift($params);