hosting_server.install in Hosting 7.3
Same filename and directory in other branches
Define the database schema and update functions for the hosting_server module.
File
server/hosting_server.installView source
<?php
/**
* @file
* Define the database schema and update functions for the hosting_server module.
*
*/
/**
* Implements hook_schema().
*/
function hosting_server_schema() {
$schema['hosting_server'] = array(
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'human_name' => array(
'type' => 'text',
'size' => 'small',
'not null' => FALSE,
),
'verified' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'vid',
),
);
$schema['hosting_ip_addresses'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'ip_address' => array(
'type' => 'text',
'size' => 'small',
'not null' => TRUE,
),
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
'indexes' => array(
'nid' => array(
'nid',
),
),
);
$schema['hosting_service'] = array(
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'service' => array(
'type' => 'text',
'size' => 'small',
'not null' => TRUE,
),
'type' => array(
'type' => 'text',
'size' => 'small',
'not null' => TRUE,
),
'restart_cmd' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'port' => array(
'type' => 'int',
'default' => 0,
'unsigned' => TRUE,
'not null' => FALSE,
),
'available' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 1,
),
),
'indexes' => array(
'vid' => array(
'vid',
),
),
);
return $schema;
}
/**
* Implements hook_update_N().
*/
function hosting_server_update_6000() {
$return = array();
db_add_index($return, 'hosting_service', 'vid', array(
'vid',
));
return $return;
}
/**
* Implements hook_update_N().
*
* Drop the drush_path and backup_path columns which are no longer needed.
*/
function hosting_server_update_6001() {
$ret = array();
db_drop_field($ret, "hosting_server", "drush_path");
db_drop_field($ret, "hosting_server", "backup_path");
return $ret;
}
/**
* Implements hook_update_N().
*
* Drop the script_user and config_path columns which are no longer needed.
* Also remove hosting_service entries which are no longer relevant.
*/
function hosting_server_update_6002() {
$ret = array();
db_query("DELETE FROM {hosting_service} WHERE service='server'");
db_drop_field($ret, "hosting_server", "script_user");
db_drop_field($ret, "hosting_server", "config_path");
return $ret;
}
/**
* Implements hook_update_N().
*
* Bring the port and restart command from hosting_web_server into hosting_service.
*/
function hosting_server_update_6003() {
db_add_field($ret, 'hosting_service', 'port', array(
'type' => 'int',
'default' => 0,
'unsigned' => TRUE,
'not null' => FALSE,
));
db_add_field($ret, 'hosting_service', 'restart_cmd', array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
));
return $ret;
}
/**
* Implements hook_update_N().
*
* Add the IP address table.
*/
function hosting_server_update_6004() {
$return = array();
// create the table so we can rename it.
// retarded, i know.
$schema = array(
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'ip_address' => array(
'type' => 'text',
'size' => 'small',
'not null' => TRUE,
),
),
'indexes' => array(
'vid' => array(
'vid',
),
),
);
db_create_table($return, 'hosting_server_ip', $schema);
return $return;
}
/**
* Implements hook_update_N().
*
* Rename the IP address table so that sites can also use it.
*/
function hosting_server_update_6005() {
$ret = array();
db_rename_table($ret, 'hosting_server_ip', 'hosting_ip_addresses');
return $ret;
}
/**
* Implements hook_update_N().
*
* Add primary key for IPs, drop versionning
*/
function hosting_server_update_6200() {
$ret = array();
db_drop_index($ret, 'hosting_ip_addresses', 'vid');
db_drop_field($ret, "hosting_ip_addresses", "vid");
db_add_field($ret, "hosting_ip_addresses", "id", array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
'id',
),
));
$r = db_query("SELECT nid, ip_address FROM {hosting_ip_addresses}");
for ($i = 0; $row = db_fetch_object($r); $i++) {
$ret[] = update_sql("UPDATE {hosting_ip_addresses} SET id={$i} WHERE nid={$row->nid} AND ip_address='{$row->ip_address}'");
}
db_add_index($ret, 'hosting_ip_addresses', 'nid', array(
'nid',
));
return $ret;
}
/**
* Implements hook_update_N().
*
* Create SSL cert to IP mapping table.
*
* We create the SSL cert to IP mapping table here instead of in the ssl
* module as we need to cleanup the ip_address table after and we can't sync
* across modules. Since this module is a dependency of hosting_site_ssl, this
* is not a problem.
*
* If SSL is not installed, this is a noop.
*/
function hosting_server_update_6201() {
if (!db_table_exists('hosting_ssl_site')) {
return array(
array(
'success' => TRUE,
),
);
}
$ret = array();
$schema = array(
'fields' => array(
// cert id
'cid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
// reference to the hosting_ip_addresses table
'ip_address' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'cid' => array(
'cid',
),
'ip_address' => array(
'ip_address',
),
),
);
db_create_table($ret, 'hosting_ssl_cert_ips', $schema);
return $ret;
}
/**
* Implements hook_update_N().
*
* Migrate site-specific IPs to server-specific IPs.
*
* We inject into the new certificate to IP mapping table the correct
* associations, by looking at the server IPs matching the IPs allocated to
* sites.
*
* If SSL is not installed, this is a noop.
*/
function hosting_server_update_6202() {
if (!db_table_exists('hosting_ssl_site')) {
return array(
array(
'success' => TRUE,
),
);
}
$ret = array();
/* this is rather complicated:
*
* we need to first find the SSL certificate of the site, then look at the
* IP of the sites with SSL certs, match that IP with the IP of a server (we
* assume it's the same server!).
*
* Verification query:
*
* SELECT cert.cid,cert.ssl_key,server_ip.ip_address,server_ip.nid,server_ip.id FROM hosting_ssl_site ssl_site
* INNER JOIN hosting_ssl_cert cert ON cert.cid = ssl_site.ssl_key
* INNER JOIN hosting_ip_addresses site_ip ON site_ip.nid = ssl_site.nid
* INNER JOIN hosting_site site ON site.nid = ssl_site.nid
* INNER JOIN hosting_ip_addresses server_ip ON server_ip.ip_address = site_ip.ip_address
* INNER JOIN hosting_platform p ON site.platform = p.nid AND p.web_server = server_ip.nid
* WHERE ssl_enabled > 0 AND site.status > -2 GROUP BY cid ;
*
* This should show a meaningful list of SSL certificates -> IPs mappings.
*
*/
$ret[] = update_sql("INSERT INTO {hosting_ssl_cert_ips} (cid, ip_address)\n SELECT cert.cid,server_ip.id FROM {hosting_ssl_site} ssl_site\n INNER JOIN {hosting_ssl_cert} cert ON cert.cid = ssl_site.ssl_key\n INNER JOIN {hosting_ip_addresses} site_ip ON site_ip.nid = ssl_site.nid\n INNER JOIN {hosting_site} site ON site.nid = ssl_site.nid\n INNER JOIN {hosting_ip_addresses} server_ip ON server_ip.ip_address = site_ip.ip_address\n INNER JOIN {hosting_platform} p ON site.platform = p.nid AND p.web_server = server_ip.nid\n WHERE ssl_enabled > %d AND site.status > %d GROUP BY cid", HOSTING_SSL_DISABLED, HOSTING_SITE_DELETED);
return $ret;
}
/**
* Implements hook_update_N().
*
* Cleanup site-specific IP mappings.
*
* Those are now associated only to servers again, and different modules
* should manage their own mappings.
*
* @todo enable this in 3.x? or maybe after the RC cycle of 2.x? we keep the
* data right now because the above request is quite error-prone and we are
* not sure we cover all cases.
*/
/* function hosting_server_update_6203() { */
/* $ret = array(); */
/* $ret[] = update_sql("DELETE {hosting_ip_addresses} FROM {hosting_ip_addresses} JOIN {node} ON hosting_ip_addresses.nid = node.nid WHERE node.type <> 'server';"); */
/* return $ret; */
/* } */
/**
* Add 'name' field to hosting_server.
*/
function hosting_server_update_7300() {
db_add_field('hosting_server', 'human_name', array(
'type' => 'text',
'size' => 'small',
'not null' => FALSE,
));
}
/**
* Add 'verified' and 'status' fields to hosting_server.
*/
function hosting_server_update_7301() {
db_add_field('hosting_server', 'verified', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
db_add_field('hosting_server', 'status', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Convert all roles with the 'administer server' permission to 'administer servers'.
*/
function hosting_server_update_7302() {
db_update('role_permission')
->fields(array(
'permission' => 'administer servers',
))
->condition('permission', 'administer server')
->execute();
}
Functions
Name | Description |
---|---|
hosting_server_schema | Implements hook_schema(). |
hosting_server_update_6000 | Implements hook_update_N(). |
hosting_server_update_6001 | Implements hook_update_N(). |
hosting_server_update_6002 | Implements hook_update_N(). |
hosting_server_update_6003 | Implements hook_update_N(). |
hosting_server_update_6004 | Implements hook_update_N(). |
hosting_server_update_6005 | Implements hook_update_N(). |
hosting_server_update_6200 | Implements hook_update_N(). |
hosting_server_update_6201 | Implements hook_update_N(). |
hosting_server_update_6202 | Implements hook_update_N(). |
hosting_server_update_7300 | Add 'name' field to hosting_server. |
hosting_server_update_7301 | Add 'verified' and 'status' fields to hosting_server. |
hosting_server_update_7302 | Convert all roles with the 'administer server' permission to 'administer servers'. |