Merge branch 'MDL-80290-task-ui' of https://github.com/brendanheywood/moodle

This commit is contained in:
Sara Arjona 2024-03-20 17:12:13 +01:00
commit be1bb3dfc3
No known key found for this signature in database
4 changed files with 32 additions and 6 deletions

View File

@ -46,5 +46,20 @@ function tool_task_status_checks(): array {
*/
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
// more than we need and has side effects which are not useful in this context.
$urlpattern = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/';
$message = preg_replace_callback($urlpattern, function($matches) {
$url = $matches[0];
return html_writer::link($url, $url, ['target' => '_blank']);
}, $message);
$emailpattern = '/[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/';
$message = preg_replace_callback($emailpattern, function($matches) {
$email = $matches[0];
return html_writer::link('mailto:' . $email, $email);
}, $message);
echo $message . $eol;
}

View File

@ -115,6 +115,8 @@ if (!$confirmed) {
require_sesskey();
\core\session\manager::write_close();
echo $OUTPUT->footer();
echo $OUTPUT->select_element_for_append();
// Prepare to handle output via mtrace.
require_once("{$CFG->dirroot}/{$CFG->admin}/tool/task/lib.php");
@ -124,7 +126,7 @@ $CFG->mtrace_wrapper = 'tool_task_mtrace_wrapper';
if ($taskid) {
$repeat = $DB->get_record('task_adhoc', ['id' => $taskid]);
echo html_writer::start_tag('pre');
echo html_writer::start_tag('pre', ['class' => 'task-output']);
\core\task\manager::run_adhoc_from_cli($taskid);
echo html_writer::end_tag('pre');
} else {
@ -133,13 +135,13 @@ if ($taskid) {
// Run failed first (if any). We have to run them separately anyway,
// because faildelay is observed if failed flag is not true.
echo html_writer::tag('p', get_string('runningfailedtasks', 'tool_task'), ['class' => 'lead']);
echo html_writer::start_tag('pre');
echo html_writer::start_tag('pre', ['class' => 'task-output']);
\core\task\manager::run_all_adhoc_from_cli(true, $classname);
echo html_writer::end_tag('pre');
if (!$failedonly) {
echo html_writer::tag('p', get_string('runningalltasks', 'tool_task'), ['class' => 'lead']);
echo html_writer::start_tag('pre');
echo html_writer::start_tag('pre', ['class' => 'task-output']);
\core\task\manager::run_all_adhoc_from_cli(false, $classname);
echo html_writer::end_tag('pre');
}
@ -161,4 +163,3 @@ echo html_writer::div(
)
);
echo $OUTPUT->footer();

View File

@ -88,9 +88,8 @@ echo $OUTPUT->footer();
echo $OUTPUT->select_element_for_append();
// Prepare to handle output via mtrace.
echo html_writer::start_tag('pre', ['style' => 'color: #fff; background: #333; padding: 1em; min-height: 24lh']);
require_once("{$CFG->dirroot}/{$CFG->admin}/tool/task/lib.php");
echo html_writer::start_tag('pre', ['class' => 'task-output', 'style' => 'min-height: 24lh']);
$CFG->mtrace_wrapper = 'tool_task_mtrace_wrapper';
// Run the specified task (this will output an error if it doesn't exist).

View File

@ -15,3 +15,14 @@
#page-admin-tool-task-scheduledtasks .task-clearfaildelay {
font-size: 0.75em;
}
.path-admin-tool-task .task-output {
color: #fff;
background: #333;
padding: 1em;
a {
color: #fff;
text-decoration: underline;
}
}