You are here

function drush_hosting_task in Hostmaster (Aegir) 6

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

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

Code

function drush_hosting_task() {
  $task =& drush_get_context('HOSTING_TASK');
  $output = array();
  $mode = drush_get_option('debug', FALSE) ? 'GET' : '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_backend_invoke_args('provision-save', array(
      '@' . $task->ref->hosting_name,
    ), $task->context_options, $mode);
  }

  // Run the actual command. Adding alias here to work aorund 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);
  $code = drush_get_error();

  // We return 0 on success, so anything else is an error.
  $task->task_status = $code ? HOSTING_TASK_ERROR : HOSTING_TASK_SUCCESS;

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

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