Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/admin/ -> tasklogs.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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  
  28  use core_admin\local\systemreports\task_logs;
  29  use core_reportbuilder\system_report_factory;
  30  
  31  $PAGE->set_url(new \moodle_url('/admin/tasklogs.php'));
  32  $PAGE->set_context(context_system::instance());
  33  $PAGE->set_pagelayout('admin');
  34  $strheading = get_string('tasklogs', 'admin');
  35  $PAGE->set_title($strheading);
  36  $PAGE->set_heading($strheading);
  37  
  38  admin_externalpage_setup('tasklogs');
  39  
  40  $logid = optional_param('logid', null, PARAM_INT);
  41  $download = optional_param('download', false, PARAM_BOOL);
  42  $filter = optional_param('filter', null, PARAM_TEXT);
  43  
  44  if (null !== $logid) {
  45      // Raise memory limit in case the log is large.
  46      raise_memory_limit(MEMORY_HUGE);
  47      $log = $DB->get_record('task_log', ['id' => $logid], '*', MUST_EXIST);
  48  
  49      if ($download) {
  50          $filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
  51          header("Content-Disposition: attachment; filename=\"{$filename}\"");
  52      }
  53  
  54      readstring_accel($log->output, 'text/plain');
  55      exit;
  56  }
  57  
  58  echo $OUTPUT->header();
  59  $report = system_report_factory::create(task_logs::class, context_system::instance());
  60  
  61  if (!empty($filter)) {
  62      $report->set_filter_values([
  63          'task_log:name_operator' => \core_reportbuilder\local\filters\text::IS_EQUAL_TO,
  64          'task_log:name_value' => $filter,
  65      ]);
  66  }
  67  
  68  echo $report->output();
  69  echo $OUTPUT->footer();