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).
This commit is contained in:
Paul Holden 2025-01-07 13:13:42 +00:00
parent ab5692acdf
commit a296bdfc5b
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
3 changed files with 10 additions and 4 deletions

View File

@ -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,
]));
}
/**

View File

@ -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();
}
}

View File

@ -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)
);
}
}