You are here

hosting_task.install in Hosting 5

File

task/hosting_task.install
View source
<?php

function hosting_task_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {hosting_task} (\n      vid int(10) unsigned NOT NULL default '0',\n      nid int(10) unsigned NOT NULL default '0',\n      task_type longtext,\n      rid int(11) NOT NULL default '0',\n      task_status int(11) default NULL,\n      executed int(11) default NULL,\n    PRIMARY KEY  (vid)\n    ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {hosting_task_arguments} (\n      vid int(10) unsigned NOT NULL default '0',\n      nid int(10) unsigned NOT NULL default '0',\n      name longtext,\n      value longtext\n    ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      # Logging table for backend task calls
      db_query("CREATE TABLE {hosting_task_log} (\n      lid int NOT NULL auto_increment,\n      vid int NOT NULL default '0',\n      type varchar(16) NOT NULL default '',\n      message longtext NOT NULL,\n      error longtext NOT NULL default '',\n      timestamp int NOT NULL default '0',\n      PRIMARY KEY (lid),\n      KEY (type)\n    ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      # Task queue
      db_query("CREATE TABLE {hosting_task_queue} (\n      nid int NOT NULL default '0',\n      timestamp int NOT NULL default '0',\n      status tinyint unsigned NOT NULL default 0,\n      PRIMARY KEY (nid)\n    ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
  }
}

/**
 * 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;
}

Functions

Namesort descending Description
hosting_task_install
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