MDL-67274 Tasks: Log display fails with memory errors
[moodle.git] / admin / tasklogs.php
CommitLineData
8c69e86c
AN
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
25require_once(__DIR__ . '/../config.php');
26require_once("{$CFG->libdir}/adminlib.php");
27require_once("{$CFG->libdir}/tablelib.php");
28require_once("{$CFG->libdir}/filelib.php");
29
251ee97c 30$filter = optional_param('filter', '', PARAM_RAW);
8c69e86c
AN
31$result = optional_param('result', null, PARAM_INT);
32
33$pageurl = new \moodle_url('/admin/tasklogs.php');
34$pageurl->param('filter', $filter);
35
36$PAGE->set_url($pageurl);
37$PAGE->set_context(context_system::instance());
38$PAGE->set_pagelayout('admin');
39$strheading = get_string('tasklogs', 'tool_task');
40$PAGE->set_title($strheading);
41$PAGE->set_heading($strheading);
42
8c69e86c
AN
43admin_externalpage_setup('tasklogs');
44
45$logid = optional_param('logid', null, PARAM_INT);
46$download = optional_param('download', false, PARAM_BOOL);
47
48if (null !== $logid) {
b4e2b99c 49 // Raise memory limit in case the log is large.
50 raise_memory_limit(MEMORY_HUGE);
8c69e86c
AN
51 $log = $DB->get_record('task_log', ['id' => $logid], '*', MUST_EXIST);
52
251ee97c
AN
53 if ($download) {
54 $filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
55 header("Content-Disposition: attachment; filename=\"{$filename}\"");
56 }
8c69e86c 57
d6f5fbb7 58 readstring_accel($log->output, 'text/plain');
251ee97c 59 exit;
8c69e86c
AN
60}
61
62$renderer = $PAGE->get_renderer('tool_task');
63
64echo $OUTPUT->header();
65echo $OUTPUT->render_from_template('core_admin/tasklogs', (object) [
66 'action' => $pageurl->out(),
67 'filter' => $filter,
68 'resultfilteroptions' => [
69 (object) [
70 'value' => -1,
71 'title' => get_string('all'),
72 'selected' => (-1 === $result),
73 ],
74 (object) [
75 'value' => 0,
76 'title' => get_string('success'),
77 'selected' => (0 === $result),
78 ],
79 (object) [
80 'value' => 1,
81 'title' => get_string('task_result:failed', 'admin'),
82 'selected' => (1 === $result),
83 ],
84 ],
85]);
86
87$table = new \core_admin\task_log_table($filter, $result);
88$table->baseurl = $pageurl;
89$table->out(100, false);
90
91echo $OUTPUT->footer();