You are here

domain_prefix.install in Domain Access 5

Same filename and directory in other branches
  1. 6.2 domain_prefix/domain_prefix.install

Install file for the Domain Prefix module

File

domain_prefix/domain_prefix.install
View source
<?php

/**
 * @file
 * Install file for the Domain Prefix module
 */

/**
 * Implement hook_install()
 *
 * @ingroup drupal
 */
function domain_prefix_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE IF NOT EXISTS {domain_prefix} (\n       domain_id int(11) NOT NULL default 0,\n       status smallint NOT NULL default 0,\n       tablename varchar(80) NOT NULL default '',\n       module varchar(80) NOT NULL default '',\n       source smallint NOT NULL default 0,\n       INDEX (domain_id)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {domain_prefix} (\n       domain_id integer NOT NULL default 0,\n       status smallint NOT NULL default 0,\n       tablename varchar(80) NOT NULL default '',\n       module varchar(80) NOT NULL default '',\n       source smallint NOT NULL default 0\n      )");
      db_query("CREATE INDEX {domain_prefix}_domain_id_idx ON {domain_prefix} (domain_id)");
      break;
  }
}

/**
 * Implement hook_uninstall()
 */
function domain_prefix_uninstall() {

  // We must drop all the created tables.
  $result = db_query("SELECT domain_id, tablename FROM {domain_prefix} WHERE status > 1");
  while ($table = db_fetch_array($result)) {
    $name = db_escape_table('domain_' . $table['domain_id'] . '_' . $table['tablename']);
    db_query("DROP TABLE {%s}", $name);
  }

  // If there are values in the sequences table, delete them.
  $result = db_query("SELECT DISTINCT(domain_id) FROM {domain_prefix} WHERE status > 1");
  while ($domain = db_fetch_array($result)) {
    db_query("DELETE FROM {sequences} WHERE name LIKE '{%s%}'", db_escape_table('domain_' . $domain['domain_id']));
  }

  // Now drop the storage table.
  db_query("DROP TABLE {domain_prefix}");
  variable_del('domain_prefix');
  variable_del('domain_prefix_options');
}

/**
 * Update from beta6 to beta7.
 * Adds the source column to the database.
 */
function domain_prefix_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {domain_prefix} ADD COLUMN source smallint NOT NULL DEFAULT 0");
      break;
    case 'pgsql':
      db_add_column($ret, 'domain_prefix', 'source', 'smallint', array(
        'not null' => TRUE,
        'default' => 0,
      ));
      break;
  }
  return $ret;
}

Functions

Namesort descending Description
domain_prefix_install Implement hook_install()
domain_prefix_uninstall Implement hook_uninstall()
domain_prefix_update_1 Update from beta6 to beta7. Adds the source column to the database.