Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Web cron single task 19 * 20 * This script runs a single scheduled task from the web UI. 21 * 22 * @package tool_task 23 * @copyright 2016 The Open University 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 define('NO_OUTPUT_BUFFERING', true); 28 29 require('../../../config.php'); 30 31 require_once($CFG->libdir.'/cronlib.php'); 32 33 // Allow execution of single task. This requires login and has different rules. 34 $taskname = required_param('task', PARAM_RAW_TRIMMED); 35 36 // Basic security checks. 37 require_admin(); 38 $context = context_system::instance(); 39 40 // Check input parameter against all existing tasks (this ensures it isn't possible to 41 // create some kind of security problem by specifying a class that isn't a task or whatever). 42 $task = \core\task\manager::get_scheduled_task($taskname); 43 if (!$task) { 44 throw new moodle_exception('cannotfindinfo', 'error', new moodle_url('/admin/tool/task/scheduledtasks.php'), $taskname); 45 } 46 47 if (!\core\task\manager::is_runnable()) { 48 $redirecturl = new \moodle_url('/admin/settings.php', ['section' => 'systempaths']); 49 throw new moodle_exception('cannotfindthepathtothecli', 'tool_task', $redirecturl->out()); 50 } 51 52 $plugininfo = core_plugin_manager::instance()->get_plugin_info($task->get_component()); 53 $plugindisabled = $plugininfo && $plugininfo->is_enabled() === false && 54 !$task->get_run_if_component_disabled(); 55 56 if (!get_config('tool_task', 'enablerunnow') || $plugindisabled) { 57 throw new moodle_exception('nopermissions', 'error', new moodle_url('/admin/tool/task/scheduledtasks.php'), 58 get_string('runnow', 'tool_task'), $task->get_name()); 59 } 60 61 // Start output. 62 $PAGE->set_url(new moodle_url('/admin/tool/task/schedule_task.php', ['task' => $taskname])); 63 $PAGE->set_context($context); 64 $PAGE->set_heading($SITE->fullname); 65 $PAGE->set_title($task->get_name()); 66 67 navigation_node::override_active_url(new moodle_url('/admin/tool/task/scheduledtasks.php')); 68 $PAGE->navbar->add(s($task->get_name())); 69 70 echo $OUTPUT->header(); 71 echo $OUTPUT->heading($task->get_name()); 72 73 // The initial request just shows the confirmation page; we don't do anything further unless 74 // they confirm. 75 if (!optional_param('confirm', 0, PARAM_INT)) { 76 echo $OUTPUT->confirm(get_string('runnow_confirm', 'tool_task', $task->get_name()), 77 new single_button(new moodle_url('/admin/tool/task/schedule_task.php', 78 ['task' => $taskname, 'confirm' => 1, 'sesskey' => sesskey()]), 79 get_string('runnow', 'tool_task')), 80 new single_button(new moodle_url('/admin/tool/task/scheduledtasks.php', 81 ['lastchanged' => get_class($task)]), 82 get_string('cancel'), false)); 83 echo $OUTPUT->footer(); 84 exit; 85 } 86 87 // Action requires session key. 88 require_sesskey(); 89 90 \core\session\manager::write_close(); 91 92 // Prepare to handle output via mtrace. 93 echo html_writer::start_tag('pre'); 94 require ('lib.php'); 95 $CFG->mtrace_wrapper = 'tool_task_mtrace_wrapper'; 96 97 // Run the specified task (this will output an error if it doesn't exist). 98 \core\task\manager::run_from_cli($task); 99 100 echo html_writer::end_tag('pre'); 101 102 $output = $PAGE->get_renderer('tool_task'); 103 104 // Re-run the specified task (this will output an error if it doesn't exist). 105 echo $OUTPUT->single_button(new moodle_url('/admin/tool/task/schedule_task.php', 106 array('task' => $taskname, 'confirm' => 1, 'sesskey' => sesskey())), 107 get_string('runagain', 'tool_task')); 108 echo $output->link_back(get_class($task)); 109 110 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body