From 7a42c2e37a231a44e708ca59474565bb1329912b 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 2792c4774ce21..1409906f4c7d8 100644 --- a/lib/classes/output/core_renderer.php +++ b/lib/classes/output/core_renderer.php @@ -4765,7 +4765,13 @@ public function render_progress_bar(progress_bar $bar) { */ 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 cbb697dbf6056..ddb8b6180add6 100644 --- a/lib/classes/output/progress_bar.php +++ b/lib/classes/output/progress_bar.php @@ -181,7 +181,7 @@ protected function update_raw($percent, $msg) { $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 @@ public function error(string $errormsg): void { $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 37d5be6a007fd..41fd66c0c32f4 100644 --- a/lib/classes/output/stored_progress_bar.php +++ b/lib/classes/output/stored_progress_bar.php @@ -299,7 +299,7 @@ protected function render_update(): void { // 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) ); } }