function hosting_db_server_update_6000 in Hostmaster (Aegir) 6
Get rid of db_server node type and associate ourselves with server nodes instead.
File
- modules/
hosting/ db_server/ hosting_db_server.install, line 53 - Install, update and uninstall for the database server module.
Code
function hosting_db_server_update_6000() {
drupal_install_modules(array(
'hosting_server',
));
$ret = array();
$result = db_query("SELECT nid, vid, title FROM {node} WHERE type='db_server'");
while ($record = db_fetch_object($result)) {
if ($record->title == 'localhost') {
$db_server = db_fetch_object(db_query("SELECT * FROM {hosting_db_server} WHERE nid=%d", $record->nid));
// Remove old data to remove collision opportunities.
db_query("DELETE FROM {hosting_db_server} WHERE nid=%d", $record->nid);
// get all the web servers to add the localhost db service to.
$web_result = db_query("SELECT n.nid, n.vid FROM {node} n WHERE (n.type='web_server')");
while ($web_server = db_fetch_object($web_result)) {
db_query("INSERT INTO {hosting_service} (nid, vid, service, type, available) VALUES (%d, %d, 'db', 'mysql', 1)", $web_server->nid, $web_server->vid);
db_query("INSERT INTO {hosting_db_server} (nid, vid, db_user, db_passwd) VALUES (%d, %d, '%s', '%s')", $web_server->nid, $web_server->vid, $db_server->db_user, $db_server->db_passwd);
db_query("UPDATE {hosting_site} SET db_server = %d WHERE db_server=%d", $web_server->nid, $record->nid);
}
}
else {
// couldn't find a relative web server, so we will need to lose this db server.
db_query("DELETE FROM {hosting_db_server} WHERE nid=%d", $record->nid);
}
db_query("DELETE FROM {node_revisions} WHERE nid=%d", $record->nid);
}
db_query("DELETE FROM {node} WHERE type='db_server'");
return $ret;
}