mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-26 00:36:31 +02: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) {
|
||||
|
||||
47
themes/grav/js/admin.min.js
vendored
47
themes/grav/js/admin.min.js
vendored
@@ -4605,6 +4605,7 @@ var SafeUpgrade = /*#__PURE__*/function () {
|
||||
this.statusRequest = null;
|
||||
this.isPolling = false;
|
||||
this.active = false;
|
||||
this.progressFile = "".concat(external_GravAdmin_namespaceObject.config.base_url_relative, "/user/data/upgrades/safe-upgrade-progress.json");
|
||||
this.registerEvents();
|
||||
}
|
||||
return safe_upgrade_createClass(SafeUpgrade, [{
|
||||
@@ -4857,7 +4858,7 @@ var SafeUpgrade = /*#__PURE__*/function () {
|
||||
manifest: data.manifest || null
|
||||
});
|
||||
});
|
||||
this.beginPolling(800);
|
||||
this.beginPolling(1200);
|
||||
}
|
||||
}, {
|
||||
key: "beginPolling",
|
||||
@@ -4901,28 +4902,37 @@ var SafeUpgrade = /*#__PURE__*/function () {
|
||||
this.pollTimer = null;
|
||||
var nextStage = null;
|
||||
var shouldContinue = true;
|
||||
console.debug('[SafeUpgrade] poll status');
|
||||
this.statusRequest = utils_request(this.urls.status, function (response) {
|
||||
console.debug('[SafeUpgrade] status response', response);
|
||||
if (response.status === 'error') {
|
||||
if (!silent) {
|
||||
_this6.renderProgress({
|
||||
stage: 'error',
|
||||
message: response.message || t('SAFE_UPGRADE_GENERIC_ERROR', 'Safe upgrade could not complete. See Grav logs for details.'),
|
||||
percent: null
|
||||
});
|
||||
}
|
||||
nextStage = 'error';
|
||||
return;
|
||||
console.debug('[SafeUpgrade] poll status file');
|
||||
var url = "".concat(this.progressFile, "?_=").concat(Date.now());
|
||||
this.statusRequest = fetch(url, {
|
||||
credentials: 'same-origin',
|
||||
cache: 'no-store',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
var data = response.data || {};
|
||||
}).then(function (resp) {
|
||||
if (!resp.ok) {
|
||||
throw new Error("HTTP ".concat(resp.status));
|
||||
}
|
||||
return resp.json();
|
||||
}).then(function (data) {
|
||||
nextStage = data.stage || null;
|
||||
console.debug('[SafeUpgrade] status data', data);
|
||||
_this6.renderProgress(data);
|
||||
if (nextStage === 'installing' || nextStage === 'finalizing' || nextStage === 'complete') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
});
|
||||
var finalize = function finalize() {
|
||||
})["catch"](function (err) {
|
||||
console.warn('[SafeUpgrade] status fetch failed', err);
|
||||
nextStage = 'error';
|
||||
if (!silent) {
|
||||
_this6.renderProgress({
|
||||
stage: 'error',
|
||||
message: err.message || t('SAFE_UPGRADE_GENERIC_ERROR', 'Safe upgrade could not complete. See Grav logs for details.'),
|
||||
percent: null
|
||||
});
|
||||
}
|
||||
})["finally"](function () {
|
||||
_this6.statusRequest = null;
|
||||
if (!_this6.isPolling) {
|
||||
return;
|
||||
@@ -4934,8 +4944,7 @@ var SafeUpgrade = /*#__PURE__*/function () {
|
||||
} else {
|
||||
_this6.stopPolling();
|
||||
}
|
||||
};
|
||||
this.statusRequest.then(finalize, finalize);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "renderProgress",
|
||||
|
||||
Reference in New Issue
Block a user