mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-26 07:46:31 +01:00
yet more upgrade flow fixes 2
This commit is contained in:
@@ -51,6 +51,7 @@ export default class SafeUpgrade {
|
||||
this.statusRequest = null;
|
||||
this.isPolling = false;
|
||||
this.active = false;
|
||||
this.progressFile = `${config.base_url_relative}/user/data/upgrades/safe-upgrade-progress.json`;
|
||||
|
||||
this.registerEvents();
|
||||
}
|
||||
@@ -392,7 +393,7 @@ export default class SafeUpgrade {
|
||||
});
|
||||
});
|
||||
|
||||
this.beginPolling(800);
|
||||
this.beginPolling(1200);
|
||||
}
|
||||
|
||||
beginPolling(delay = 1200) {
|
||||
@@ -430,49 +431,59 @@ export default class SafeUpgrade {
|
||||
|
||||
let shouldContinue = true;
|
||||
|
||||
console.debug('[SafeUpgrade] poll status');
|
||||
console.debug('[SafeUpgrade] poll status file');
|
||||
|
||||
this.statusRequest = request(this.urls.status, (response) => {
|
||||
console.debug('[SafeUpgrade] status response', response);
|
||||
const url = `${this.progressFile}?_=${Date.now()}`;
|
||||
|
||||
if (response.status === 'error') {
|
||||
this.statusRequest = fetch(url, {
|
||||
credentials: 'same-origin',
|
||||
cache: 'no-store',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
})
|
||||
.then((resp) => {
|
||||
if (!resp.ok) {
|
||||
throw new Error(`HTTP ${resp.status}`);
|
||||
}
|
||||
|
||||
return resp.json();
|
||||
})
|
||||
.then((data) => {
|
||||
nextStage = data.stage || null;
|
||||
console.debug('[SafeUpgrade] status data', data);
|
||||
this.renderProgress(data);
|
||||
|
||||
if (nextStage === 'installing' || nextStage === 'finalizing' || nextStage === 'complete') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('[SafeUpgrade] status fetch failed', err);
|
||||
nextStage = 'error';
|
||||
if (!silent) {
|
||||
this.renderProgress({
|
||||
stage: 'error',
|
||||
message: response.message || t('SAFE_UPGRADE_GENERIC_ERROR', 'Safe upgrade could not complete. See Grav logs for details.'),
|
||||
message: err.message || t('SAFE_UPGRADE_GENERIC_ERROR', 'Safe upgrade could not complete. See Grav logs for details.'),
|
||||
percent: null
|
||||
});
|
||||
}
|
||||
nextStage = 'error';
|
||||
return;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.statusRequest = null;
|
||||
|
||||
const data = response.data || {};
|
||||
nextStage = data.stage || null;
|
||||
this.renderProgress(data);
|
||||
if (!this.isPolling) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextStage === 'installing' || nextStage === 'finalizing' || nextStage === 'complete') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
});
|
||||
|
||||
const finalize = () => {
|
||||
this.statusRequest = null;
|
||||
|
||||
if (!this.isPolling) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextStage === 'complete' || nextStage === 'error') {
|
||||
this.stopPolling();
|
||||
} else if (shouldContinue) {
|
||||
this.schedulePoll();
|
||||
} else {
|
||||
this.stopPolling();
|
||||
}
|
||||
};
|
||||
|
||||
this.statusRequest.then(finalize, finalize);
|
||||
if (nextStage === 'complete' || nextStage === 'error') {
|
||||
this.stopPolling();
|
||||
} else if (shouldContinue) {
|
||||
this.schedulePoll();
|
||||
} else {
|
||||
this.stopPolling();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
renderProgress(data) {
|
||||
|
||||
Reference in New Issue
Block a user