You are here

yr_verdata.install in Yr Weatherdata 6

Same filename and directory in other branches
  1. 6.2 yr_verdata.install
  2. 7.3 yr_verdata.install
  3. 7 yr_verdata.install

The install schema and hooks for yr_verdata.module.

File

yr_verdata.install
View source
<?php

/**
 * @file
 * The install schema and hooks for yr_verdata.module.
 */

/**
 * Implementation of hook_requirements().
 */
function yr_verdata_requirements($phase) {
  $requirements = array();
  $t = get_t();
  $value = '';
  switch ($phase) {
    case 'install':
      if (!function_exists('curl_init')) {
        $description = $t('cURL must be available for yr_verdata to function properly.');
        $severity = REQUIREMENT_ERROR;
        $requirements['curl'] = array(
          'title' => 'curl',
          'description' => $description,
          'severity' => $severity,
        );
      }
      if (!function_exists('simplexml_load_file')) {
        $value = $t('The SimpleXML class is required. This class is built-in with PHP 5 and up.');
        $severity = REQUIREMENT_ERROR;
        $requirements['simplexml'] = array(
          'title' => 'simplexml',
          'description' => $description,
          'severity' => $severity,
        );
      }
      break;
  }
  return $requirements;
}

/**
 * Implementation of hook_install().
 */
function yr_verdata_install() {
  drupal_install_schema('yr_verdata');
}

/**
 * Implementation of hook_uninstall().
 */
function yr_verdata_uninstall() {
  drupal_uninstall_schema('yr_verdata');
}

/**
 * Implementation of hook_schema().
 */
function yr_verdata_schema() {
  $schema['yr_verdata'] = array(
    'description' => 'Store locations to display forecast for on the site.',
    'fields' => array(
      'yid' => array(
        'description' => 'The unique "yr-ID".',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'url' => array(
        'description' => 'The string to append to "http://yr.no/" to create the complete url for fetching xml data.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
      ),
      'location' => array(
        'description' => "The location's locationname, only applicable for locations in Norway.",
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => '',
      ),
      'subregion' => array(
        'description' => "The location's subregion, which is the locationname for locations outside Norway.",
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => '',
      ),
      'region' => array(
        'description' => "The location's region.",
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => '',
      ),
      'country' => array(
        'description' => "The location's country.",
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'yid',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_update_N().
 */
function yr_verdata_update_6101() {
  $ret = array();
  db_add_field($ret, 'yr_verdata', 'location', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'yr_verdata', 'subregion', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'yr_verdata', 'region', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field($ret, 'yr_verdata', 'country', array(
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
  $sql = "SELECT * FROM {yr_verdata}";
  $result = db_query($sql);
  while ($row = db_fetch_object($result)) {
    $comps = explode('/', $row->url);
    $location = !empty($comps[4]) ? $comps[4] : 'x';
    $args = array(
      $comps[1],
      $comps[2],
      $comps[3],
      $location,
      $row->yid,
    );
    update_sql("UPDATE {yr_verdata} SET location = '{$location}', subregion = '{$comps[3]}', region = '{$comps[2]}', country = '{$comps[1]}' WHERE yid = {$row->yid}");
  }
  return $ret;
}

Functions

Namesort descending Description
yr_verdata_install Implementation of hook_install().
yr_verdata_requirements Implementation of hook_requirements().
yr_verdata_schema Implementation of hook_schema().
yr_verdata_uninstall Implementation of hook_uninstall().
yr_verdata_update_6101 Implementation of hook_update_N().