You are here

function hosting_add_task in Hosting 6.2

Same name and namespace in other branches
  1. 5 task/hosting_task.module \hosting_add_task()
  2. 7.4 task/hosting_task.module \hosting_add_task()
  3. 7.3 task/hosting_task.module \hosting_add_task()

Helper function to generate new task node

34 calls to hosting_add_task()
drush_hosting_post_pm_enable in ./hosting.drush.inc
Implements drush_hook_post_COMMAND().
drush_hosting_task_validate in ./task.hosting.inc
Validate hook for the hosting-task Drush command.
hook_hosting_TASK_TYPE_task_rollback in ./hosting.api.php
Perform actions when a task has failed and has been rolled back.
hosting_alias_update_6204 in alias/hosting_alias.install
Fixup redirection data after table change in hosting_alias_update_6203()
hosting_features_form_submit in ./hosting.features.inc
Submit callback for the Hosting features form.

... See full list

File

task/hosting_task.module, line 364
Web server node type is defined here.

Code

function hosting_add_task($nid, $type, $args = null, $status = HOSTING_TASK_QUEUED) {
  global $user;
  $task = hosting_get_most_recent_task($nid, $type);

  // Guard against destructive tasks run on the hostmaster site
  $hostmaster_nid = hosting_get_hostmaster_nid();
  if ($nid == $hostmaster_nid && in_array($type, array(
    'delete',
    'disable',
  ))) {
    drupal_set_message(t('You cannot !task the Hostmaster site.', array(
      '!task' => $type,
    )), 'warning');
    watchdog('hostmaster', t('Attempt to !task the Hostmaster site blocked.', array(
      '!task' => $type,
    )), array(), WATCHDOG_WARNING);
    return FALSE;
  }
  $node = db_fetch_object(db_query("SELECT nid, uid, title FROM {node} WHERE nid=%d", $nid));
  if (!$task) {
    $task = new stdClass();
  }
  $task->type = 'task';

  # TODO: make this pretty
  $task->title = t("!type !title", array(
    '!type' => $type,
    '!title' => $node->title,
  ));
  $task->task_type = $type;
  $task->rid = $node->nid;

  /*
   * fallback the owner of the task to the owner of the node we operate
   * upon
   *
   * this is mostly for the signup form, which runs as the anonymous
   * user, but for which the node is set to the right user
   */
  $task->uid = $user->uid ? $user->uid : $node->uid;
  $task->status = 1;
  $task->task_status = $status;
  if ($status == HOSTING_TASK_QUEUED) {
    $task->revision = TRUE;
  }

  #arguments, such as which backup to restore.
  if (is_array($args)) {
    $task->task_args = $args;
  }
  node_save($task);
  drupal_set_message(t("Task %type was added to the queue. Next queue run is %date, server time is %time.", array(
    '%type' => $type,
    '%date' => format_date(_hosting_queue_next_run('tasks'), 'custom', 'H:i:sO'),
    '%time' => format_date(time(), 'custom', 'H:i:sO'),
  )));
  return $task;
}