MDL-49399 tool_task: Link to log viewer
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 4 Dec 2018 02:56:48 +0000 (10:56 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 16 Jan 2019 04:14:25 +0000 (12:14 +0800)
This commit also adds the fa-file-text icon from font-awesome.

admin/classes/task_log_table.php
admin/settings/server.php
admin/tasklogs.php
admin/tool/task/lang/en/tool_task.php
admin/tool/task/renderer.php
admin/tool/task/settings.php
lib/classes/output/icon_system_fontawesome.php
pix/e/file-text.png [new file with mode: 0644]
pix/e/file-text.svg [new file with mode: 0644]

index 554d92d..2bb892d 100644 (file)
@@ -83,9 +83,17 @@ class task_log_table extends \table_sql {
         $where = [];
         $params = [];
         if (!empty($filter)) {
-            $where[] = $DB->sql_like('classname', ':filter', false, false);
+            $orwhere = [];
             $filter = str_replace('\\', '\\\\', $filter);
-            $params['filter'] = '%' . $DB->sql_like_escape($filter) . '%';
+
+            // Check the class name.
+            $orwhere[] = $DB->sql_like('classname', ':classfilter', false, false);
+            $params['classfilter'] = '%' . $DB->sql_like_escape($filter) . '%';
+
+            $orwhere[] = $DB->sql_like('output', ':outputfilter', false, false);
+            $params['outputfilter'] = '%' . $DB->sql_like_escape($filter) . '%';
+
+            $where[] = "(" . implode(' OR ', $orwhere) . ")";
         }
 
         if (null !== $resultfilter) {
index eaa318c..9102155 100644 (file)
@@ -249,7 +249,7 @@ if (\core\task\logmanager::uses_standard_settings()) {
 }
 $ADMIN->add('taskconfig', $temp);
 
-if (empty($CFG->task_log_class) || '\\core\\task\\database_logger' == $CFG->task_log_class) {
+if (\core\task\logmanager::uses_standard_settings()) {
     $ADMIN->add('taskconfig', new admin_externalpage(
         'tasklogs',
         new lang_string('tasklogs','admin'),
index bcebd58..6684a7e 100644 (file)
@@ -27,7 +27,7 @@ require_once("{$CFG->libdir}/adminlib.php");
 require_once("{$CFG->libdir}/tablelib.php");
 require_once("{$CFG->libdir}/filelib.php");
 
-$filter = optional_param('filter', '', PARAM_ALPHANUMEXT);
+$filter = optional_param('filter', '', PARAM_RAW);
 $result = optional_param('result', null, PARAM_INT);
 
 $pageurl = new \moodle_url('/admin/tasklogs.php');
@@ -51,13 +51,13 @@ $download = optional_param('download', false, PARAM_BOOL);
 if (null !== $logid) {
     $log = $DB->get_record('task_log', ['id' => $logid], '*', MUST_EXIST);
 
-    $fs = get_file_storage();
-    $file = $fs->get_file(\context_system::instance()->id, 'core', 'task_logs', $log->id, '/', 'log.txt');
+    if ($download) {
+        $filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
+        header("Content-Disposition: attachment; filename=\"{$filename}\"");
+    }
 
-    $filename = str_replace('\\', '_', $log->classname) . "-{$log->id}.log";
-    send_stored_file($file, null, 0, $download, [
-            'filename' => $filename,
-        ]);
+    readstring_accel($log->output, 'text/plain', false);
+    exit;
 }
 
 $renderer = $PAGE->get_renderer('tool_task');
index 8ea9c70..a28b478 100644 (file)
@@ -48,6 +48,7 @@ $string['runpattern'] = 'Run pattern';
 $string['scheduledtasks'] = 'Scheduled tasks';
 $string['scheduledtaskchangesdisabled'] = 'Modifications to the list of scheduled tasks have been prevented in Moodle configuration';
 $string['taskdisabled'] = 'Task disabled';
+$string['tasklogs'] = 'Task logs';
 $string['taskscheduleday'] = 'Day';
 $string['taskscheduleday_help'] = 'Day of month field for task schedule. The field uses the same format as unix cron. Some examples are:<br/><ul><li><strong>*</strong> Every day</li><li><strong>*/2</strong> Every 2nd day</li><li><strong>1</strong> The first of every month</li><li><strong>1,15</strong> The first and fifteenth of every month</li></ul>';
 $string['taskscheduledayofweek'] = 'Day of week';
@@ -59,4 +60,4 @@ $string['taskscheduleminute_help'] = 'Minute field for task schedule. The field
 $string['taskschedulemonth'] = 'Month';
 $string['taskschedulemonth_help'] = 'Month field for task schedule. The field uses the same format as unix cron. Some examples are:<br/><ul><li><strong>*</strong> Every month</li><li><strong>*/2</strong> Every second month</li><li><strong>1</strong> Every January</li><li><strong>1,5</strong> Every January and May</li></ul>';
 $string['privacy:metadata'] = 'The Scheduled task configuration plugin does not store any personal data.';
-
+$string['viewlogs'] = 'View logs for {$a}';
index 88dbdd4..3afd20c 100644 (file)
@@ -41,20 +41,33 @@ class tool_task_renderer extends plugin_renderer_base {
     public function scheduled_tasks_table($tasks) {
         global $CFG;
 
+        $showloglink = \core\task\logmanager::has_log_report();
+
         $table = new html_table();
-        $table->head  = array(get_string('name'),
-                              get_string('component', 'tool_task'),
-                              get_string('edit'),
-                              get_string('lastruntime', 'tool_task'),
-                              get_string('nextruntime', 'tool_task'),
-                              get_string('taskscheduleminute', 'tool_task'),
-                              get_string('taskschedulehour', 'tool_task'),
-                              get_string('taskscheduleday', 'tool_task'),
-                              get_string('taskscheduledayofweek', 'tool_task'),
-                              get_string('taskschedulemonth', 'tool_task'),
-                              get_string('faildelay', 'tool_task'),
-                              get_string('default', 'tool_task'));
+        $table->head = [
+            get_string('name'),
+            get_string('component', 'tool_task'),
+            get_string('edit'),
+            get_string('logs'),
+            get_string('lastruntime', 'tool_task'),
+            get_string('nextruntime', 'tool_task'),
+            get_string('taskscheduleminute', 'tool_task'),
+            get_string('taskschedulehour', 'tool_task'),
+            get_string('taskscheduleday', 'tool_task'),
+            get_string('taskscheduledayofweek', 'tool_task'),
+            get_string('taskschedulemonth', 'tool_task'),
+            get_string('faildelay', 'tool_task'),
+            get_string('default', 'tool_task'),
+        ];
+
         $table->attributes['class'] = 'admintable generaltable';
+        $table->colclasses = [];
+
+        if (!$showloglink) {
+            // Hide the log links.
+            $table->colclasses['3'] = 'hidden';
+        }
+
         $data = array();
         $yes = get_string('yes');
         $no = get_string('no');
@@ -72,6 +85,14 @@ class tool_task_renderer extends plugin_renderer_base {
                 $editlink = $this->render(new pix_icon('t/locked', get_string('scheduledtaskchangesdisabled', 'tool_task')));
             }
 
+            $loglink = '';
+            if ($showloglink) {
+                $loglink = $this->action_icon(
+                    \core\task\logmanager::get_url_for_task_class(get_class($task)),
+                    new pix_icon('e/file-text', get_string('viewlogs', 'tool_task', $task->get_name())
+                ));
+            }
+
             $namecell = new html_table_cell($task->get_name() . "\n" . html_writer::tag('span', '\\'.get_class($task),
                 array('class' => 'task-class text-ltr')));
             $namecell->header = true;
@@ -125,6 +146,7 @@ class tool_task_renderer extends plugin_renderer_base {
                         $namecell,
                         $componentcell,
                         new html_table_cell($editlink),
+                        new html_table_cell($loglink),
                         new html_table_cell($lastrun . $runnow),
                         new html_table_cell($nextrun),
                         new html_table_cell($task->get_minute()),
@@ -136,11 +158,11 @@ class tool_task_renderer extends plugin_renderer_base {
                         new html_table_cell($customised)));
 
             // Cron-style values must always be LTR.
-            $row->cells[5]->attributes['class'] = 'text-ltr';
             $row->cells[6]->attributes['class'] = 'text-ltr';
             $row->cells[7]->attributes['class'] = 'text-ltr';
             $row->cells[8]->attributes['class'] = 'text-ltr';
             $row->cells[9]->attributes['class'] = 'text-ltr';
+            $row->cells[10]->attributes['class'] = 'text-ltr';
 
             if ($disabled) {
                 $row->attributes['class'] = 'disabled';
index ac75859..ac9858e 100644 (file)
 defined('MOODLE_INTERNAL') || die;
 
 if ($hassiteconfig) {
-    $ADMIN->add('server', new admin_externalpage('scheduledtasks', new lang_string('scheduledtasks','tool_task'), "$CFG->wwwroot/$CFG->admin/tool/task/scheduledtasks.php"));
+    $ADMIN->add(
+        'taskconfig',
+        new admin_externalpage(
+            'scheduledtasks',
+            new lang_string('scheduledtasks', 'tool_task'),
+            "$CFG->wwwroot/$CFG->admin/tool/task/scheduledtasks.php"
+        )
+    );
 }
index 1530895..e90efe8 100644 (file)
@@ -99,6 +99,7 @@ class icon_system_fontawesome extends icon_system_font {
             'core:e/document_properties' => 'fa-info',
             'core:e/emoticons' => 'fa-smile-o',
             'core:e/find_replace' => 'fa-search-plus',
+            'core:e/file-text' => 'fa-file-text',
             'core:e/forward' => 'fa-arrow-right',
             'core:e/fullpage' => 'fa-arrows-alt',
             'core:e/fullscreen' => 'fa-arrows-alt',
diff --git a/pix/e/file-text.png b/pix/e/file-text.png
new file mode 100644 (file)
index 0000000..02c2f66
Binary files /dev/null and b/pix/e/file-text.png differ
diff --git a/pix/e/file-text.svg b/pix/e/file-text.svg
new file mode 100644 (file)
index 0000000..25a8d4e
--- /dev/null
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><title>Artboard 1</title><path d="M14.86,4.86V15.14A.86.86,0,0,1,14,16H2a.86.86,0,0,1-.86-.86V.86A.86.86,0,0,1,2,0h8a2.39,2.39,0,0,1,1.46.61l2.79,2.79A2.39,2.39,0,0,1,14.86,4.86Zm-1.14.86H10a.86.86,0,0,1-.86-.86V1.14H2.29V14.86H13.71ZM4.86,6.86h6.29a.28.28,0,0,1,.29.29v.57a.28.28,0,0,1-.29.29H4.86a.28.28,0,0,1-.29-.29V7.14A.28.28,0,0,1,4.86,6.86Zm6.57,2.57V10a.28.28,0,0,1-.29.29H4.86A.28.28,0,0,1,4.57,10V9.43a.28.28,0,0,1,.29-.29h6.29A.28.28,0,0,1,11.43,9.43Zm0,2.29v.57a.28.28,0,0,1-.29.29H4.86a.28.28,0,0,1-.29-.29v-.57a.28.28,0,0,1,.29-.29h6.29A.28.28,0,0,1,11.43,11.71ZM10.29,4.57h3.36a1.14,1.14,0,0,0-.2-.37L10.65,1.41a1.14,1.14,0,0,0-.37-.2Z" fill="#999"/></svg>
\ No newline at end of file