Commit 57845c74 authored by Jon Pugh's avatar Jon Pugh Committed by Steven Jones
parent 522c2947
......@@ -137,8 +137,12 @@ function hook_hosting_queues() {
/**
* Add or change context options before a hosting task runs.
*
* This hook is invoked just before an 'install', 'verify' or 'import' task, and
* the TASK_OBJECT will be either: 'server', 'platform' or 'site'.
* This hook is invoked just before any task that has the 'provision_save' flag
* equal to TRUE. These include the 'install', 'verify' and 'import' tasks.
*
* The TASK_OBJECT will be either: 'server', 'platform' or 'site'.
*
* @see hook_hosting_tasks()
*
* This gives other modules the chance to send data to the backend to be
* persisted by services there. The entire task is sent so that you have access
......
......@@ -81,6 +81,7 @@ function hosting_platform_hosting_tasks() {
'title' => t('Verify'),
'description' => t('Verify that the platform is correctly installed and working.'),
'weight' => 10,
'provision_save' => TRUE,
);
$tasks['platform']['delete'] = array(
'title' => t('Delete'),
......
......@@ -70,6 +70,7 @@ function hosting_server_hosting_tasks() {
'title' => t('Verify'),
'description' => t('Verify that the server is correctly installed and working.'),
'weight' => 10,
'provision_save' => TRUE,
);
/**
......
......@@ -224,6 +224,7 @@ function hosting_site_hosting_tasks() {
$tasks['site']['verify'] = array(
'title' => t('Verify'),
'description' => t('Confirm that the site has been correctly installed and regenerate all configuration files to match the hosting front end.'),
'provision_save' => TRUE,
);
$tasks['site']['disable'] = array(
......@@ -259,14 +260,16 @@ function hosting_site_hosting_tasks() {
$tasks['site']['install'] = array(
'title' => t('Install'),
'description' => t('Install a site'),
'hidden' => TRUE
'hidden' => TRUE,
'provision_save' => TRUE,
);
$tasks['site']['import'] = array(
'title' => t('Import'),
'description' => t('Import an existing site into Aegir'),
'hidden' => TRUE
);
'hidden' => TRUE,
'provision_save' => TRUE,
);
return $tasks;
}
......
......@@ -75,6 +75,14 @@ function drush_hosting_task_validate($id, $type = null) {
else {
drush_set_error('HOSTING_INVALID_TASK', t("This task is not valid"));
}
// 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];
}
}
/**
......@@ -85,6 +93,7 @@ function drush_hosting_task_validate($id, $type = null) {
* are attached to the task for reference.
*
* @see drush_hosting_task_validate()
* @see hook_hosting_TASK_OBJECT_context_options()
*/
function drush_hosting_task() {
$task =& drush_get_context('HOSTING_TASK');
......@@ -94,9 +103,10 @@ function drush_hosting_task() {
// Make sure argument order is correct
ksort($task->args);
// On install/verify, save the named context
if ($task->task_type === 'install' || $task->task_type === 'verify' || $task->task_type === 'import') {
// XXX: we copy module_invoke_all() here because it doesn't pass by
// 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) {
......@@ -106,10 +116,12 @@ function drush_hosting_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 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;
......
......@@ -28,6 +28,13 @@
* task will still be available for execution by the front-end however.
* - 'access callback' (optional) An access callback to determine if the user
* can access the task, defaults to 'hosting_task_menu_access'.
* - 'provision_save' (optional, defaults to FALSE) A mostly internal flag
* that tells provision that a "provision-save" call needs to happen before
* this task can be run, for tasks like Verify, Install, and Migrate.
* If you implement this option, you should implement
* hook_hosting_TASK_OBJECT_context_options() in order to pass parameters to
* the provision-save command. See hosting_hosting_site_context_options() for
* an example of how a site context is saved
*
* @see hosting_available_tasks()
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment