Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * 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");
1441 ariadna 27
require_once("tool/task/lib.php");
1 efrain 28
 
29
use core_admin\reportbuilder\local\systemreports\task_logs;
30
use core_reportbuilder\system_report_factory;
31
 
32
$PAGE->set_url(new \moodle_url('/admin/tasklogs.php'));
33
$PAGE->set_context(context_system::instance());
34
$PAGE->set_pagelayout('admin');
35
$strheading = get_string('tasklogs', 'admin');
36
$PAGE->set_title($strheading);
37
$PAGE->set_heading($strheading);
38
 
39
admin_externalpage_setup('tasklogs');
40
 
41
$logid = optional_param('logid', null, PARAM_INT);
42
$download = optional_param('download', false, PARAM_BOOL);
43
$filter = optional_param('filter', null, PARAM_TEXT);
44
 
45
if (null !== $logid) {
46
    // Raise memory limit in case the log is large.
47
    raise_memory_limit(MEMORY_HUGE);
48
    $log = $DB->get_record('task_log', ['id' => $logid], '*', MUST_EXIST);
49
 
50
    if ($download) {
51
        $filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
52
        header("Content-Disposition: attachment; filename=\"{$filename}\"");
1441 ariadna 53
        readstring_accel($log->output, 'text/plain');
54
        exit;
1 efrain 55
    }
56
 
1441 ariadna 57
    try {
58
        $class = new $log->classname;
59
        $title = $class->get_name();
60
    } catch (Exception $e) {
61
        $title = $log->classname;
62
    }
63
    $title .= " ($log->id)";
64
 
65
    $PAGE->navbar->add($title, '');
66
    echo $OUTPUT->header();
67
    echo html_writer::start_tag('pre', ['class' => 'task-output', 'style' => 'min-height: 24lh']);
68
 
69
    echo tool_task_mtrace_wrapper($log->output);
70
    echo html_writer::end_tag('pre');
71
    echo $OUTPUT->action_link(
72
        new moodle_url('/admin/tasklogs.php'),
73
        $strheading,
74
        null,
75
        null,
76
        new pix_icon('i/log', ''),
77
    );
78
    echo ' ';
79
    echo $OUTPUT->action_link(
80
        new moodle_url('/admin/tasklogs.php', ['logid' => $log->id, 'download' => true]),
81
        new lang_string('download'),
82
        null,
83
        null,
84
        new pix_icon('t/download', ''),
85
    );
86
 
87
    echo $OUTPUT->footer();
1 efrain 88
    exit;
89
}
90
 
91
echo $OUTPUT->header();
92
$report = system_report_factory::create(task_logs::class, context_system::instance());
93
 
94
if (!empty($filter)) {
95
    $report->set_filter_values([
96
        'task_log:name_values' => trim($filter, '\\'),
97
    ]);
98
}
99
 
100
echo $report->output();
101
echo $OUTPUT->footer();