From f12f34166dc8ba8d507d09ce0cb314e805a8303e Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 30 Apr 2014 10:45:37 +0800 Subject: [PATCH] MDL-45329 admin_task: Allow scheduled task change prevention Some hosting providers have a requirement to prevent users making modifications to the configuration of scheduled tasks as doing so may have a negative impact not only on their own site, but also on the performance of other sites (depending on host configuration). For example, if the statistics or automated backup tasks were run every minute, this could have a negative impact for other users). --- admin/tool/task/lang/en/tool_task.php | 1 + admin/tool/task/renderer.php | 10 ++++++++-- admin/tool/task/scheduledtasks.php | 4 ++-- config-dist.php | 5 +++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/admin/tool/task/lang/en/tool_task.php b/admin/tool/task/lang/en/tool_task.php index 493fa1dea90..6b4410e27b8 100644 --- a/admin/tool/task/lang/en/tool_task.php +++ b/admin/tool/task/lang/en/tool_task.php @@ -37,6 +37,7 @@ $string['pluginname'] = 'Scheduled task configuration'; $string['resettasktodefaults'] = 'Reset task schedule to defaults'; $string['resettasktodefaults_help'] = 'This will discard any local changes and revert the schedule for this task back to its original settings.'; $string['scheduledtasks'] = 'Scheduled tasks'; +$string['scheduledtaskchangesdisabled'] = 'Modifications to the list of scheduled tasks have been prevented in Moodle configuration'; $string['taskscheduleday'] = 'Day'; $string['taskscheduleday_help'] = 'Day of month field for task schedule. The field uses the same format as unix cron. Some examples are:
'; $string['taskscheduledayofweek'] = 'Day of week'; diff --git a/admin/tool/task/renderer.php b/admin/tool/task/renderer.php index f32c9e0025e..360ec9e8622 100644 --- a/admin/tool/task/renderer.php +++ b/admin/tool/task/renderer.php @@ -39,6 +39,8 @@ class tool_task_renderer extends plugin_renderer_base { * @return string HTML to output. */ public function scheduled_tasks_table($tasks) { + global $CFG; + $table = new html_table(); $table->head = array(get_string('name'), get_string('component', 'tool_task'), @@ -70,8 +72,12 @@ class tool_task_renderer extends plugin_renderer_base { } else { $nextrun = $asap; } - $configureurl = new moodle_url('/admin/tool/task/scheduledtasks.php', array('action'=>'edit', 'task' => get_class($task))); - $editlink = $this->action_icon($configureurl, new pix_icon('t/edit', get_string('edittaskschedule', 'tool_task', $task->get_name()))); + if (empty($CFG->preventscheduledtaskchanges)) { + $configureurl = new moodle_url('/admin/tool/task/scheduledtasks.php', array('action'=>'edit', 'task' => get_class($task))); + $editlink = $this->action_icon($configureurl, new pix_icon('t/edit', get_string('edittaskschedule', 'tool_task', $task->get_name()))); + } else { + $editlink = $this->render(new pix_icon('t/locked', get_string('scheduledtaskchangesdisabled', 'tool_task'))); + } $namecell = new html_table_cell($task->get_name() . "\n" . html_writer::tag('span', '\\'.get_class($task), array('class' => 'task-class'))); $namecell->header = true; diff --git a/admin/tool/task/scheduledtasks.php b/admin/tool/task/scheduledtasks.php index 2b38300e9ea..768d4bc0065 100644 --- a/admin/tool/task/scheduledtasks.php +++ b/admin/tool/task/scheduledtasks.php @@ -59,9 +59,9 @@ if ($task) { $mform = new tool_task_edit_scheduled_task_form(null, $task); } -if ($mform && $mform->is_cancelled()) { +if ($mform && ($mform->is_cancelled() || !empty($CFG->preventscheduledtaskchanges))) { redirect(new moodle_url('/admin/tool/task/scheduledtasks.php')); -} else if ($action == 'edit') { +} else if ($action == 'edit' && empty($CFG->preventscheduledtaskchanges)) { if ($data = $mform->get_data()) { diff --git a/config-dist.php b/config-dist.php index 47ffb73416f..c182b8741c8 100644 --- a/config-dist.php +++ b/config-dist.php @@ -452,6 +452,11 @@ $CFG->admin = 'admin'; // // $CFG->disableonclickaddoninstall = true; // +// Use the following flag to disable modifications to scheduled tasks +// whilst still showing the state of tasks. +// +// $CFG->preventscheduledtaskchanges = true; +// // As of version 2.4 Moodle serves icons as SVG images if the users browser appears // to support SVG. // For those wanting to control the serving of SVG images the following setting can