Skip to content

Commit

Permalink
MDL-84072 output: correct progress bar component percentage parameter.
Browse files Browse the repository at this point in the history
Avoid mixing float/string types, where the decimal separator could
vary according to current locale (as per previous fix 5a1aef5, which
was subsequently re-broken by b92886a).
  • Loading branch information
paulholden committed Jan 7, 2025
1 parent c58bc49 commit 7a42c2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/classes/output/progress_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/output/stored_progress_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
Expand Down

0 comments on commit 7a42c2e

Please sign in to comment.