From 87a6da0d598306bbd08bda4eecffbdca96255a17 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Thu, 10 Mar 2022 16:18:23 +0100 Subject: [PATCH] MDL-74141 tool_task: Display error when Path to CLI not defined When "Path to PHP CLI" is not defined, an exception with the message in cannotfindthepathtothecli should be displayed, and the page should be redirected to System paths settings page. Apart from that, this patch also replaced core_task to tool_task, because this message wasn't traslated properly. --- admin/tool/task/schedule_task.php | 8 ++++++-- lib/classes/task/manager.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/admin/tool/task/schedule_task.php b/admin/tool/task/schedule_task.php index 1c72eb4fd8c..5179b9e4c3b 100644 --- a/admin/tool/task/schedule_task.php +++ b/admin/tool/task/schedule_task.php @@ -54,12 +54,16 @@ if (!$task) { throw new moodle_exception('cannotfindinfo', 'error', new moodle_url('/admin/tool/task/scheduledtasks.php'), $taskname); } +if (!\core\task\manager::is_runnable()) { + $redirecturl = new \moodle_url('/admin/settings.php', ['section' => 'systempaths']); + throw new moodle_exception('cannotfindthepathtothecli', 'tool_task', $redirecturl->out()); +} + $plugininfo = core_plugin_manager::instance()->get_plugin_info($task->get_component()); $plugindisabled = $plugininfo && $plugininfo->is_enabled() === false && !$task->get_run_if_component_disabled(); -$canruntasks = \core\task\manager::is_runnable() && get_config('tool_task', 'enablerunnow'); -if (!$canruntasks || $plugindisabled) { +if (!get_config('tool_task', 'enablerunnow') || $plugindisabled) { throw new moodle_exception('nopermissions', 'error', new moodle_url('/admin/tool/task/scheduledtasks.php'), get_string('runnow', 'tool_task'), $task->get_name()); } diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index 48667b1f97a..636d4d0cc7b 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -1116,7 +1116,7 @@ class manager { if (!self::is_runnable()) { $redirecturl = new \moodle_url('/admin/settings.php', ['section' => 'systempaths']); - throw new \moodle_exception('cannotfindthepathtothecli', 'core_task', $redirecturl->out()); + throw new \moodle_exception('cannotfindthepathtothecli', 'tool_task', $redirecturl->out()); } else { // Shell-escaped path to the PHP binary. $phpbinary = escapeshellarg(self::find_php_cli_path());