You are here

function drush_hosting_task in Hosting 6.2

Same name and namespace in other branches
  1. 7.4 task.hosting.inc \drush_hosting_task()
  2. 7.3 task.hosting.inc \drush_hosting_task()

Drush hosting task command.

This is the main way that the frontend communicates with the backend. Tasks correspond to backend drush commands, and the results and log of the command are attached to the task for reference.

See also

drush_hosting_task_validate()

hook_hosting_TASK_OBJECT_context_options()

File

./task.hosting.inc, line 99
Drush include for the Hosting module's hosting task command.

Code

function drush_hosting_task() {
  $task =& drush_get_context('HOSTING_TASK');
  $output = array();
  $mode = 'POST';

  // Make sure argument order is correct
  ksort($task->args);

  // If this task type needs it, run provision-save to create the named context.
  if (!empty($task->task_info['provision_save'])) {

    // Invoke hook_hosting_TASK_OBJECT_context_options()
    // We copy module_invoke_all() here because it doesn't pass by
    // reference and it breaks under PHP 5.3
    $hook = 'hosting_' . $task->ref->type . '_context_options';
    foreach (module_implements($hook) as $module) {
      $function = $module . '_' . $hook;
      call_user_func($function, $task);
    }
    $output = drush_invoke_process('@none', 'provision-save', array(
      '@' . $task->ref->hosting_name,
    ), $task->context_options, array(
      'method' => $mode,
    ));
  }

  // Run the actual command. Adding alias here to work around Drush API.
  $output = provision_backend_invoke($task->ref->hosting_name, 'provision-' . $task->task_type, $task->args, $task->options, $mode);
  drush_set_context('HOSTING_DRUSH_OUTPUT', $output);

  // On succesful delete, remove the named context.
  if ($task->task_type === 'delete' && !drush_get_error()) {
    $output = drush_invoke_process('@none', 'provision-save', array(
      '@' . $task->ref->hosting_name,
    ), array(
      'delete' => TRUE,
    ), array(
      'method' => $mode,
    ));
  }

  // New revision is created at the beginning of function.
  $task->revision = FALSE;
  $task->delta = time() - $task->executed;
  node_save($task);
}