Commit ad814aa8 authored by Steven Jones's avatar Steven Jones

Issue #1513678 by Jon Pugh, fastangel, Steven Jones: Fixed Hooks based on...

Issue #1513678 by Jon Pugh, fastangel, Steven Jones: Fixed Hooks based on TASK_NAME should handle task names with dashes in them.
parent 6f376669
......@@ -58,7 +58,7 @@ function drush_hosting_site_pre_hosting_task($task) {
$task->args[1] = $backup['filename'];
}
if ($task->task_type == 'backup_delete') {
if ($task->task_type == 'backup-delete') {
foreach ($task->task_args as $bid => $filename) {
if ($filename !== '0') {
$backups[] = $filename;
......
......@@ -269,3 +269,46 @@ function hosting_site_update_6008() {
return $ret;
}
/**
* Implements hook_update_N().
*/
function hosting_site_update_6200() {
$ret = array();
// We re-named 'login_reset' tasks to 'login-reset' and 'backup_delete' to
// 'backup-delete'.
$replacements = array(
'backup_delete' => 'backup-delete',
'login_reset' => 'login-reset',
);
foreach ($replacements as $old => $new) {
db_query("UPDATE {hosting_task} SET task_type = '%s' where task_type = '%s'", $new, $old);
}
return $ret;
}
/**
* Implements hook_update_N().
*/
function hosting_site_update_6201() {
$ret = array();
// We re-named 'login_reset' tasks to 'login-reset' and 'backup_delete' to
// 'backup-delete' and so we need to fix any roles using those permissions.
$replacements = array(
'create backup_delete task' => 'create backup-delete task',
'create login_reset task' => 'create login-reset task',
);
// Process all the roles.
$roles = db_query('SELECT rid, perm FROM {permission}');
while ($role = db_fetch_object($roles)) {
$perms = explode(', ', $role->perm);
$perms = str_replace(array_keys($replacements), array_values($replacements), $perms);
db_query("UPDATE {permission} SET perm = '%s' where rid = %d", implode(', ', $perms), $role->rid);
}
return $ret;
}
......@@ -245,12 +245,12 @@ function hosting_site_hosting_tasks() {
'dialog' => TRUE,
);
$tasks['site']['login_reset'] = array(
$tasks['site']['login-reset'] = array(
'title' => t('Reset password'),
'description' => t('Generate a one-time login reset url for this site.'),
);
$tasks['site']['backup_delete'] = array(
$tasks['site']['backup-delete'] = array(
'title' => t('Delete backups'),
'description' => t('Delete one or more backup files of a site.'),
'dialog' => TRUE,
......
......@@ -131,7 +131,7 @@ function drush_hosting_task() {
*/
function drush_hosting_hosting_task_rollback() {
$task =& drush_get_context('HOSTING_TASK');
module_invoke_all(sprintf("hosting_%s_task_rollback", $task->task_type), $task, drush_get_context('HOSTING_DRUSH_OUTPUT'));
module_invoke_all(sprintf("hosting_%s_task_rollback", str_replace('-', '_', $task->task_type)), $task, drush_get_context('HOSTING_DRUSH_OUTPUT'));
}
/**
......@@ -142,5 +142,5 @@ function drush_hosting_hosting_task_rollback() {
function drush_hosting_post_hosting_task($task) {
$task =& drush_get_context('HOSTING_TASK');
module_invoke_all(sprintf("post_hosting_%s_task", $task->task_type), $task, drush_get_context('HOSTING_DRUSH_OUTPUT'));
module_invoke_all(sprintf("post_hosting_%s_task", str_replace('-', '_', $task->task_type)), $task, drush_get_context('HOSTING_DRUSH_OUTPUT'));
}
......@@ -136,10 +136,10 @@ function hosting_task_menu_access($node, $task) {
if (hosting_task_outstanding($node->nid, 'delete') || ($node->site_status == HOSTING_SITE_DELETED)) {
return FALSE;
}
if (($task == 'login_reset') && ($node->site_status != HOSTING_SITE_ENABLED)) {
if (($task == 'login-reset') && ($node->site_status != HOSTING_SITE_ENABLED)) {
return FALSE;
}
$safe_tasks = array('backup', 'backup_delete', 'verify', 'enable');
$safe_tasks = array('backup', 'backup-delete', 'verify', 'enable');
if (!in_array($task, $safe_tasks)) {
// Don't show certain tasks if the site is the 'special' main aegir site
$profile = node_load($node->profile);
......@@ -261,8 +261,8 @@ function hosting_task_perm() {
'create verify task',
'create lock task',
'create unlock task',
'create login_reset task',
'create backup_delete task',
'create login-reset task',
'create backup-delete task',
'view own tasks',
'view task',
'access task logs',
......@@ -390,7 +390,7 @@ function hosting_task_confirm_form($form_state, $node, $task) {
$form['nid'] = array('#type' => 'value', '#value' => $node->nid);
$form['task'] = array('#type' => 'value', '#value' => $task);
$form['parameters'] = array('#tree' => TRUE);
$func = 'hosting_task_' . $task . '_form';
$func = 'hosting_task_' . str_replace('-', '_', $task) . '_form';
if (function_exists($func)) {
$form['parameters'] += $func($node);
}
......@@ -976,7 +976,7 @@ function hosting_task_queue_block() {
foreach ($nodes as $node) {
$row = array();
$row['type'] = array(
'data' => drupal_ucfirst(str_replace('_', ' ', $node->task_type)) . ' ' . _hosting_node_link($node->rid),
'data' => drupal_ucfirst(str_replace(array('_', '-'), ' ', $node->task_type)) . ' ' . _hosting_node_link($node->rid),
'class' => 'hosting-status'
);
......
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