function hosting_update_6008 in Hosting 7.4
Same name and namespace in other branches
- 6.2 hosting.install \hosting_update_6008()
- 7.3 hosting.install \hosting_update_6008()
Implements hook_update_N().
Add hosting_context table to map alias names.
File
- ./
hosting.install, line 237 - Define database schemas and update functions for the hosting module.
Code
function hosting_update_6008() {
$return = array();
if (!variable_get('hosting_update_6008_run', FALSE)) {
db_create_table($return, 'hosting_context', array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
),
),
'primary key' => array(
'nid',
),
'unique keys' => array(
'name' => array(
'name',
),
),
));
variable_set('hosting_update_6008_run', TRUE);
$records = array();
$result = db_query("SELECT n.nid, title FROM {node} n LEFT JOIN {hosting_site} s ON n.nid=s.nid WHERE s.status <> -2 AND n.type='site'");
while ($object = db_fetch_object($result)) {
$records[$object->nid] = $object->title;
}
$result = db_query("SELECT n.nid, title FROM {node} n LEFT JOIN {hosting_server} s ON n.nid=s.nid WHERE n.status = 1 AND n.type='server'");
while ($object = db_fetch_object($result)) {
$records[$object->nid] = 'server_' . preg_replace("/[!\\W\\.\\-]/", "", $object->title);
}
// We start with the web server because we assume that the main hostmaster site is installed locally.
$server_id = variable_get('hosting_default_web_server', 3);
$records[$server_id] = 'server_master';
foreach ($records as $nid => $name) {
hosting_context_register($nid, $name);
}
}
return $return;
}