You are here

function hosting_task_cancel in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 task/hosting_task.module \hosting_task_cancel()
  2. 7.3 task/hosting_task.module \hosting_task_cancel()

Cancel a task before it's started.

1 string reference to 'hosting_task_cancel'
hosting_task_menu in task/hosting_task.module
Implements hook_menu().

File

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

Code

function hosting_task_cancel($node) {
  if ($node->type == 'task') {
    if ($node->task_status == HOSTING_TASK_QUEUED || $node->task_status == HOSTING_TASK_PROCESSING) {
      $node->task_status = HOSTING_TASK_WARNING;
      node_save($node);
      if (module_exists('hosting_queued')) {

        // Release the hosting_queued lock.
        // Cannot use lock release because it uses semaphore value, which only works in a single request.
        global $locks;
        unset($locks['hosting_queue_tasks_running']);
        db_delete('semaphore')
          ->condition('name', 'hosting_queue_tasks_running')
          ->execute();
      }

      // Log the cancellation.
      hosting_task_log($node->vid, 'warning', t("Task was cancelled."));
      drupal_goto('node/' . $node->rid);
    }
    else {
      drupal_set_message(t('This task is not running or queued. It cannot be cancelled.'), 'warning');
      drupal_goto('node/' . $node->nid);
    }
  }
}