MDL-82175 cron: Improved task view logs page

This commit is contained in:
Brendan Heywood 2024-06-20 16:58:16 +10:00
parent a75365f2e4
commit 340e8b120a
5 changed files with 41 additions and 6 deletions

View File

@ -105,9 +105,10 @@ class task_log extends base {
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_field("$tablealias.classname")
->add_fields("{$tablealias}.classname, {$tablealias}.id")
->set_is_sortable(true)
->add_callback(static function(string $classname): string {
->add_callback(static function($value, stdClass $row): string {
$classname = $row->classname;
$output = '';
if (class_exists($classname)) {
$task = new $classname;
@ -118,6 +119,7 @@ class task_log extends base {
$output .= \html_writer::tag('div', "\\{$classname}", [
'class' => 'small text-muted',
]);
$output = \html_writer::link(new \moodle_url('/admin/tasklogs.php', ['logid' => $row->id]), $output);
return $output;
});

View File

@ -143,7 +143,7 @@ class task_logs extends system_report {
new moodle_url('/admin/tasklogs.php', ['logid' => ':id']),
new pix_icon('e/search', ''),
[],
true,
false,
new lang_string('view'),
)));

View File

@ -24,6 +24,7 @@
require_once(__DIR__ . '/../config.php');
require_once("{$CFG->libdir}/adminlib.php");
require_once("tool/task/lib.php");
use core_admin\reportbuilder\local\systemreports\task_logs;
use core_reportbuilder\system_report_factory;
@ -49,9 +50,41 @@ if (null !== $logid) {
if ($download) {
$filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
header("Content-Disposition: attachment; filename=\"{$filename}\"");
readstring_accel($log->output, 'text/plain');
exit;
}
readstring_accel($log->output, 'text/plain');
try {
$class = new $log->classname;
$title = $class->get_name();
} catch (Exception $e) {
$title = $log->classname;
}
$title .= " ($log->id)";
$PAGE->navbar->add($title, '');
echo $OUTPUT->header();
echo html_writer::start_tag('pre', ['class' => 'task-output', 'style' => 'min-height: 24lh']);
echo tool_task_mtrace_wrapper($log->output);
echo html_writer::end_tag('pre');
echo $OUTPUT->action_link(
new moodle_url('/admin/tasklogs.php'),
$strheading,
null,
null,
new pix_icon('i/log', ''),
);
echo ' ';
echo $OUTPUT->action_link(
new moodle_url('/admin/tasklogs.php', ['logid' => $log->id, 'download' => true]),
new lang_string('download'),
null,
null,
new pix_icon('t/download', ''),
);
echo $OUTPUT->footer();
exit;
}

View File

@ -44,7 +44,7 @@ function tool_task_status_checks(): array {
* @param string $message Message to output
* @param string $eol End of line character
*/
function tool_task_mtrace_wrapper(string $message, string $eol): void {
function tool_task_mtrace_wrapper(string $message, string $eol = ''): void {
$message = s($message);
// We autolink urls and emails here but can't use format_text as it does

View File

@ -16,7 +16,7 @@
font-size: 0.75em;
}
.path-admin-tool-task .task-output {
.path-admin .task-output {
color: #fff;
background: #333;
padding: 1em;