function weather_install in Weather 5.6
Same name and namespace in other branches
- 8 weather.install \weather_install()
- 5 weather.install \weather_install()
- 6.5 weather.install \weather_install()
- 7.3 weather.install \weather_install()
- 7 weather.install \weather_install()
- 7.2 weather.install \weather_install()
- 2.0.x weather.install \weather_install()
Implementation of hook_install().
We use the install hook to clean up the Drupal tables from old variables used by previous versions of this module.
File
- ./
weather.install, line 31
Code
function weather_install() {
// these were used by the official module
variable_del('weather_region');
variable_del('weather_scale');
variable_del('weather_mini_block');
variable_del('weather_extended_forecast');
variable_del('weather_xml_feed');
variable_del('weather_recache_cache');
variable_del('weather_enable_cron');
// these were added by an inofficial module release for Drupal 4.7
variable_del('weather_host');
variable_del('weather_title');
// these were used in version 1.x of this module, they are no longer
// needed in the 2.x series
variable_del('weather_country');
variable_del('weather_icao');
variable_del('weather_icao_name');
variable_del('weather_place');
variable_del('weather_units');
variable_del('weather_use_cron');
// icao: ICAO code of the METAR station
// next_update_on: timestamp of next possible update
// metar_raw: raw METAR data, not parsed
$sql = "CREATE TABLE {weather} (\n icao VARCHAR(4) DEFAULT '' NOT NULL,\n next_update_on INTEGER DEFAULT 0 NOT NULL,\n metar_raw VARCHAR(255) DEFAULT '' NOT NULL,\n PRIMARY KEY (icao)\n )";
// ensure the utf8 character set on MySQL (syntax for 4.1 and above)
if ($GLOBALS['db_type'] == 'mysql' or $GLOBALS['db_type'] == 'mysqli') {
$sql .= " /*!40100 DEFAULT CHARACTER SET utf8 */";
}
db_query($sql);
// the table stores the configuration of a custom user weather block
// uid: user id
// cid: configuration id, to enable multiple locations in one block
// icao: ICAO code of the METAR station
// real_name: the name to display for the ICAO code
// units: units for display (metric, imperial)
// weight: the weight of the location
$sql = "CREATE TABLE {weather_config} (\n uid INTEGER DEFAULT 0 NOT NULL,\n cid INTEGER DEFAULT 0 NOT NULL,\n icao VARCHAR(4) DEFAULT '' NOT NULL,\n real_name VARCHAR(255) DEFAULT '' NOT NULL,\n units VARCHAR(255) DEFAULT '%s' NOT NULL,\n settings VARCHAR(255) DEFAULT '%s' NOT NULL,\n weight INTEGER DEFAULT 0 NOT NULL,\n PRIMARY KEY (uid, cid)\n )";
// ensure the utf8 character set on MySQL (syntax for 4.1 and above)
if ($GLOBALS['db_type'] == 'mysql' or $GLOBALS['db_type'] == 'mysqli') {
$sql .= " /*!40100 DEFAULT CHARACTER SET utf8 */";
}
// the table prefixing code removes all {} brackets, so we need
// to insert the brackets as string afterwards.
db_query($sql, 'a:4:{s:11:"temperature";s:7:"celsius";s:9:"windspeed";s:3:"kmh";s:8:"pressure";s:3:"hpa";s:10:"visibility";s:10:"kilometers";}', 'a:3:{s:22:"show_unconverted_metar";i:0;s:27:"show_abbreviated_directions";i:0;s:22:"show_directions_degree";i:0;}');
// the table holds all known ICAO codes with further information
// it's not decoupled, but that's probably not worth the effort.
// icao: ICAO code of the METAR station
// country: name of the country
// name: the METAR station's name
// latitude: degree of the station
// longitude: degree of the station
$sql = "CREATE TABLE {weather_icao} (\n icao VARCHAR(4) DEFAULT '' NOT NULL,\n country VARCHAR(255) DEFAULT '' NOT NULL,\n name VARCHAR(255) DEFAULT '' NOT NULL,\n latitude DOUBLE PRECISION DEFAULT 0.0 NOT NULL,\n longitude DOUBLE PRECISION DEFAULT 0.0 NOT NULL,\n PRIMARY KEY (icao)\n )";
// ensure the utf8 character set on MySQL (syntax for 4.1 and above)
if ($GLOBALS['db_type'] == 'mysql' or $GLOBALS['db_type'] == 'mysqli') {
$sql .= " /*!40100 DEFAULT CHARACTER SET utf8 */";
}
db_query($sql);
_weather_fill_icao_table();
}