Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/admin/ -> tasklogs.php (source)

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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   * Task log.
  19   *
  20   * @package    admin
  21   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../config.php');
  26  require_once("{$CFG->libdir}/adminlib.php");
  27  require_once("{$CFG->libdir}/tablelib.php");
  28  require_once("{$CFG->libdir}/filelib.php");
  29  
  30  $filter = optional_param('filter', '', PARAM_RAW);
  31  $result = optional_param('result', null, PARAM_INT);
  32  
  33  $pageurl = new \moodle_url('/admin/tasklogs.php');
  34  $pageurl->param('filter', $filter);
  35  $pageurl->param('result', $result);
  36  
  37  $PAGE->set_url($pageurl);
  38  $PAGE->set_context(context_system::instance());
  39  $PAGE->set_pagelayout('admin');
  40  $strheading = get_string('tasklogs', 'tool_task');
  41  $PAGE->set_title($strheading);
  42  $PAGE->set_heading($strheading);
  43  
  44  admin_externalpage_setup('tasklogs');
  45  
  46  $logid = optional_param('logid', null, PARAM_INT);
  47  $download = optional_param('download', false, PARAM_BOOL);
  48  
  49  if (null !== $logid) {
  50      // Raise memory limit in case the log is large.
  51      raise_memory_limit(MEMORY_HUGE);
  52      $log = $DB->get_record('task_log', ['id' => $logid], '*', MUST_EXIST);
  53  
  54      if ($download) {
  55          $filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
  56          header("Content-Disposition: attachment; filename=\"{$filename}\"");
  57      }
  58  
  59      readstring_accel($log->output, 'text/plain');
  60      exit;
  61  }
  62  
  63  $renderer = $PAGE->get_renderer('tool_task');
  64  
  65  echo $OUTPUT->header();
  66  
  67  // Output the search form.
  68  echo $OUTPUT->render_from_template('core_admin/tasklogs', (object) [
  69      'action' => $pageurl->out(),
  70      'filter' => htmlentities($filter),
  71      'resultfilteroptions' => [
  72          (object) [
  73              'value' => -1,
  74              'title' => get_string('all'),
  75              'selected' => (-1 === $result),
  76          ],
  77          (object) [
  78              'value' => 0,
  79              'title' => get_string('success'),
  80              'selected' => (0 === $result),
  81          ],
  82          (object) [
  83              'value' => 1,
  84              'title' => get_string('task_result:failed', 'admin'),
  85              'selected' => (1 === $result),
  86          ],
  87      ],
  88  ]);
  89  
  90  // Output any matching logs.
  91  $table = new \core_admin\task_log_table($filter, $result);
  92  $table->baseurl = $pageurl;
  93  $table->out(100, false);
  94  
  95  echo $OUTPUT->footer();