You are here

function weather_update_7203 in Weather 7.3

Same name and namespace in other branches
  1. 7.2 weather.install \weather_update_7203()

Convert old locations to new locations.

File

./weather.install, line 721
Install, update and uninstall functions for the weather module.

Code

function weather_update_7203(&$sandbox) {
  module_load_include('inc', 'weather', 'weather.common');
  $old_locations = db_query('SELECT * FROM {weather_location} AS wl LEFT JOIN {weather_icao} AS wi on wl.icao=wi.icao');
  foreach ($old_locations as $old_location) {

    // Determine position of location.
    $new_place = weather_get_nearest_station($old_location->latitude, $old_location->longitude);
    $record = array(
      'display_type' => $old_location->display_type,
      'display_number' => $old_location->display_number,
      'place_geoid' => $new_place->geoid,
      // Append the old name to the new name to avoid confusion.
      // Also use the distance of the new place to the old place.
      'displayed_name' => $new_place->displayed_name . ' (' . $new_place->distance . ' km from ' . $old_location->real_name . ')',
      'weight' => $old_location->weight,
    );
    db_insert('weather_displays_places')
      ->fields($record)
      ->execute();
  }
}