You are here

browscap.install in Browscap 6

Install, update and uninstall functions for the Browscap module.

File

browscap.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Browscap module.
 */

// Include the browscap information retrieval functions
include_once 'import.inc';

/**
 * Implementation of hook_install.
 */
function browscap_install() {

  // Create tables
  drupal_install_schema('browscap');

  // Update the browscap information
  _browscap_import();

  // Record when the browscap information was updated
  variable_set('browscap_imported', time());
}

/**
 * Implementation of hook_schema.
 */
function browscap_schema() {
  $schema['browscap'] = array(
    'fields' => array(
      'useragent' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'type' => 'blob',
        'size' => 'big',
      ),
    ),
    'primary key' => array(
      'useragent',
    ),
  );
  $schema['browscap_statistics'] = array(
    'fields' => array(
      'parent' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'counter' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'is_crawler' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'parent',
    ),
  );
  $schema['cache_browscap'] = array(
    'fields' => array(
      'cid' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'type' => 'blob',
        'size' => 'big',
      ),
      'expire' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'headers' => array(
        'type' => 'text',
      ),
      'serialized' => array(
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'cid',
    ),
    'indexes' => array(
      'expire' => array(
        'expire',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_uninstall.
 */
function browscap_uninstall() {
  drupal_uninstall_schema('browscap');
  variable_del('browscap_imported');
  variable_del('browscap_version');
  variable_del('browscap_enable_automatic_updates');
  variable_del('browscap_automatic_updates_timer');
  variable_del('browscap_enable_user_agent_log');
}

/**
 * Add the browscap cache table.
 */
function browscap_update_6000() {
  $ret = array();
  if (!db_column_exists('cache_browscap', 'serialized')) {
    db_add_field($ret, 'cache_browscap', 'serialized', array(
      'type' => 'int',
      'size' => 'small',
      'not null' => TRUE,
      'default' => 0,
    ));
  }
  return $ret;
}

/**
 * Rename and remove old variables.
 */
function browscap_update_6001() {

  // Find the length of the update interval
  $browscap_update_interval = variable_get('browscap_update_interval', 7);

  // If the interval length was 0 then disable updates
  if ($browscap_update_interval == 0) {
    variable_set('browscap_enable_automatic_updates', FALSE);
  }

  // Delete the interval variable
  variable_del('browscap_update_interval');

  // Rename the user agent monitoring variable
  $browscap_monitor = variable_get('browscap_monitor', FALSE);
  variable_set('browscap_enable_user_agent_log', $browscap_monitor);
  variable_del('browscap_monitor');
  return array(
    array(
      'success' => TRUE,
      'query' => 'Renamed and removed old variables.',
    ),
  );
}

Functions

Namesort descending Description
browscap_install Implementation of hook_install.
browscap_schema Implementation of hook_schema.
browscap_uninstall Implementation of hook_uninstall.
browscap_update_6000 Add the browscap cache table.
browscap_update_6001 Rename and remove old variables.