You are here

function hosting_add_task in Hosting 7.3

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

Helper function to generate new task node

37 calls to hosting_add_task()
drush_hosting_subdirs_post_hosting_task in subdirs/hosting_subdirs.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_feature_rebuild_caches in ./hosting.features.inc
Perform necessary task after enabling or disabling Hosting features.

... See full list

File

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

Code

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

  // Guard against destructive tasks run on guarded nodes.
  if (!hosting_task_dangerous_task_is_allowed($type, $nid)) {
    return FALSE;
  }
  $node = db_query("SELECT nid, uid, title FROM {node} WHERE nid = :nid", array(
    ':nid' => $nid,
  ))
    ->fetchObject();
  $task = new stdClass();
  $task->language = LANGUAGE_NONE;
  $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);
  return $task;
}