mirror of
				https://github.com/getgrav/grav-plugin-admin.git
				synced 2025-10-31 02:16:26 +01:00 
			
		
		
		
	fixes for restore
This commit is contained in:
		| @@ -696,6 +696,11 @@ class SafeUpgradeManager | |||||||
|      */ |      */ | ||||||
|     public function run(array $options = []): array |     public function run(array $options = []): array | ||||||
|     { |     { | ||||||
|  |         $operation = isset($options['operation']) ? (string)$options['operation'] : 'upgrade'; | ||||||
|  |         if ($operation === 'restore') { | ||||||
|  |             return $this->runRestore($options); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         $force = (bool)($options['force'] ?? false); |         $force = (bool)($options['force'] ?? false); | ||||||
|         $timeout = (int)($options['timeout'] ?? 30); |         $timeout = (int)($options['timeout'] ?? 30); | ||||||
|         $overwrite = (bool)($options['overwrite'] ?? false); |         $overwrite = (bool)($options['overwrite'] ?? false); | ||||||
| @@ -852,7 +857,7 @@ class SafeUpgradeManager | |||||||
|             return $this->errorResult('Snapshot identifier is required.', ['operation' => 'restore']); |             return $this->errorResult('Snapshot identifier is required.', ['operation' => 'restore']); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $this->setProgress('restoring', sprintf('Restoring snapshot %s...', $snapshotId), null, [ |         $this->setProgress('rollback', sprintf('Restoring snapshot %s...', $snapshotId), null, [ | ||||||
|             'operation' => 'restore', |             'operation' => 'restore', | ||||||
|             'snapshot' => $snapshotId, |             'snapshot' => $snapshotId, | ||||||
|         ]); |         ]); | ||||||
|   | |||||||
| @@ -533,9 +533,12 @@ PLUGIN_ADMIN: | |||||||
|   SAFE_UPGRADE_BLOCKERS_DESC: "Resolve the following items to enable the upgrade." |   SAFE_UPGRADE_BLOCKERS_DESC: "Resolve the following items to enable the upgrade." | ||||||
|   SAFE_UPGRADE_START: "Start Safe Upgrade" |   SAFE_UPGRADE_START: "Start Safe Upgrade" | ||||||
|   SAFE_UPGRADE_FINISH: "Finish" |   SAFE_UPGRADE_FINISH: "Finish" | ||||||
|  |   SAFE_UPGRADE_STAGE_QUEUED: "Waiting for worker" | ||||||
|   SAFE_UPGRADE_STAGE_INITIALIZING: "Preparing upgrade" |   SAFE_UPGRADE_STAGE_INITIALIZING: "Preparing upgrade" | ||||||
|   SAFE_UPGRADE_STAGE_DOWNLOADING: "Downloading update" |   SAFE_UPGRADE_STAGE_DOWNLOADING: "Downloading update" | ||||||
|  |   SAFE_UPGRADE_STAGE_SNAPSHOT: "Creating backup snapshot" | ||||||
|   SAFE_UPGRADE_STAGE_INSTALLING: "Installing update" |   SAFE_UPGRADE_STAGE_INSTALLING: "Installing update" | ||||||
|  |   SAFE_UPGRADE_STAGE_ROLLBACK: "Restoring snapshot" | ||||||
|   SAFE_UPGRADE_STAGE_FINALIZING: "Finalizing changes" |   SAFE_UPGRADE_STAGE_FINALIZING: "Finalizing changes" | ||||||
|   SAFE_UPGRADE_STAGE_COMPLETE: "Upgrade complete" |   SAFE_UPGRADE_STAGE_COMPLETE: "Upgrade complete" | ||||||
|   SAFE_UPGRADE_STAGE_ERROR: "Upgrade encountered an error" |   SAFE_UPGRADE_STAGE_ERROR: "Upgrade encountered an error" | ||||||
|   | |||||||
| @@ -24,7 +24,9 @@ const STAGE_TITLES = { | |||||||
|     queued: () => t('SAFE_UPGRADE_STAGE_QUEUED', 'Waiting for worker'), |     queued: () => t('SAFE_UPGRADE_STAGE_QUEUED', 'Waiting for worker'), | ||||||
|     initializing: () => t('SAFE_UPGRADE_STAGE_INITIALIZING', 'Preparing upgrade'), |     initializing: () => t('SAFE_UPGRADE_STAGE_INITIALIZING', 'Preparing upgrade'), | ||||||
|     downloading: () => t('SAFE_UPGRADE_STAGE_DOWNLOADING', 'Downloading update'), |     downloading: () => t('SAFE_UPGRADE_STAGE_DOWNLOADING', 'Downloading update'), | ||||||
|  |     snapshot: () => t('SAFE_UPGRADE_STAGE_SNAPSHOT', 'Creating backup snapshot'), | ||||||
|     installing: () => t('SAFE_UPGRADE_STAGE_INSTALLING', 'Installing update'), |     installing: () => t('SAFE_UPGRADE_STAGE_INSTALLING', 'Installing update'), | ||||||
|  |     rollback: () => t('SAFE_UPGRADE_STAGE_ROLLBACK', 'Restoring snapshot'), | ||||||
|     finalizing: () => t('SAFE_UPGRADE_STAGE_FINALIZING', 'Finalizing changes'), |     finalizing: () => t('SAFE_UPGRADE_STAGE_FINALIZING', 'Finalizing changes'), | ||||||
|     complete: () => t('SAFE_UPGRADE_STAGE_COMPLETE', 'Upgrade complete'), |     complete: () => t('SAFE_UPGRADE_STAGE_COMPLETE', 'Upgrade complete'), | ||||||
|     error: () => t('SAFE_UPGRADE_STAGE_ERROR', 'Upgrade encountered an error') |     error: () => t('SAFE_UPGRADE_STAGE_ERROR', 'Upgrade encountered an error') | ||||||
| @@ -806,9 +808,15 @@ export default class SafeUpgrade { | |||||||
|                 } |                 } | ||||||
|                 return 12; |                 return 12; | ||||||
|             } |             } | ||||||
|  |             if (stage === 'snapshot') { | ||||||
|  |                 return this.computeSmoothPercent(20, 45, 8, percent); | ||||||
|  |             } | ||||||
|             if (stage === 'installing') { |             if (stage === 'installing') { | ||||||
|                 return this.computeSmoothPercent(20, 90, 28, percent); |                 return this.computeSmoothPercent(20, 90, 28, percent); | ||||||
|             } |             } | ||||||
|  |             if (stage === 'rollback') { | ||||||
|  |                 return this.computeSmoothPercent(40, 95, 20, percent); | ||||||
|  |             } | ||||||
|             if (stage === 'finalizing') { |             if (stage === 'finalizing') { | ||||||
|                 return this.computeSmoothPercent(90, 99, 6, percent); |                 return this.computeSmoothPercent(90, 99, 6, percent); | ||||||
|             } |             } | ||||||
| @@ -821,12 +829,29 @@ export default class SafeUpgrade { | |||||||
|         const displayPercent = percent !== null ? Math.round(percent) : null; |         const displayPercent = percent !== null ? Math.round(percent) : null; | ||||||
|         const percentLabel = displayPercent !== null ? `${displayPercent}%` : ''; |         const percentLabel = displayPercent !== null ? `${displayPercent}%` : ''; | ||||||
|  |  | ||||||
|  |         const message = typeof data.message === 'string' ? data.message : ''; | ||||||
|  |         const normalize = (value) => value | ||||||
|  |             .replace(/\u2026/g, '...') | ||||||
|  |             .replace(/\.+$/, '') | ||||||
|  |             .trim() | ||||||
|  |             .toLowerCase(); | ||||||
|  |         const normalizedTitle = normalize(title || ''); | ||||||
|  |         const normalizedMessage = normalize(message || ''); | ||||||
|  |  | ||||||
|  |         const shouldShowMessage = stage === 'error' | ||||||
|  |             ? message.trim().length > 0 | ||||||
|  |             : ( | ||||||
|  |                 message && | ||||||
|  |                 stage !== 'installing' && | ||||||
|  |                 stage !== 'finalizing' && | ||||||
|  |                 normalizedMessage !== '' && | ||||||
|  |                 normalizedMessage !== normalizedTitle | ||||||
|  |             ); | ||||||
|  |  | ||||||
|         const statusLine = job && job.status ? `<p class="safe-upgrade-status">${t('SAFE_UPGRADE_JOB_STATUS', 'Status')}: <strong>${job.status.toUpperCase()}</strong>${job.error ? ` — ${job.error}` : ''}</p>` : ''; |         const statusLine = job && job.status ? `<p class="safe-upgrade-status">${t('SAFE_UPGRADE_JOB_STATUS', 'Status')}: <strong>${job.status.toUpperCase()}</strong>${job.error ? ` — ${job.error}` : ''}</p>` : ''; | ||||||
|         const animateBar = stage !== 'complete' && stage !== 'error' && percent !== null; |         const animateBar = stage !== 'complete' && stage !== 'error' && percent !== null; | ||||||
|         const barClass = `safe-upgrade-progress-bar${animateBar ? ' is-active' : ''}`; |         const barClass = `safe-upgrade-progress-bar${animateBar ? ' is-active' : ''}`; | ||||||
|         const detailMessage = stage === 'error' |         const detailMessage = shouldShowMessage ? `<p>${message}</p>` : ''; | ||||||
|             ? `<p>${data.message || ''}</p>` |  | ||||||
|             : (data.message && stage !== 'installing' && stage !== 'finalizing' ? `<p>${data.message}</p>` : ''); |  | ||||||
|  |  | ||||||
|         this.steps.progress.html(` |         this.steps.progress.html(` | ||||||
|             <div class="safe-upgrade-progress"> |             <div class="safe-upgrade-progress"> | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								themes/grav/js/admin.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								themes/grav/js/admin.min.js
									
									
									
									
										vendored
									
									
								
							| @@ -2228,9 +2228,15 @@ var STAGE_TITLES = { | |||||||
|   downloading: function downloading() { |   downloading: function downloading() { | ||||||
|     return t('SAFE_UPGRADE_STAGE_DOWNLOADING', 'Downloading update'); |     return t('SAFE_UPGRADE_STAGE_DOWNLOADING', 'Downloading update'); | ||||||
|   }, |   }, | ||||||
|  |   snapshot: function snapshot() { | ||||||
|  |     return t('SAFE_UPGRADE_STAGE_SNAPSHOT', 'Creating backup snapshot'); | ||||||
|  |   }, | ||||||
|   installing: function installing() { |   installing: function installing() { | ||||||
|     return t('SAFE_UPGRADE_STAGE_INSTALLING', 'Installing update'); |     return t('SAFE_UPGRADE_STAGE_INSTALLING', 'Installing update'); | ||||||
|   }, |   }, | ||||||
|  |   rollback: function rollback() { | ||||||
|  |     return t('SAFE_UPGRADE_STAGE_ROLLBACK', 'Restoring snapshot'); | ||||||
|  |   }, | ||||||
|   finalizing: function finalizing() { |   finalizing: function finalizing() { | ||||||
|     return t('SAFE_UPGRADE_STAGE_FINALIZING', 'Finalizing changes'); |     return t('SAFE_UPGRADE_STAGE_FINALIZING', 'Finalizing changes'); | ||||||
|   }, |   }, | ||||||
| @@ -2861,9 +2867,15 @@ var SafeUpgrade = /*#__PURE__*/function () { | |||||||
|           } |           } | ||||||
|           return 12; |           return 12; | ||||||
|         } |         } | ||||||
|  |         if (stage === 'snapshot') { | ||||||
|  |           return _this7.computeSmoothPercent(20, 45, 8, percent); | ||||||
|  |         } | ||||||
|         if (stage === 'installing') { |         if (stage === 'installing') { | ||||||
|           return _this7.computeSmoothPercent(20, 90, 28, percent); |           return _this7.computeSmoothPercent(20, 90, 28, percent); | ||||||
|         } |         } | ||||||
|  |         if (stage === 'rollback') { | ||||||
|  |           return _this7.computeSmoothPercent(40, 95, 20, percent); | ||||||
|  |         } | ||||||
|         if (stage === 'finalizing') { |         if (stage === 'finalizing') { | ||||||
|           return _this7.computeSmoothPercent(90, 99, 6, percent); |           return _this7.computeSmoothPercent(90, 99, 6, percent); | ||||||
|         } |         } | ||||||
| @@ -2878,10 +2890,17 @@ var SafeUpgrade = /*#__PURE__*/function () { | |||||||
|       percent = scaledPercent(); |       percent = scaledPercent(); | ||||||
|       var displayPercent = percent !== null ? Math.round(percent) : null; |       var displayPercent = percent !== null ? Math.round(percent) : null; | ||||||
|       var percentLabel = displayPercent !== null ? "".concat(displayPercent, "%") : ''; |       var percentLabel = displayPercent !== null ? "".concat(displayPercent, "%") : ''; | ||||||
|  |       var message = typeof data.message === 'string' ? data.message : ''; | ||||||
|  |       var normalize = function normalize(value) { | ||||||
|  |         return value.replace(/\u2026/g, '...').replace(/\.+$/, '').trim().toLowerCase(); | ||||||
|  |       }; | ||||||
|  |       var normalizedTitle = normalize(title || ''); | ||||||
|  |       var normalizedMessage = normalize(message || ''); | ||||||
|  |       var shouldShowMessage = stage === 'error' ? message.trim().length > 0 : message && stage !== 'installing' && stage !== 'finalizing' && normalizedMessage !== '' && normalizedMessage !== normalizedTitle; | ||||||
|       var statusLine = job && job.status ? "<p class=\"safe-upgrade-status\">".concat(t('SAFE_UPGRADE_JOB_STATUS', 'Status'), ": <strong>").concat(job.status.toUpperCase(), "</strong>").concat(job.error ? " — ".concat(job.error) : '', "</p>") : ''; |       var statusLine = job && job.status ? "<p class=\"safe-upgrade-status\">".concat(t('SAFE_UPGRADE_JOB_STATUS', 'Status'), ": <strong>").concat(job.status.toUpperCase(), "</strong>").concat(job.error ? " — ".concat(job.error) : '', "</p>") : ''; | ||||||
|       var animateBar = stage !== 'complete' && stage !== 'error' && percent !== null; |       var animateBar = stage !== 'complete' && stage !== 'error' && percent !== null; | ||||||
|       var barClass = "safe-upgrade-progress-bar".concat(animateBar ? ' is-active' : ''); |       var barClass = "safe-upgrade-progress-bar".concat(animateBar ? ' is-active' : ''); | ||||||
|       var detailMessage = stage === 'error' ? "<p>".concat(data.message || '', "</p>") : data.message && stage !== 'installing' && stage !== 'finalizing' ? "<p>".concat(data.message, "</p>") : ''; |       var detailMessage = shouldShowMessage ? "<p>".concat(message, "</p>") : ''; | ||||||
|       this.steps.progress.html("\n            <div class=\"safe-upgrade-progress\">\n                <h3>".concat(title, "</h3>\n                ").concat(detailMessage, "\n                ").concat(statusLine, "\n                ").concat(percentLabel ? "<div class=\"".concat(barClass, "\"><span style=\"width:").concat(percent, "%\"></span></div><div class=\"progress-value\">").concat(percentLabel, "</div>") : '', "\n            </div>\n        ")); |       this.steps.progress.html("\n            <div class=\"safe-upgrade-progress\">\n                <h3>".concat(title, "</h3>\n                ").concat(detailMessage, "\n                ").concat(statusLine, "\n                ").concat(percentLabel ? "<div class=\"".concat(barClass, "\"><span style=\"width:").concat(percent, "%\"></span></div><div class=\"progress-value\">").concat(percentLabel, "</div>") : '', "\n            </div>\n        ")); | ||||||
|       this.switchStep('progress'); |       this.switchStep('progress'); | ||||||
|       if (stage === 'complete') { |       if (stage === 'complete') { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user