From fc92e42abfe99803fee26dc34b695c2b032b6c31 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 31 Aug 2021 17:17:55 +0100 Subject: [PATCH] MDL-67686 task: add duration filter to task logs report. --- admin/classes/local/entities/task_log.php | 11 +++++++++++ .../classes/local/systemreports/task_logs.php | 1 + admin/tests/behat/task_logs.feature | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/admin/classes/local/entities/task_log.php b/admin/classes/local/entities/task_log.php index 4f8136ada8b..d54f260b386 100644 --- a/admin/classes/local/entities/task_log.php +++ b/admin/classes/local/entities/task_log.php @@ -17,6 +17,7 @@ namespace core_admin\local\entities; use core_reportbuilder\local\filters\date; +use core_reportbuilder\local\filters\duration; use core_reportbuilder\local\filters\select; use core_reportbuilder\local\filters\text; use core_reportbuilder\local\helpers\format; @@ -282,6 +283,16 @@ class task_log extends base { )) ->add_joins($this->get_joins()); + // Duration filter. + $filters[] = (new filter( + duration::class, + 'duration', + new lang_string('task_duration', 'admin'), + $this->get_entity_name(), + "${tablealias}.timeend - {$tablealias}.timestart" + )) + ->add_joins($this->get_joins()); + return $filters; } } diff --git a/admin/classes/local/systemreports/task_logs.php b/admin/classes/local/systemreports/task_logs.php index 8cf9959c256..9688fa3d591 100644 --- a/admin/classes/local/systemreports/task_logs.php +++ b/admin/classes/local/systemreports/task_logs.php @@ -124,6 +124,7 @@ class task_logs extends system_report { 'task_log:output', 'task_log:result', 'task_log:timestart', + 'task_log:duration', ]; $this->add_filters_from_entities($filters); diff --git a/admin/tests/behat/task_logs.feature b/admin/tests/behat/task_logs.feature index 686ca4bbd9f..b17cd935d11 100644 --- a/admin/tests/behat/task_logs.feature +++ b/admin/tests/behat/task_logs.feature @@ -29,3 +29,22 @@ Feature: View task logs report and use its filters | name | match | nonmatch | | task\\clean_events | Cleanup event monitor events | Incoming email pickup | | task\\pickup_task | Incoming email pickup | Cleanup event monitor events | + + @javascript + # Task duration is dependent on many factors, we are asserting here that no task has a duration >2 minutes. + Scenario Outline: Filter task logs by duration + Given I log in as "admin" + And I change window size to "large" + And I navigate to "Server > Tasks > Task logs" in site administration + When I click on "Filters" "button" + And I set the following fields in the "Duration" "core_reportbuilder > Filter" to these values: + | Duration operator | | + | Duration value | 2 | + | Duration unit | minutes | + And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element" + Then I should see "Filters applied" + And I "Nothing to display" + Examples: + | operator | shouldornotsee | + | Less than | should not see | + | Greater than | should see |