You are here

function location_update_7 in Location 7.3

Same name and namespace in other branches
  1. 5.3 location.install \location_update_7()
  2. 5 location.install \location_update_7()
  3. 6.3 location.install \location_update_7()
  4. 7.5 location.install \location_update_7()
  5. 7.4 location.install \location_update_7()

Update 7 (Location 2.x).

Generalize google geocoding so you don't have to enter the api key over and over.

File

./location.install, line 481
Install, update and uninstall functions for the location module.

Code

function location_update_7() {
  $services = array(
    'google',
  );
  $general_geocoders_in_use = array();
  $result = db_query("SELECT * FROM {variable} WHERE name REGEXP '^location_geocode_[a-z][a-z]\$'");
  foreach ($result as $row) {
    $value_decoded = unserialize($row->value);
    if (!in_array($value_decoded, $services)) {
      db_update('variable')
        ->fields(array(
        'value' => serialize($value_decoded . '|' . substr($row->name, 17)),
      ))
        ->condition('name', $row->name)
        ->execute();
    }
    else {
      $general_geocoders_in_use[$value_decoded] = $value_decoded;
    }
  }
  $key = db_query("SELECT value FROM {variable} WHERE name REGEXP '^location_geocode_[a-z][a-z]_google_apikey\$'")
    ->fetchField();
  db_delete('variable')
    ->where("name REGEXP '^location_geocode_[a-z][a-z]_google_apikey\$'")
    ->execute();
  db_insert('variable')
    ->fields(array(
    'name' => 'location_geocode_google_apikey',
    'value' => $key,
  ))
    ->execute();
  db_delete('cache')
    ->condition('cid', 'variables')
    ->execute();
  variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
}