From 3597ec7916623d6b72902df1c363b40f789c71ef Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 31 Jul 2025 14:16:41 +0100 Subject: [PATCH] MDL-86177 task: ensure tasks are runnable in indicator output. Also fix case where task indicator progress data no longer exists, which lead to exceptions when encountered, breaking the gradebook. --- grade/tests/behat/grade_async_regrade.feature | 7 ------- lib/classes/output/task_indicator.php | 7 +++++-- lib/templates/task_indicator.mustache | 10 +++++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/grade/tests/behat/grade_async_regrade.feature b/grade/tests/behat/grade_async_regrade.feature index effe1f13cb7..0f9e7517b93 100644 --- a/grade/tests/behat/grade_async_regrade.feature +++ b/grade/tests/behat/grade_async_regrade.feature @@ -100,7 +100,6 @@ Feature: Asynchronous regrade on a large course Scenario: Task indicator progresses and redirects when the task is run. When I am on the "Test course 1" "grades > Grader report > View" page logged in as teacher1 And I should see "The report will update automatically. You don't need to do anything." - And I should not see "Run now" And I should not see "0.0%" And "user-grades" "table" should not exist And I run all adhoc tasks @@ -113,12 +112,6 @@ Feature: Asynchronous regrade on a large course And "user-grades" "table" should exist And "40.00" "text" should exist in the "student1@example.com" "table_row" - Scenario: Admin should see a "Run now" button in the task indicator - When I am on the "Test course 1" "grades > Grader report > View" page logged in as admin - And I should see "The report will update automatically. You don't need to do anything." - And I should not see "0.0%" - And I should see "Run now" - Scenario: Making changes on course with less than 100 grades performs the regrade synchronously, no indicator is shown. Given I am on the "Test assignment 2" "assign activity editing" page logged in as teacher1 And I expand all fieldsets diff --git a/lib/classes/output/task_indicator.php b/lib/classes/output/task_indicator.php index 2bf4a1914bc..fd7d6585830 100644 --- a/lib/classes/output/task_indicator.php +++ b/lib/classes/output/task_indicator.php @@ -98,6 +98,7 @@ class task_indicator implements renderable, templatable { if ( array_key_exists('task', plugin_manager::instance()->get_present_plugins('tool')) && is_null($this->taskrecord->timestarted) + && \core\task\manager::is_runnable() && has_capability('moodle/site:config', system::instance()) ) { $this->runurl = new url('/admin/tool/task/run_adhoctasks.php', ['id' => $this->taskrecord->id]); @@ -124,13 +125,15 @@ class task_indicator implements renderable, templatable { if ($this->taskrecord) { $export['heading'] = $this->heading; $export['message'] = $this->message; - $export['progress'] = $this->progressbar->export_for_template($output); $export['icon'] = $this->icon ? $this->icon->export_for_template($output) : ''; $export['redirecturl'] = $this->redirecturl?->out(); $export['extraclasses'] = implode(' ', $this->extraclasses); $export['runurl'] = $this->runurl?->out(); $export['runlabel'] = $this->runlabel; - $this->progressbar->init_js(); + if ($this->progressbar !== null) { + $export['progress'] = $this->progressbar->export_for_template($output); + $this->progressbar->init_js(); + } } return $export; } diff --git a/lib/templates/task_indicator.mustache b/lib/templates/task_indicator.mustache index c399300bffa..07922841e95 100644 --- a/lib/templates/task_indicator.mustache +++ b/lib/templates/task_indicator.mustache @@ -49,12 +49,12 @@

{{heading}}

{{message}}

- {{#runurl}} -

- {{runlabel}} -

- {{/runurl}} {{#progress}} + {{#runurl}} +

+ {{runlabel}} +

+ {{/runurl}} {{>core/progress_bar}} {{/progress}}