You are here

hosting_task.install in Hosting 6.2

File

task/hosting_task.install
View source
<?php

/**
 * Implementation of hook_schema().
 */
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() {

  // Create tables.
  drupal_install_schema('hosting_task');
}

/**
 * Add the error column to hosting_task_log, so we can extract the
 * specific error codes, not just the messages.
 */
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;
}

/**
 * Reset the task_status of all currently (according to us) in queue tasks
 *
 * This will force them to be re-evaluated if the queue status doesn't match the task status
 */
function hosting_task_update_2() {
  $ret = array();
  variable_set('hosting_dispatch_enabled', FALSE);

  // Put the queued items separately for a bit.
  db_query("UPDATE {hosting_task_queue} SET status = 100 WHERE status = 0");

  // Remove all the other items from the queue.
  db_query("UPDATE {hosting_task_queue} SET status = 0 WHERE status <> 100");

  // Add all the queued items back into the queue.
  db_query("UPDATE {hosting_task_queue} SET status = 1 WHERE status = 100");
  variable_set('hosting_dispatch_enabled', TRUE);
  return $ret;
}

/**
 * Add a delta column to tasks so that we have a measure of duration of tasks
 */
function hosting_task_update_6000() {
  $ret = hosting_package_update_6002();

  // this update needs to be run before tasks can be added, in other update functions.
  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;
}

/**
 * remove the redundant hosting_queue table
 */
function hosting_task_update_6001() {
  $ret = array();
  db_drop_table($ret, 'hosting_task_queue');
  return $ret;
}

/**
 * Remove all the duplicate task nodes for previous task type / rid combinations
 *
 * This makes it more efficient to query and generate the data, and makes sure we don't
 * lose any history.
 */
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;
}

/**
 * Processing state constant changed to ensure proper sorting
 */
function hosting_task_update_6003() {
  $ret = array();
  db_query("UPDATE {hosting_task} SET task_status = -1 WHERE task_status = 4");
  return $ret;
}

/**
 * Add 'cancel own task' permission to 'aegir client' role
 */
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;
}

/**
 * Remove DEFAULT value on a LONGTEXT fields.
 * 
 * This was breaking in MariaDB and preventing installation. On MySQL
 * it was silently ignored, so the installation works, but the
 * defaults are not in the table anyway.
 *
 * See #969326
 */
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;
}

/**
 * Add nid field to hosting_task_log and remove orphaned log entries.
 */
function hosting_task_update_6006() {
  $ret = array();

  // Add nid field.
  $field = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );

  // Add some useful indexes.
  $indexes = array(
    'indexes' => array(
      'vid_lid' => array(
        'vid',
        'lid',
      ),
      'nid' => array(
        'nid',
      ),
    ),
  );
  db_add_field($ret, 'hosting_task_log', 'nid', $field, $indexes);

  // Populate nid field.
  $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);
  }

  // Remove orphaned logs, which will have nid == 0 now.
  $query = "DELETE FROM {hosting_task_log} WHERE nid = %d";
  db_query($query, 0);
  return $ret;
}

/**
 * Add permission.
 */
function hosting_task_update_6200() {
  $ret = array();

  // Temporarily enable Install Profile API module and load includes.
  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;
}

Functions

Namesort descending Description
hosting_task_install
hosting_task_schema Implementation of hook_schema().
hosting_task_update_1 Add the error column to hosting_task_log, so we can extract the specific error codes, not just the messages.
hosting_task_update_2 Reset the task_status of all currently (according to us) in queue tasks
hosting_task_update_6000 Add a delta column to tasks so that we have a measure of duration of tasks
hosting_task_update_6001 remove the redundant hosting_queue table
hosting_task_update_6002 Remove all the duplicate task nodes for previous task type / rid combinations
hosting_task_update_6003 Processing state constant changed to ensure proper sorting
hosting_task_update_6004 Add 'cancel own task' permission to 'aegir client' role
hosting_task_update_6005 Remove DEFAULT value on a LONGTEXT fields.
hosting_task_update_6006 Add nid field to hosting_task_log and remove orphaned log entries.
hosting_task_update_6200 Add permission.