View source
<?php
function hosting_task_schema() {
$schema['hosting_task'] = 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,
),
'task_type' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'rid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'task_status' => array(
'type' => 'int',
'not null' => FALSE,
),
'executed' => array(
'type' => 'int',
'not null' => FALSE,
),
'delta' => array(
'type' => 'int',
'not null' => FALSE,
),
),
'primary key' => array(
'vid',
),
);
$schema['hosting_task_arguments'] = 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,
),
'name' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
),
);
$schema['hosting_task_log'] = array(
'fields' => array(
'lid' => array(
'type' => 'serial',
'not null' => TRUE,
),
'vid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => '',
),
'message' => array(
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
'error' => array(
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'type' => array(
'type',
),
'vid_lid' => array(
'vid',
'lid',
),
'nid' => array(
'nid',
),
),
'primary key' => array(
'lid',
),
);
return $schema;
}
function hosting_task_install() {
drupal_install_schema('hosting_task');
}
function hosting_task_update_1() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {hosting_task_log} \n ADD COLUMN error longtext NOT NULL default ''");
$ret[] = update_sql("ALTER TABLE {hosting_task_log} \n DROP COLUMN severity");
return $ret;
}
function hosting_task_update_2() {
$ret = array();
variable_set('hosting_dispatch_enabled', FALSE);
db_query("UPDATE {hosting_task_queue} SET status = 100 WHERE status = 0");
db_query("UPDATE {hosting_task_queue} SET status = 0 WHERE status <> 100");
db_query("UPDATE {hosting_task_queue} SET status = 1 WHERE status = 100");
variable_set('hosting_dispatch_enabled', TRUE);
return $ret;
}
function hosting_task_update_6000() {
$ret = hosting_package_update_6002();
if (!variable_get('hosting_task_update_6000_run', FALSE)) {
db_add_field($ret, 'hosting_task', 'delta', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
variable_set('hosting_task_update_6000_run', TRUE);
}
return $ret;
}
function hosting_task_update_6001() {
$ret = array();
db_drop_table($ret, 'hosting_task_queue');
return $ret;
}
function hosting_task_update_6002() {
$ret = array();
$result = db_query("select t.task_type, t.rid, max(t.nid) as max_nid from {hosting_task} t group by t.task_type, t.rid");
while ($obj = db_fetch_object($result)) {
db_query("UPDATE {hosting_task} SET nid = %d WHERE task_type='%s' AND rid=%d", $obj->max_nid, $obj->task_type, $obj->rid);
}
db_query("update {hosting_task_arguments} a, {hosting_task} t set a.nid=t.nid where a.vid=t.vid");
db_query("update {node_revisions} r, {hosting_task} t set r.nid=t.nid where r.vid=t.vid");
$result = db_query("select n.nid, count(t.vid) as vid_count from {node} n left join {hosting_task} t on n.nid = t.nid where n.type = 'task' group by n.nid having vid_count = 0");
while ($obj = db_fetch_object($result)) {
db_query("DELETE FROM {node} WHERE nid=%d", $obj->nid);
}
return $ret;
}
function hosting_task_update_6003() {
$ret = array();
db_query("UPDATE {hosting_task} SET task_status = -1 WHERE task_status = 4");
return $ret;
}
function hosting_task_update_6004() {
$ret = array();
install_include(array(
'user',
));
install_add_permissions(install_get_rid('aegir client'), array(
'cancel own tasks',
));
node_access_rebuild();
return $ret;
}
function hosting_task_update_6005() {
$ret = array();
db_change_field($ret, 'hosting_task_log', 'error', 'error', array(
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
));
return $ret;
}
function hosting_task_update_6006() {
$ret = array();
$field = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
$indexes = array(
'indexes' => array(
'vid_lid' => array(
'vid',
'lid',
),
'nid' => array(
'nid',
),
),
);
db_add_field($ret, 'hosting_task_log', 'nid', $field, $indexes);
$query = "SELECT nid, vid FROM {hosting_task}";
$result = db_query($query);
while ($task = db_fetch_object($result)) {
$query = "UPDATE {hosting_task_log} SET nid = %d WHERE vid = %d";
db_query($query, $task->nid, $task->vid);
}
$query = "DELETE FROM {hosting_task_log} WHERE nid = %d";
db_query($query, 0);
return $ret;
}
function hosting_task_update_6200() {
$ret = array();
module_enable(array(
'install_profile_api',
));
module_load_include('inc', 'install_profile_api', 'core/user');
install_add_permissions(install_get_rid('aegir administrator'), array(
'update status of tasks',
));
module_disable(array(
'install_profile_api',
));
return $ret;
}