Commit f69f40d2 authored by Steven Jones's avatar Steven Jones

Issue #1760962 by Jon Pugh: Added Allow any hosting task to flag itself for...

Issue #1760962 by Jon Pugh: Added Allow any hosting task to flag itself for needing a provision-save.
parents 522c2947 345b122b
...@@ -137,8 +137,10 @@ function hook_hosting_queues() { ...@@ -137,8 +137,10 @@ function hook_hosting_queues() {
/** /**
* Add or change context options before a hosting task runs. * Add or change context options before a hosting task runs.
* *
* This hook is invoked just before an 'install', 'verify' or 'import' task, and * This hook is invoked just before any task that has the 'provision_save' flag
* the TASK_OBJECT will be either: 'server', 'platform' or 'site'. * equal to TRUE. These include the 'install', 'verify' and 'import' tasks.
*
* The TASK_OBJECT will be either: 'server', 'platform' or 'site'.
* *
* This gives other modules the chance to send data to the backend to be * 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 * persisted by services there. The entire task is sent so that you have access
...@@ -162,6 +164,7 @@ function hook_hosting_queues() { ...@@ -162,6 +164,7 @@ function hook_hosting_queues() {
* *
* @see drush_hosting_task() * @see drush_hosting_task()
* @see hook_drush_context_import() * @see hook_drush_context_import()
* @see hook_hosting_tasks()
*/ */
function hook_hosting_TASK_OBJECT_context_options(&$task) { function hook_hosting_TASK_OBJECT_context_options(&$task) {
// From hosting_hosting_platform_context_options(). // From hosting_hosting_platform_context_options().
......
...@@ -81,6 +81,7 @@ function hosting_platform_hosting_tasks() { ...@@ -81,6 +81,7 @@ function hosting_platform_hosting_tasks() {
'title' => t('Verify'), 'title' => t('Verify'),
'description' => t('Verify that the platform is correctly installed and working.'), 'description' => t('Verify that the platform is correctly installed and working.'),
'weight' => 10, 'weight' => 10,
'provision_save' => TRUE,
); );
$tasks['platform']['delete'] = array( $tasks['platform']['delete'] = array(
'title' => t('Delete'), 'title' => t('Delete'),
......
...@@ -70,6 +70,7 @@ function hosting_server_hosting_tasks() { ...@@ -70,6 +70,7 @@ function hosting_server_hosting_tasks() {
'title' => t('Verify'), 'title' => t('Verify'),
'description' => t('Verify that the server is correctly installed and working.'), 'description' => t('Verify that the server is correctly installed and working.'),
'weight' => 10, 'weight' => 10,
'provision_save' => TRUE,
); );
/** /**
......
...@@ -224,6 +224,7 @@ function hosting_site_hosting_tasks() { ...@@ -224,6 +224,7 @@ function hosting_site_hosting_tasks() {
$tasks['site']['verify'] = array( $tasks['site']['verify'] = array(
'title' => t('Verify'), 'title' => t('Verify'),
'description' => t('Confirm that the site has been correctly installed and regenerate all configuration files to match the hosting front end.'), '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( $tasks['site']['disable'] = array(
...@@ -259,13 +260,15 @@ function hosting_site_hosting_tasks() { ...@@ -259,13 +260,15 @@ function hosting_site_hosting_tasks() {
$tasks['site']['install'] = array( $tasks['site']['install'] = array(
'title' => t('Install'), 'title' => t('Install'),
'description' => t('Install a site'), 'description' => t('Install a site'),
'hidden' => TRUE 'hidden' => TRUE,
'provision_save' => TRUE,
); );
$tasks['site']['import'] = array( $tasks['site']['import'] = array(
'title' => t('Import'), 'title' => t('Import'),
'description' => t('Import an existing site into Aegir'), 'description' => t('Import an existing site into Aegir'),
'hidden' => TRUE 'hidden' => TRUE,
'provision_save' => TRUE,
); );
return $tasks; return $tasks;
......
...@@ -75,6 +75,14 @@ function drush_hosting_task_validate($id, $type = null) { ...@@ -75,6 +75,14 @@ function drush_hosting_task_validate($id, $type = null) {
else { else {
drush_set_error('HOSTING_INVALID_TASK', t("This task is not valid")); 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) { ...@@ -85,6 +93,7 @@ function drush_hosting_task_validate($id, $type = null) {
* are attached to the task for reference. * are attached to the task for reference.
* *
* @see drush_hosting_task_validate() * @see drush_hosting_task_validate()
* @see hook_hosting_TASK_OBJECT_context_options()
*/ */
function drush_hosting_task() { function drush_hosting_task() {
$task =& drush_get_context('HOSTING_TASK'); $task =& drush_get_context('HOSTING_TASK');
...@@ -94,9 +103,10 @@ function drush_hosting_task() { ...@@ -94,9 +103,10 @@ function drush_hosting_task() {
// Make sure argument order is correct // Make sure argument order is correct
ksort($task->args); ksort($task->args);
// On install/verify, save the named context // If this task type needs it, run provision-save to create the named context.
if ($task->task_type === 'install' || $task->task_type === 'verify' || $task->task_type === 'import') { if (!empty($task->task_info['provision_save'])) {
// XXX: we copy module_invoke_all() here because it doesn't pass by // 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 // reference and it breaks under PHP 5.3
$hook = 'hosting_' . $task->ref->type . '_context_options'; $hook = 'hosting_' . $task->ref->type . '_context_options';
foreach (module_implements($hook) as $module) { foreach (module_implements($hook) as $module) {
...@@ -106,10 +116,12 @@ function drush_hosting_task() { ...@@ -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)); $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. // 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); $output = provision_backend_invoke($task->ref->hosting_name, 'provision-' . $task->task_type, $task->args, $task->options, $mode);
drush_set_context('HOSTING_DRUSH_OUTPUT', $output); drush_set_context('HOSTING_DRUSH_OUTPUT', $output);
$code = drush_get_error(); $code = drush_get_error();
// We return 0 on success, so anything else is an error. // We return 0 on success, so anything else is an error.
$task->task_status = ($code) ? HOSTING_TASK_ERROR : HOSTING_TASK_SUCCESS; $task->task_status = ($code) ? HOSTING_TASK_ERROR : HOSTING_TASK_SUCCESS;
......
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
* task will still be available for execution by the front-end however. * task will still be available for execution by the front-end however.
* - 'access callback' (optional) An access callback to determine if the user * - 'access callback' (optional) An access callback to determine if the user
* can access the task, defaults to 'hosting_task_menu_access'. * can access the task, defaults to 'hosting_task_menu_access'.
* - 'provision_save' (optional, defaults to FALSE) A flag that tells
* provision that a "provision-save" command needs to happen before this
* task can be run, used for tasks like Verify, Install, and Import.
* 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_available_tasks() * @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