From e81ed34dd6913d00c2d96decc5a93af24ee54587 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sat, 18 Oct 2025 19:10:42 -0600 Subject: [PATCH] fix labels in snapshots --- classes/plugin/SafeUpgradeManager.php | 3 +- themes/grav/app/tools/restore.js | 31 ++++++++++---- themes/grav/js/admin.min.js | 41 +++++++++++++------ .../partials/tools-restore-grav.html.twig | 9 +++- 4 files changed, 63 insertions(+), 21 deletions(-) diff --git a/classes/plugin/SafeUpgradeManager.php b/classes/plugin/SafeUpgradeManager.php index fdf8448b..44eca271 100644 --- a/classes/plugin/SafeUpgradeManager.php +++ b/classes/plugin/SafeUpgradeManager.php @@ -121,7 +121,7 @@ class SafeUpgradeManager } /** - * @return array + * @return array */ public function listSnapshots(): array { @@ -144,6 +144,7 @@ class SafeUpgradeManager $snapshots[] = [ 'id' => (string)$decoded['id'], + 'label' => isset($decoded['label']) && $decoded['label'] !== '' ? (string)$decoded['label'] : null, 'source_version' => $decoded['source_version'] ?? null, 'target_version' => $decoded['target_version'] ?? null, 'created_at' => $createdAt, diff --git a/themes/grav/app/tools/restore.js b/themes/grav/app/tools/restore.js index 08992c86..0d4a29c0 100644 --- a/themes/grav/app/tools/restore.js +++ b/themes/grav/app/tools/restore.js @@ -186,6 +186,12 @@ class RestoreManager { this.job.snapshot = job.result.snapshot; } + if (!this.job.label && progress.label) { + this.job.label = progress.label; + } else if (!this.job.label && job.result && job.result.label) { + this.job.label = job.result.label; + } + if (stage === 'error' || status === 'error') { const message = job.error || progress.message || (operation === 'snapshot' ? translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FAILED || 'Snapshot creation failed.' @@ -199,10 +205,14 @@ class RestoreManager { if (stage === 'complete' || status === 'success') { if (operation === 'snapshot') { const snapshotId = progress.snapshot || (job.result && job.result.snapshot) || this.job.snapshot || ''; - const snapshotLabel = snapshotId || (translations.PLUGIN_ADMIN?.RESTORE_GRAV_TABLE_SNAPSHOT || 'snapshot'); + const labelValue = progress.label || (job.result && job.result.label) || this.job.label || ''; + let displayName = labelValue || snapshotId || (translations.PLUGIN_ADMIN?.RESTORE_GRAV_TABLE_SNAPSHOT || 'snapshot'); + if (labelValue && snapshotId && labelValue !== snapshotId) { + displayName = `${labelValue} (${snapshotId})`; + } const successMessage = translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_SUCCESS - ? translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', snapshotLabel) - : (snapshotId ? `Snapshot ${snapshotId} created.` : 'Snapshot created.'); + ? translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', displayName) + : (snapshotId ? `Snapshot ${displayName} created.` : 'Snapshot created.'); toastr.success(successMessage); this.job = null; this.clearPoll(); @@ -210,15 +220,22 @@ class RestoreManager { return; } - const snapshot = progress.snapshot || this.job.snapshot; + const snapshotId = progress.snapshot || this.job.snapshot || ''; + const labelValue = progress.label || (job.result && job.result.label) || this.job.label || ''; + let snapshotDisplay = snapshotId || labelValue; + if (labelValue && snapshotId && labelValue !== snapshotId) { + snapshotDisplay = `${labelValue} (${snapshotId})`; + } else if (!snapshotDisplay) { + snapshotDisplay = translations.PLUGIN_ADMIN?.RESTORE_GRAV_TABLE_SNAPSHOT || 'snapshot'; + } const version = (job.result && job.result.version) || progress.version || ''; let successMessage; if (translations.PLUGIN_ADMIN?.RESTORE_GRAV_SUCCESS_MESSAGE && version) { - successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshot).replace('%2$s', version); + successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshotDisplay).replace('%2$s', version); } else if (translations.PLUGIN_ADMIN?.RESTORE_GRAV_SUCCESS_SIMPLE) { - successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshot); + successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshotDisplay); } else { - successMessage = version ? `Snapshot ${snapshot} restored (Grav ${version}).` : `Snapshot ${snapshot} restored.`; + successMessage = version ? `Snapshot ${snapshotDisplay} restored (Grav ${version}).` : `Snapshot ${snapshotDisplay} restored.`; } toastr.success(successMessage); this.job = null; diff --git a/themes/grav/js/admin.min.js b/themes/grav/js/admin.min.js index 22682880..8f09643d 100644 --- a/themes/grav/js/admin.min.js +++ b/themes/grav/js/admin.min.js @@ -11160,6 +11160,11 @@ var RestoreManager = /*#__PURE__*/function () { } else if (!_this5.job.snapshot && job.result && job.result.snapshot) { _this5.job.snapshot = job.result.snapshot; } + if (!_this5.job.label && progress.label) { + _this5.job.label = progress.label; + } else if (!_this5.job.label && job.result && job.result.label) { + _this5.job.label = job.result.label; + } if (stage === 'error' || status === 'error') { var _translations$PLUGIN_0, _translations$PLUGIN_1; var message = job.error || progress.message || (operation === 'snapshot' ? ((_translations$PLUGIN_0 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_0 === void 0 ? void 0 : _translations$PLUGIN_0.RESTORE_GRAV_SNAPSHOT_FAILED) || 'Snapshot creation failed.' : ((_translations$PLUGIN_1 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_1 === void 0 ? void 0 : _translations$PLUGIN_1.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.'); @@ -11169,12 +11174,16 @@ var RestoreManager = /*#__PURE__*/function () { return; } if (stage === 'complete' || status === 'success') { - var _translations$PLUGIN_12, _translations$PLUGIN_13; + var _translations$PLUGIN_13, _translations$PLUGIN_14; if (operation === 'snapshot') { var _translations$PLUGIN_10, _translations$PLUGIN_11; - var snapshotId = progress.snapshot || job.result && job.result.snapshot || _this5.job.snapshot || ''; - var snapshotLabel = snapshotId || ((_translations$PLUGIN_10 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_10 === void 0 ? void 0 : _translations$PLUGIN_10.RESTORE_GRAV_TABLE_SNAPSHOT) || 'snapshot'; - var _successMessage = (_translations$PLUGIN_11 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_11 !== void 0 && _translations$PLUGIN_11.RESTORE_GRAV_SNAPSHOT_SUCCESS ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', snapshotLabel) : snapshotId ? "Snapshot ".concat(snapshotId, " created.") : 'Snapshot created.'; + var _snapshotId = progress.snapshot || job.result && job.result.snapshot || _this5.job.snapshot || ''; + var _labelValue = progress.label || job.result && job.result.label || _this5.job.label || ''; + var displayName = _labelValue || _snapshotId || ((_translations$PLUGIN_10 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_10 === void 0 ? void 0 : _translations$PLUGIN_10.RESTORE_GRAV_TABLE_SNAPSHOT) || 'snapshot'; + if (_labelValue && _snapshotId && _labelValue !== _snapshotId) { + displayName = "".concat(_labelValue, " (").concat(_snapshotId, ")"); + } + var _successMessage = (_translations$PLUGIN_11 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_11 !== void 0 && _translations$PLUGIN_11.RESTORE_GRAV_SNAPSHOT_SUCCESS ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', displayName) : _snapshotId ? "Snapshot ".concat(displayName, " created.") : 'Snapshot created.'; utils_toastr.success(_successMessage); _this5.job = null; _this5.clearPoll(); @@ -11183,15 +11192,23 @@ var RestoreManager = /*#__PURE__*/function () { }, 1500); return; } - var snapshot = progress.snapshot || _this5.job.snapshot; + var snapshotId = progress.snapshot || _this5.job.snapshot || ''; + var labelValue = progress.label || job.result && job.result.label || _this5.job.label || ''; + var snapshotDisplay = snapshotId || labelValue; + if (labelValue && snapshotId && labelValue !== snapshotId) { + snapshotDisplay = "".concat(labelValue, " (").concat(snapshotId, ")"); + } else if (!snapshotDisplay) { + var _translations$PLUGIN_12; + snapshotDisplay = ((_translations$PLUGIN_12 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_12 === void 0 ? void 0 : _translations$PLUGIN_12.RESTORE_GRAV_TABLE_SNAPSHOT) || 'snapshot'; + } var version = job.result && job.result.version || progress.version || ''; var successMessage; - if ((_translations$PLUGIN_12 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_12 !== void 0 && _translations$PLUGIN_12.RESTORE_GRAV_SUCCESS_MESSAGE && version) { - successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshot).replace('%2$s', version); - } else if ((_translations$PLUGIN_13 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_13 !== void 0 && _translations$PLUGIN_13.RESTORE_GRAV_SUCCESS_SIMPLE) { - successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshot); + if ((_translations$PLUGIN_13 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_13 !== void 0 && _translations$PLUGIN_13.RESTORE_GRAV_SUCCESS_MESSAGE && version) { + successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshotDisplay).replace('%2$s', version); + } else if ((_translations$PLUGIN_14 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_14 !== void 0 && _translations$PLUGIN_14.RESTORE_GRAV_SUCCESS_SIMPLE) { + successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshotDisplay); } else { - successMessage = version ? "Snapshot ".concat(snapshot, " restored (Grav ").concat(version, ").") : "Snapshot ".concat(snapshot, " restored."); + successMessage = version ? "Snapshot ".concat(snapshotDisplay, " restored (Grav ").concat(version, ").") : "Snapshot ".concat(snapshotDisplay, " restored."); } utils_toastr.success(successMessage); _this5.job = null; @@ -11220,8 +11237,8 @@ var RestoreManager = /*#__PURE__*/function () { if (this.pollFailures >= 3) { var message; if (operation === 'snapshot') { - var _translations$PLUGIN_14; - message = ((_translations$PLUGIN_14 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_14 === void 0 ? void 0 : _translations$PLUGIN_14.RESTORE_GRAV_SNAPSHOT_FALLBACK) || 'Snapshot creation may have completed. Reloading...'; + var _translations$PLUGIN_15; + message = ((_translations$PLUGIN_15 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_15 === void 0 ? void 0 : _translations$PLUGIN_15.RESTORE_GRAV_SNAPSHOT_FALLBACK) || 'Snapshot creation may have completed. Reloading...'; } else { message = snapshot ? "Snapshot ".concat(snapshot, " restore is completing. Reloading...") : 'Snapshot restore is completing. Reloading...'; } diff --git a/themes/grav/templates/partials/tools-restore-grav.html.twig b/themes/grav/templates/partials/tools-restore-grav.html.twig index b9136d49..4d302017 100644 --- a/themes/grav/templates/partials/tools-restore-grav.html.twig +++ b/themes/grav/templates/partials/tools-restore-grav.html.twig @@ -36,7 +36,14 @@ - {{ snapshot.id }} + + {% if snapshot.label %} + {{ snapshot.label }}
+ {{ snapshot.id }} + {% else %} + {{ snapshot.id }} + {% endif %} + {{ version ?: "PLUGIN_ADMIN.UNKNOWN"|t }} {% if snapshot.created_at %}