domain.install in Domain Access 7.2
Same filename and directory in other branches
Install file.
File
domain.installView source
<?php
/**
* @file
* Install file.
*/
/**
* Implements hook_install()
*/
function domain_install() {
$root = strtolower(rtrim($_SERVER['SERVER_NAME']));
$site = variable_get('site_name', 'Drupal');
$scheme = 'http';
if (!empty($_SERVER['HTTPS'])) {
$scheme = 'https';
}
db_insert('domain')
->fields(array(
'subdomain' => $root,
'sitename' => $site,
'scheme' => $scheme,
'valid' => 1,
))
->execute();
// MySQL won't let us insert row 0 into an autoincrement table. Deducting
// the value itself like this also handles auto_increment_offset settings.
// Similar to the {users} tablein Drupal 6, this leaves us with no row 1.
db_update('domain')
->expression('domain_id', 'domain_id - domain_id')
->execute();
// Set the default domain variables.
variable_set('domain_root', $root);
variable_set('domain_scheme', $scheme);
variable_set('domain_sitename', $site);
// Tag the default domain.
// In a later update function, we will remove the 0 record
// and change this value.
variable_set('domain_default', 0);
}
/**
* Implements hook_schema()
*/
function domain_schema() {
$schema['domain'] = array(
'description' => 'The base table for domain records',
'fields' => array(
'domain_id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'subdomain' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'sitename' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'scheme' => array(
'type' => 'varchar',
'length' => '8',
'not null' => TRUE,
'default' => 'http',
),
'valid' => array(
'type' => 'varchar',
'length' => '1',
'not null' => TRUE,
'default' => '1',
),
),
'primary key' => array(
'domain_id',
),
'indexes' => array(
'subdomain' => array(
'subdomain',
),
),
);
$schema['domain_access'] = array(
'description' => 'Stores domain information for each node',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'realm' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'nid',
'gid',
'realm',
),
'indexes' => array(
'nid' => array(
'nid',
),
),
'foreign_keys' => array(
'nid' => array(
'node' => 'nid',
),
),
);
$schema['domain_editor'] = array(
'description' => 'Stores domain information for each user',
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'domain_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'uid',
'domain_id',
),
'foreign_keys' => array(
'uid' => array(
'user' => 'uid',
),
'domain_id' => array(
'domain' => 'domain_id',
),
),
);
return $schema;
}
/**
* Implements hook_uninstall()
*/
function domain_uninstall() {
db_delete('variable')
->condition('name', db_like('domain_') . '%', 'LIKE')
->execute();
}
/**
* Update note.
*
* Upgrading from Drupal 5 to Drupal 7 is not supported.
* You must first upgrade to Drupal 6.x.2.3 or higher, and then proceed to Drupal 7.
*
*/
/**
* Update block deltas to Drupal 7.
*/
function domain_update_7000() {
// Get an array of the renamed block deltas, organized by module.
$renamed_deltas = array(
'domain' => array(
'0' => 'switcher',
'1' => 'information',
),
);
$moved_deltas = array();
update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas);
return t('Domain Access blocks updated.');
}
/**
* Change the edit and delete permissions.
*/
function domain_update_7001() {
db_update('role_permission')
->condition('permission', 'edit domain nodes')
->fields(array(
'permission' => 'edit domain content',
))
->execute();
db_update('role_permission')
->condition('permission', 'delete domain nodes')
->fields(array(
'permission' => 'delete domain content',
))
->execute();
return t('Updated Domain Access permission names.');
}
Functions
Name | Description |
---|---|
domain_install | Implements hook_install() |
domain_schema | Implements hook_schema() |
domain_uninstall | Implements hook_uninstall() |
domain_update_7000 | Update block deltas to Drupal 7. |
domain_update_7001 | Change the edit and delete permissions. |