Skip to content

Commit 2c10c11

Browse files
committed
fix: improved last update step
1 parent 16b9ee4 commit 2c10c11

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

phpmyfaq/admin/assets/src/configuration/upgrade.ts

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,25 @@ const createTemporaryBackup = async (): Promise<void> => {
216216

217217
async function pump(): Promise<void> {
218218
const { done, value } = await reader.read();
219-
const decodedValue: string = new TextDecoder().decode(value);
220219

221220
if (done) {
222221
progressBarBackup!.style.width = '100%';
223222
progressBarBackup!.innerText = '100%';
224-
progressBarBackup!.classList.remove('progress-bar-animated');
223+
progressBarBackup!.classList.remove('progress-bar-animated', 'bg-primary');
224+
progressBarBackup!.classList.add('bg-success');
225225
return;
226-
} else {
227-
progressBarBackup!.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
228-
progressBarBackup!.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
226+
}
227+
228+
const decodedValue: string = new TextDecoder().decode(value);
229+
try {
230+
const data = JSON.parse(decodedValue);
231+
if (data.progress) {
232+
progressBarBackup!.style.width = data.progress;
233+
progressBarBackup!.innerText = data.progress;
234+
}
235+
} catch (e) {
236+
// Ignore JSON parse errors for incomplete chunks
237+
console.debug('JSON parse error:', e);
229238
}
230239

231240
return pump();
@@ -248,16 +257,25 @@ const installPackage = async (): Promise<void> => {
248257

249258
async function pump(): Promise<void> {
250259
const { done, value } = await reader.read();
251-
const decodedValue: string = new TextDecoder().decode(value);
252260

253261
if (done) {
254262
progressBarInstallation!.style.width = '100%';
255263
progressBarInstallation!.innerText = '100%';
256-
progressBarInstallation!.classList.remove('progress-bar-animated');
264+
progressBarInstallation!.classList.remove('progress-bar-animated', 'bg-primary');
265+
progressBarInstallation!.classList.add('bg-success');
257266
return;
258-
} else {
259-
progressBarInstallation!.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
260-
progressBarInstallation!.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
267+
}
268+
269+
const decodedValue: string = new TextDecoder().decode(value);
270+
try {
271+
const data = JSON.parse(decodedValue);
272+
if (data.progress) {
273+
progressBarInstallation!.style.width = data.progress;
274+
progressBarInstallation!.innerText = data.progress;
275+
}
276+
} catch (e) {
277+
// Ignore JSON parse errors for incomplete chunks
278+
console.debug('JSON parse error:', e);
261279
}
262280

263281
return pump();
@@ -281,17 +299,26 @@ const updateDatabase = async (): Promise<void> => {
281299

282300
async function pump(): Promise<void> {
283301
const { done, value } = await reader.read();
284-
const decodedValue: string = new TextDecoder().decode(value);
285302

286303
if (done) {
287304
progressBarInstallation!.style.width = '100%';
288305
progressBarInstallation!.innerText = '100%';
289-
progressBarInstallation!.classList.remove('progress-bar-animated');
306+
progressBarInstallation!.classList.remove('progress-bar-animated', 'bg-primary');
307+
progressBarInstallation!.classList.add('bg-success');
290308
card.classList.add('text-bg-success');
291309
return;
292-
} else {
293-
progressBarInstallation!.style.width = JSON.parse(JSON.stringify(decodedValue)).progress;
294-
progressBarInstallation!.innerText = JSON.parse(JSON.stringify(decodedValue)).progress;
310+
}
311+
312+
const decodedValue: string = new TextDecoder().decode(value);
313+
try {
314+
const data = JSON.parse(decodedValue);
315+
if (data.progress) {
316+
progressBarInstallation!.style.width = data.progress;
317+
progressBarInstallation!.innerText = data.progress;
318+
}
319+
} catch (e) {
320+
// Ignore JSON parse errors for incomplete chunks
321+
console.debug('JSON parse error:', e);
295322
}
296323

297324
return pump();

phpmyfaq/assets/templates/admin/configuration/upgrade.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,19 @@
150150
</div>
151151
<div class="w-25">
152152
<div class="progress w-100 mt-1 mb-2" role="progressbar">
153-
<div class="progress-bar progress-bar-striped progress-bar-animated"
153+
<div class="progress-bar progress-bar-striped progress-bar-animated bg-primary"
154154
id="result-backup-package" style="width: 0">
155155
0%
156156
</div>
157157
</div>
158158
<div class="progress w-100 mt-1 mb-2" role="progressbar">
159-
<div class="progress-bar progress-bar-striped progress-bar-animated"
159+
<div class="progress-bar progress-bar-striped progress-bar-animated bg-primary"
160160
id="result-install-package" style="width: 0">
161161
0%
162162
</div>
163163
</div>
164164
<div class="progress w-100 mt-1 mb-2" role="progressbar">
165-
<div class="progress-bar progress-bar-striped progress-bar-animated"
165+
<div class="progress-bar progress-bar-striped progress-bar-animated bg-primary"
166166
id="result-update-database" style="width: 0">
167167
0%
168168
</div>

0 commit comments

Comments
 (0)