| 1 | 
           efrain | 
           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 | 
            * Script clears the fail delay for a task and reschedules its next execution.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package tool_task
  | 
        
        
            | 
            | 
           21 | 
            * @copyright 2017 The Open University
  | 
        
        
            | 
            | 
           22 | 
            * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            */
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           define('NO_OUTPUT_BUFFERING', true);
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           require('../../../config.php');
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           // Basic security checks.
  | 
        
        
            | 
            | 
           30 | 
           require_admin();
  | 
        
        
            | 
            | 
           31 | 
           $context = context_system::instance();
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           // Get task and check the parameter is valid.
  | 
        
        
            | 
            | 
           34 | 
           $taskname = required_param('task', PARAM_RAW_TRIMMED);
  | 
        
        
            | 
            | 
           35 | 
           $task = \core\task\manager::get_scheduled_task($taskname);
  | 
        
        
            | 
            | 
           36 | 
           if (!$task) {
  | 
        
        
            | 
            | 
           37 | 
               throw new \moodle_exception('cannotfindinfo', 'error', $taskname);
  | 
        
        
            | 
            | 
           38 | 
           }
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
           $returnurl = new moodle_url('/admin/tool/task/scheduledtasks.php',
  | 
        
        
            | 
            | 
           41 | 
                   ['lastchanged' => get_class($task)]);
  | 
        
        
            | 
            | 
           42 | 
              | 
        
        
            | 
            | 
           43 | 
           // If actually doing the clear, then carry out the task and redirect to the scheduled task page.
  | 
        
        
            | 
            | 
           44 | 
           if (optional_param('confirm', 0, PARAM_INT)) {
  | 
        
        
            | 
            | 
           45 | 
               require_sesskey();
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
               \core\task\manager::clear_fail_delay($task);
  | 
        
        
            | 
            | 
           48 | 
              | 
        
        
            | 
            | 
           49 | 
               redirect($returnurl);
  | 
        
        
            | 
            | 
           50 | 
           }
  | 
        
        
            | 
            | 
           51 | 
              | 
        
        
            | 
            | 
           52 | 
           // Start output.
  | 
        
        
            | 
            | 
           53 | 
           $PAGE->set_url(new moodle_url('/admin/tool/task/schedule_task.php'));
  | 
        
        
            | 
            | 
           54 | 
           $PAGE->set_context($context);
  | 
        
        
            | 
            | 
           55 | 
           $PAGE->navbar->add(get_string('scheduledtasks', 'tool_task'), new moodle_url('/admin/tool/task/scheduledtasks.php'));
  | 
        
        
            | 
            | 
           56 | 
           $PAGE->navbar->add(s($task->get_name()));
  | 
        
        
            | 
            | 
           57 | 
           $PAGE->navbar->add(get_string('clear'));
  | 
        
        
            | 
            | 
           58 | 
           echo $OUTPUT->header();
  | 
        
        
            | 
            | 
           59 | 
              | 
        
        
            | 
            | 
           60 | 
           // The initial request just shows the confirmation page; we don't do anything further unless
  | 
        
        
            | 
            | 
           61 | 
           // they confirm.
  | 
        
        
            | 
            | 
           62 | 
           echo $OUTPUT->confirm(get_string('clearfaildelay_confirm', 'tool_task', $task->get_name()),
  | 
        
        
            | 
            | 
           63 | 
                   new single_button(new moodle_url('/admin/tool/task/clear_fail_delay.php',
  | 
        
        
            | 
            | 
           64 | 
                           ['task' => $taskname, 'confirm' => 1, 'sesskey' => sesskey()]),
  | 
        
        
            | 
            | 
           65 | 
                           get_string('clear')),
  | 
        
        
            | 
            | 
           66 | 
                   new single_button($returnurl, get_string('cancel'), false));
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
           echo $OUTPUT->footer();
  |