From a296bdfc5b68d3e2cd0fddf51b49bb1b95d2f878 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 7 Jan 2025 13:13:42 +0000 Subject: [PATCH] MDL-84072 output: correct progress bar component percentage parameter. Avoid mixing float/string types, where the decimal separator could vary according to current locale (as per previous fix 5a1aef5a, which was subsequently re-broken by b92886ad). --- lib/classes/output/core_renderer.php | 8 +++++++- lib/classes/output/progress_bar.php | 4 ++-- lib/classes/output/stored_progress_bar.php | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/classes/output/core_renderer.php b/lib/classes/output/core_renderer.php index b8535061ffc..ca2f8d18c47 100644 --- a/lib/classes/output/core_renderer.php +++ b/lib/classes/output/core_renderer.php @@ -4797,7 +4797,13 @@ EOD; */ public function render_progress_bar_update(string $id, float $percent, string $msg, string $estimate, bool $error = false): string { - return html_writer::script(js_writer::function_call('updateProgressBar', [$id, $percent, $msg, $estimate, $error])); + return html_writer::script(js_writer::function_call('updateProgressBar', [ + $id, + round($percent, 1), + $msg, + $estimate, + $error, + ])); } /** diff --git a/lib/classes/output/progress_bar.php b/lib/classes/output/progress_bar.php index cbb697dbf60..ddb8b6180ad 100644 --- a/lib/classes/output/progress_bar.php +++ b/lib/classes/output/progress_bar.php @@ -181,7 +181,7 @@ class progress_bar implements renderable, templatable { $this->lastupdate = microtime(true); if ($this->autoupdate) { - echo $OUTPUT->render_progress_bar_update($this->idnumber, sprintf("%.1f", $this->percent), $msg, $estimatemsg); + echo $OUTPUT->render_progress_bar_update($this->idnumber, $this->percent, $msg, $estimatemsg); flush(); } } @@ -307,7 +307,7 @@ class progress_bar implements renderable, templatable { $this->message = $errormsg; if ($this->autoupdate) { - echo $OUTPUT->render_progress_bar_update($this->idnumber, sprintf("%.1f", $this->percent), $errormsg, '', true); + echo $OUTPUT->render_progress_bar_update($this->idnumber, $this->percent, $errormsg, '', true); flush(); } } diff --git a/lib/classes/output/stored_progress_bar.php b/lib/classes/output/stored_progress_bar.php index 37d5be6a007..41fd66c0c32 100644 --- a/lib/classes/output/stored_progress_bar.php +++ b/lib/classes/output/stored_progress_bar.php @@ -299,7 +299,7 @@ class stored_progress_bar extends progress_bar { // If we want the screen to auto update, render it. if ($this->autoupdate) { echo $OUTPUT->render_progress_bar_update( - $this->idnumber, sprintf("%.1f", $this->percent), $this->message, $this->get_estimate_message($this->percent) + $this->idnumber, $this->percent, $this->message, $this->get_estimate_message($this->percent) ); } }