You are here

domain.install in Domain Access 5

Same filename and directory in other branches
  1. 6.2 domain.install
  2. 7.3 domain.install
  3. 7.2 domain.install

Install file.

File

domain.install
View source
<?php

/**
 * @file
 * Install file.
 */

/**
 * Implement hook_install()
 */
function domain_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {domain} (\n        domain_id int(11) NOT NULL AUTO_INCREMENT,\n        subdomain varchar(255) NOT NULL default '',\n        sitename varchar(255) NOT NULL default '',\n        scheme varchar(8) NOT NULL default 'http',\n        valid varchar(1) NOT NULL default 1,\n        PRIMARY KEY  (domain_id),\n        KEY subdomain (subdomain)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {domain_access} (\n        nid int unsigned NOT NULL default '0',\n        gid int unsigned NOT NULL default '0',\n        realm varchar(255) NOT NULL default '',\n        PRIMARY KEY (nid,gid,realm),\n        INDEX (nid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {domain} (\n        domain_id serial,\n        subdomain varchar(255) NOT NULL default '',\n        sitename varchar(255) NOT NULL default '',\n        scheme varchar(8) NOT NULL default 'http',\n        valid varchar(1) NOT NULL default 1,\n        PRIMARY KEY (domain_id)\n        )");
      db_query("CREATE INDEX {domain}_subdomain_idx ON {domain} (subdomain)");
      db_query("CREATE TABLE {domain_access} (\n        nid int_unsigned NOT NULL default '0',\n        gid int_unsigned NOT NULL default '0',\n        realm varchar(255) NOT NULL default '',\n        PRIMARY KEY (nid,gid,realm)\n      )");
      db_query("CREATE INDEX {domain_access}_nid_idx ON {domain_access} (nid)");
      break;
  }

  // Create the 'all' realm for Domain Access.
  db_query("INSERT INTO {node_access} VALUES (0, 0, 'domain_all', 1, 0, 0)");

  // Set the primary domain.
  $root = strtolower(rtrim($_SERVER['SERVER_NAME']));
  $site = variable_get('site_name', 'Drupal');
  $scheme = 'http';
  if (!empty($_SERVER['HTTPS'])) {
    $scheme = 'https';
  }

  // Set the default domain variables.
  variable_set('domain_root', $root);
  variable_set('domain_scheme', $scheme);
  variable_set('domain_sitename', $site);
}

/**
 * Implement hook_uninstall()
 */
function domain_uninstall() {
  db_query("DROP TABLE {domain}");
  db_query("DROP TABLE {domain_access}");
  db_query("DELETE from {variable} WHERE name LIKE '%s%%'", 'domain_');
}

/**
 * Updates from beta6 to beta 7
 * Adds the valid column to the database.
 */
function domain_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {domain} ADD COLUMN valid varchar(1) NOT NULL DEFAULT 1");
      break;
    case 'pgsql':
      db_add_column($ret, 'domain', 'valid', 'varchar(1)', array(
        'not null' => TRUE,
        'default' => 1,
      ));
      break;
  }
  return $ret;
}

/**
 * Updates from rc2 to rc3.  Adds the {domain_access} table and copies
 * data from {node_access} to {domain_access}.
 *
 * Required to prevent deletions during node_access_rebuild().
 * See http://groups.drupal.org/node/7956
 */
function domain_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {domain_access} (\n        nid int unsigned NOT NULL default '0',\n        gid int unsigned NOT NULL default '0',\n        realm varchar(255) NOT NULL default '',\n        PRIMARY KEY (nid,gid,realm),\n        INDEX (nid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {domain_access} (\n        nid int_unsigned NOT NULL default '0',\n        gid int_unsigned NOT NULL default '0',\n        realm varchar(255) NOT NULL default '',\n        PRIMARY KEY (nid,gid,realm)\n      )");
      $ret[] = update_sql("CREATE INDEX {domain_access}_nid_idx ON {domain_access} (nid)");
      break;
  }
  $realms = array(
    'domain_site',
    'domain_id',
    'domain_editor',
  );
  foreach ($realms as $realm) {
    $result = db_query("SELECT * FROM {node_access} WHERE realm = '%s'", $realm);
    while ($data = db_fetch_array($result)) {
      db_query("INSERT INTO {domain_access} VALUES (%d, %d, '%s')", $data['nid'], $data['gid'], $data['realm']);
    }
  }
  return $ret;
}

/**
 * Updates from 5.x.1.2 to 5.x.1.3.  This change affects the size
 * of the columns for 'subdomain' and 'sitename'.  See http://drupal.org/node/244142
 */
function domain_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {domain} CHANGE subdomain subdomain varchar(255) NOT NULL default ''");
      $ret[] = update_sql("ALTER TABLE {domain} CHANGE sitename sitename varchar(255) NOT NULL default ''");
      break;
    case 'pgsql':
      db_change_column($ret, 'domain', 'subdomain', 'subdomain', 'varchar(255)', array(
        'not null' => TRUE,
        'default' => "''",
      ));
      db_change_column($ret, 'domain', 'sitename', 'sitename', 'varchar(255)', array(
        'not null' => TRUE,
        'default' => "''",
      ));
      break;
  }
  return $ret;
}

/**
 * Updates to 5.x.12.
 * 
 * Removes the authoring and menu settings for the node form.
 * 
 */
function domain_update_5012() {
  $ret = array();
  $options = variable_get('domain_form_elements', array());
  if (isset($options['author'])) {
    unset($options['author']);
  }
  if (isset($options['menu'])) {
    unset($options['menu']);
  }
  variable_set('domain_form_elements', $options);
  return $ret;
}

Functions

Namesort descending Description
domain_install Implement hook_install()
domain_uninstall Implement hook_uninstall()
domain_update_1 Updates from beta6 to beta 7 Adds the valid column to the database.
domain_update_2 Updates from rc2 to rc3. Adds the {domain_access} table and copies data from {node_access} to {domain_access}.
domain_update_3 Updates from 5.x.1.2 to 5.x.1.3. This change affects the size of the columns for 'subdomain' and 'sitename'. See http://drupal.org/node/244142
domain_update_5012 Updates to 5.x.12.