domain.install in Domain Access 6.2
Same filename and directory in other branches
Install file.
File
domain.installView source
<?php
/**
* @file
* Install file.
*/
/**
* Implement hook_install()
*/
function domain_install() {
drupal_install_schema('domain');
$root = strtolower(rtrim($_SERVER['SERVER_NAME']));
$site = variable_get('site_name', 'Drupal');
$scheme = 'http';
if (!empty($_SERVER['HTTPS'])) {
$scheme = 'https';
}
db_query("UPDATE {domain} SET subdomain = '%s', sitename = '%s', scheme = '%s', valid = 1 WHERE domain_id = 0", $root, $site, $scheme);
if (!db_affected_rows()) {
db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $root, $site, $scheme, 1);
// 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} table, this leaves us with no row 1.
db_query("UPDATE {domain} SET domain_id = domain_id - domain_id");
}
// Set the default domain variables.
variable_set('domain_root', $root);
variable_set('domain_scheme', $scheme);
variable_set('domain_sitename', $site);
}
/**
* Implement hook_schema()
*/
function domain_schema() {
$schema['domain'] = array(
'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(
'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',
),
),
);
$schema['domain_editor'] = array(
'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',
),
);
return $schema;
}
/**
* Implement hook_uninstall()
*/
function domain_uninstall() {
drupal_uninstall_schema('domain');
db_query("DELETE from {variable} WHERE name LIKE '%s%%'", 'domain_');
}
/**
* Update note.
*
* Since versions prior to 5.x.1.0 are not supported, and ther are no schema changes from
* 5.x.1 to 6.x.1, no update functions have been provided for Drupal 6.
*
* To upgrade from a release candidate, first upgrade the module to 5.x.1.0. Then upgrade
* to Drupal 6.
*
*/
/**
* Updates from 5.x.1.2 to 5.x.1.3. This change affected the size
* of the columns for 'subdomain' and 'sitename'. See http://drupal.org/node/244142
*/
function domain_update_6100() {
$ret = array();
db_drop_index($ret, 'domain', 'subdomain');
db_change_field($ret, 'domain', 'subdomain', 'subdomain', array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
));
db_add_index($ret, 'domain', 'subdomain', array(
'subdomain',
));
db_change_field($ret, 'domain', 'sitename', 'sitename', array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
));
return $ret;
}
/**
* Updates to 6.x.2.
*
* Deprecates the domain_editor grant.
* Adds the {domain_editor} table.
* Installs the new Domain Boostrap routine.
* Moves records from {user} (data) to {domain_editor}.
*/
function domain_update_6200() {
$ret = array();
// Remove the old editors information.
variable_del('domain_editors');
// Promopt the user to rebuild node access.
node_access_needs_rebuild(TRUE);
// Update the new bootstrap information.
domain_bootstrap_register();
// Try to register the default domain.
$root = variable_get('domain_root', rtrim($_SERVER['HTTP_HOST']));
db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $root, variable_get('domain_sitename', variable_get('site_name', 'Drupal')), variable_get('domain_scheme', 'http://'), 1);
// MySQL won't let us insert row 0 into an autoincrement table.
db_query("UPDATE {domain} SET domain_id = 0 WHERE subdomain = '%s'", $root);
// Install the {domain_editor} table.
$schema = domain_schema();
db_create_table($ret, 'domain_editor', $schema['domain_editor']);
// Move records from $user->data to {domain_editor}.
if (!db_table_exists('domain_editor')) {
return;
}
$result = db_query("SELECT uid, data FROM {users}");
while ($account = db_fetch_object($result)) {
$data = unserialize($account->data);
if (!empty($data['domain_user'])) {
foreach ($data['domain_user'] as $domain_id => $status) {
// A zero flag indicated not selected.
if ($status != 0) {
// Convert the -1 checkbox to a zero.
if ($domain_id == -1) {
$domain_id = 0;
}
db_query("INSERT INTO {domain_editor} (uid, domain_id) VALUES (%d, %d)", $account->uid, $domain_id);
}
}
}
}
return $ret;
}
/**
* Updates to 6.x.2.
*
* Deletes entries from {domain_editor} for domains that no longer exist.
*
* This update is needed by people who have been running 6.x.2rc versions.
*
*/
function domain_update_6201() {
$ret = array();
db_query("DELETE FROM {domain_editor} WHERE NOT EXISTS (SELECT domain_id FROM {domain} WHERE {domain}.domain_id={domain_editor}.domain_id)");
return $ret;
}
/**
* Updates to 6.x.2.
*
* Removes the authoring and menu settings for the node form.
*
*/
function domain_update_6202() {
$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;
}
/**
* Fixes permission naming error in rc9 and lower.
*/
function domain_update_6203() {
$ret = array();
$result = db_query("SELECT * FROM {permission}");
while ($permission = db_fetch_object($result)) {
if (strpos($permission->perm, 'publish to any assigned domains') > 0) {
$pid = (int) $permission->pid;
$string = db_escape_string(str_replace('publish to any assigned domains', 'publish to any assigned domain', $permission->perm));
$ret[] = update_sql("UPDATE {permission} SET perm = '{$string}' WHERE pid = {$pid}");
}
}
return $ret;
}
/**
* Adds the new 'access inactive domains' permission.
*/
function domain_update_6204() {
$ret = array();
$result = db_query("SELECT * FROM {permission}");
while ($permission = db_fetch_object($result)) {
if (strpos($permission->perm, 'administer domains') > 0) {
$pid = (int) $permission->pid;
$string = db_escape_string($permission->perm . ', access inactive domains');
if (module_exists('domain_nav')) {
$string .= ', access domain navigation';
}
$ret[] = update_sql("UPDATE {permission} SET perm = '{$string}' WHERE pid = {$pid}");
}
}
return $ret;
}
/**
* Remove dead user accounts from {domain_editor}.
*/
function domain_update_6205() {
$ret = array();
$ret[] = update_sql("DELETE FROM {domain_editor} WHERE uid NOT IN (SELECT u.uid FROM {users} u)");
return $ret;
}
/**
* Remove UPPERCASE from domain records.
*
* @link http://drupal.org/node/785818
*/
function domain_update_6206() {
$ret = array();
$result = db_query("SELECT domain_id, subdomain FROM {domain}");
while ($domain = db_fetch_array($result)) {
$string = drupal_strtolower($domain['subdomain']);
if ($string != $domain['subdomain']) {
db_query("UPDATE {domain} SET subdomain = '%s' WHERE domain_id = %d", $string, $domain['domain_id']);
if ($domain['domain_id'] == 0) {
variable_set('domain_root', $string);
}
}
}
return $ret;
}
Functions
Name | Description |
---|---|
domain_install | Implement hook_install() |
domain_schema | Implement hook_schema() |
domain_uninstall | Implement hook_uninstall() |
domain_update_6100 | Updates from 5.x.1.2 to 5.x.1.3. This change affected the size of the columns for 'subdomain' and 'sitename'. See http://drupal.org/node/244142 |
domain_update_6200 | Updates to 6.x.2. |
domain_update_6201 | Updates to 6.x.2. |
domain_update_6202 | Updates to 6.x.2. |
domain_update_6203 | Fixes permission naming error in rc9 and lower. |
domain_update_6204 | Adds the new 'access inactive domains' permission. |
domain_update_6205 | Remove dead user accounts from {domain_editor}. |
domain_update_6206 | Remove UPPERCASE from domain records. |