From 77857ced5a13f20006e2d5ab8deaeebda2745675 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 5 Oct 2021 08:03:48 +0100 Subject: [PATCH] MDL-72734 tool_task: consistent checks for running tasks from web. --- admin/tool/task/schedule_task.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/admin/tool/task/schedule_task.php b/admin/tool/task/schedule_task.php index 777de450c6e..68b5ebd231a 100644 --- a/admin/tool/task/schedule_task.php +++ b/admin/tool/task/schedule_task.php @@ -47,15 +47,17 @@ $taskname = required_param('task', PARAM_RAW_TRIMMED); require_admin(); $context = context_system::instance(); -if (!get_config('tool_task', 'enablerunnow')) { - print_error('nopermissions', 'error', '', get_string('runnow', 'tool_task')); -} - // Check input parameter against all existing tasks (this ensures it isn't possible to // create some kind of security problem by specifying a class that isn't a task or whatever). $task = \core\task\manager::get_scheduled_task($taskname); if (!$task) { - print_error('cannotfindinfo', 'error', $taskname); + throw new moodle_exception('cannotfindinfo', 'error', new moodle_url('/admin/tool/task/scheduledtasks.php'), $taskname); +} + +$canruntasks = \core\task\manager::is_runnable() && get_config('tool_task', 'enablerunnow'); +if (!$canruntasks || !$task->can_run()) { + throw new moodle_exception('nopermissions', 'error', new moodle_url('/admin/tool/task/scheduledtasks.php'), + get_string('runnow', 'tool_task'), $task->get_name()); } // Start output.