function drush_hosting_task_validate in Hosting 6.2
Same name and namespace in other branches
- 7.4 task.hosting.inc \drush_hosting_task_validate()
- 7.3 task.hosting.inc \drush_hosting_task_validate()
Validate hook for the hosting-task Drush command.
We do some magic in this command to allow the user to run either a specifc task by specifying a node id or chosen task type by specifying the type of task, e.g. 'verify' or 'migrate'.
See also
File
- ./
task.hosting.inc, line 33 - Drush include for the Hosting module's hosting task command.
Code
function drush_hosting_task_validate($id, $type = null) {
drush_set_option('user', 1);
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN);
if (is_numeric($id)) {
$task = node_load($id);
}
elseif (is_string($id) && isset($type)) {
$ref = hosting_context_load($id);
if ($ref->nid) {
if (!($task = hosting_get_most_recent_task($ref->nid, $type))) {
$task = hosting_add_task($ref->nid, $type);
}
}
}
if ($task->type == 'task') {
$task->ref = node_load($task->rid);
$task->options = array();
$task->context_options = array(
'context_type' => $task->ref->type,
'master_url' => url('', array(
'absolute' => TRUE,
)),
'root' => null,
'uri' => null,
);
$task->args = array();
$task->changed = time();
$task->executed = time();
/* if not already running, remove the task from the queue
* this is to avoid concurrent task runs */
if ($task->task_status == HOSTING_TASK_PROCESSING && !drush_get_option('force', false)) {
return drush_set_error('HOSTING_TASK_RUNNING', dt("This task is already running, use --force"));
}
if ($task->task_status != HOSTING_TASK_QUEUED && !drush_get_option('force', false)) {
return drush_set_error('HOSTING_TASK_NOT_QUEUED', dt("This task is not queued, use --force"));
}
$task->task_status = HOSTING_TASK_PROCESSING;
$task->revision = TRUE;
node_save($task);
drush_set_context('HOSTING_TASK', $task);
drush_set_context('DRUSH_LOG_CALLBACK', '_hosting_task_log');
drush_log(dt("Task starts processing"), 'queue');
// Load Task Info
$tasks_info = hosting_available_tasks($task->ref->type);
// Find task type and pass through if it needs provision_save
if (isset($tasks_info[$task->task_type])) {
$task->task_info = $tasks_info[$task->task_type];
}
}
else {
drush_set_error('HOSTING_INVALID_TASK', t("This task is not valid"));
}
}