mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-02 11:26:04 +01:00
create adhoc snapshot
This commit is contained in:
@@ -981,6 +981,45 @@ class AdminController extends AdminBaseController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a manual safe-upgrade snapshot via Tools.
|
||||||
|
*
|
||||||
|
* Route: POST /tools/restore-grav?task:safeUpgradeSnapshot
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function taskSafeUpgradeSnapshot()
|
||||||
|
{
|
||||||
|
if (!$this->authorizeTask('install grav', ['admin.super'])) {
|
||||||
|
$this->sendJsonResponse([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => $this->admin::translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')
|
||||||
|
]);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = $this->getPost($_POST ?? []);
|
||||||
|
$label = isset($post['label']) ? (string)$post['label'] : null;
|
||||||
|
|
||||||
|
$manager = $this->getSafeUpgradeManager();
|
||||||
|
$result = $manager->queueSnapshot($label);
|
||||||
|
$status = $result['status'] ?? 'error';
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'status' => $status === 'error' ? 'error' : 'success',
|
||||||
|
'data' => $result,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($result['message'])) {
|
||||||
|
$response['message'] = $result['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sendJsonResponse($response);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete one or more safe-upgrade snapshots via Tools.
|
* Delete one or more safe-upgrade snapshots via Tools.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -223,6 +223,22 @@ class SafeUpgradeManager
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function queueSnapshot(?string $label = null): array
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
'operation' => 'snapshot',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (null !== $label) {
|
||||||
|
$label = trim((string)$label);
|
||||||
|
if ($label !== '') {
|
||||||
|
$options['label'] = $label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->queue($options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, string> $snapshotIds
|
* @param array<int, string> $snapshotIds
|
||||||
* @return array<int, array{id:string,status:string,message:?string}>
|
* @return array<int, array{id:string,status:string,message:?string}>
|
||||||
@@ -515,8 +531,25 @@ class SafeUpgradeManager
|
|||||||
|
|
||||||
$this->log(sprintf('Queued safe upgrade job %s', $jobId));
|
$this->log(sprintf('Queued safe upgrade job %s', $jobId));
|
||||||
|
|
||||||
$queueMessage = $operation === 'restore' ? 'Waiting for restore worker...' : 'Waiting for upgrade worker...';
|
if ($operation === 'restore') {
|
||||||
$this->setProgress('queued', $queueMessage, 0, ['job_id' => $jobId, 'status' => 'queued', 'operation' => $operation]);
|
$queueMessage = 'Waiting for restore worker...';
|
||||||
|
} elseif ($operation === 'snapshot') {
|
||||||
|
$queueMessage = 'Waiting for snapshot worker...';
|
||||||
|
} else {
|
||||||
|
$queueMessage = 'Waiting for upgrade worker...';
|
||||||
|
}
|
||||||
|
$queuedExtras = [
|
||||||
|
'job_id' => $jobId,
|
||||||
|
'status' => 'queued',
|
||||||
|
'operation' => $operation,
|
||||||
|
];
|
||||||
|
if ($operation === 'snapshot') {
|
||||||
|
if (isset($options['label']) && is_string($options['label'])) {
|
||||||
|
$queuedExtras['label'] = $options['label'];
|
||||||
|
}
|
||||||
|
$queuedExtras['mode'] = 'manual';
|
||||||
|
}
|
||||||
|
$this->setProgress('queued', $queueMessage, 0, $queuedExtras);
|
||||||
|
|
||||||
if (!function_exists('proc_open')) {
|
if (!function_exists('proc_open')) {
|
||||||
$message = 'proc_open() is disabled on this server; unable to run safe upgrade worker.';
|
$message = 'proc_open() is disabled on this server; unable to run safe upgrade worker.';
|
||||||
@@ -701,6 +734,10 @@ class SafeUpgradeManager
|
|||||||
return $this->runRestore($options);
|
return $this->runRestore($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($operation === 'snapshot') {
|
||||||
|
return $this->runSnapshot($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);
|
||||||
@@ -888,6 +925,7 @@ class SafeUpgradeManager
|
|||||||
'snapshot' => $snapshotId,
|
'snapshot' => $snapshotId,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'manifest' => $manifest,
|
'manifest' => $manifest,
|
||||||
|
'label' => $label,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -897,6 +935,69 @@ class SafeUpgradeManager
|
|||||||
'snapshot' => $snapshotId,
|
'snapshot' => $snapshotId,
|
||||||
'version' => $version,
|
'version' => $version,
|
||||||
'manifest' => $manifest,
|
'manifest' => $manifest,
|
||||||
|
'label' => $label,
|
||||||
|
'context' => $this->buildStatusContext(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function runSnapshot(array $options): array
|
||||||
|
{
|
||||||
|
$label = isset($options['label']) ? (string)$options['label'] : null;
|
||||||
|
if ($label !== null) {
|
||||||
|
$label = trim($label);
|
||||||
|
if ($label === '') {
|
||||||
|
$label = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setProgress('snapshot', 'Creating manual snapshot...', null, [
|
||||||
|
'operation' => 'snapshot',
|
||||||
|
'label' => $label,
|
||||||
|
'mode' => 'manual',
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$safeUpgrade = $this->getSafeUpgradeService();
|
||||||
|
$manifest = $safeUpgrade->createSnapshot($label);
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
return $this->errorResult($e->getMessage(), [
|
||||||
|
'operation' => 'snapshot',
|
||||||
|
]);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
return $this->errorResult($e->getMessage(), [
|
||||||
|
'operation' => 'snapshot',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$snapshotId = $manifest['id'] ?? null;
|
||||||
|
$version = $manifest['source_version'] ?? $manifest['target_version'] ?? null;
|
||||||
|
|
||||||
|
$this->setProgress('complete', sprintf('Snapshot %s created.', $snapshotId ?? '(unknown)'), 100, [
|
||||||
|
'operation' => 'snapshot',
|
||||||
|
'snapshot' => $snapshotId,
|
||||||
|
'version' => $version,
|
||||||
|
'label' => $label,
|
||||||
|
'mode' => 'manual',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($this->jobManifestPath) {
|
||||||
|
$this->updateJob([
|
||||||
|
'result' => [
|
||||||
|
'status' => 'success',
|
||||||
|
'snapshot' => $snapshotId,
|
||||||
|
'version' => $version,
|
||||||
|
'manifest' => $manifest,
|
||||||
|
'label' => $label,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'status' => 'success',
|
||||||
|
'snapshot' => $snapshotId,
|
||||||
|
'version' => $version,
|
||||||
|
'manifest' => $manifest,
|
||||||
|
'label' => $label,
|
||||||
'context' => $this->buildStatusContext(),
|
'context' => $this->buildStatusContext(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -859,6 +859,12 @@ PLUGIN_ADMIN:
|
|||||||
RESTORE_GRAV_SUCCESS_SIMPLE: "Snapshot %s restored."
|
RESTORE_GRAV_SUCCESS_SIMPLE: "Snapshot %s restored."
|
||||||
RESTORE_GRAV_RUNNING: "Restoring snapshot %s..."
|
RESTORE_GRAV_RUNNING: "Restoring snapshot %s..."
|
||||||
RESTORE_GRAV_FAILED: "Unable to restore the selected snapshot."
|
RESTORE_GRAV_FAILED: "Unable to restore the selected snapshot."
|
||||||
|
RESTORE_GRAV_CREATE_SNAPSHOT: "Create Snapshot"
|
||||||
|
RESTORE_GRAV_SNAPSHOT_PROMPT: "Enter an optional snapshot label"
|
||||||
|
RESTORE_GRAV_SNAPSHOT_RUNNING: "Creating snapshot %s..."
|
||||||
|
RESTORE_GRAV_SNAPSHOT_SUCCESS: "Snapshot %s created."
|
||||||
|
RESTORE_GRAV_SNAPSHOT_FAILED: "Snapshot creation failed."
|
||||||
|
RESTORE_GRAV_SNAPSHOT_FALLBACK: "Snapshot creation may have completed. Reloading..."
|
||||||
RESTORE_GRAV_DELETE_SUCCESS: "%d snapshot(s) deleted."
|
RESTORE_GRAV_DELETE_SUCCESS: "%d snapshot(s) deleted."
|
||||||
RESTORE_GRAV_DELETE_FAILED: "Failed to delete one or more snapshots."
|
RESTORE_GRAV_DELETE_FAILED: "Failed to delete one or more snapshots."
|
||||||
ROUTE_OVERRIDES: "Route Overrides"
|
ROUTE_OVERRIDES: "Route Overrides"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const base = `${config.base_url_relative}/update.json`;
|
|||||||
|
|
||||||
const urls = {
|
const urls = {
|
||||||
restore: `${base}/${task}safeUpgradeRestore/${nonce}`,
|
restore: `${base}/${task}safeUpgradeRestore/${nonce}`,
|
||||||
|
snapshot: `${base}/${task}safeUpgradeSnapshot/${nonce}`,
|
||||||
status: `${base}/${task}safeUpgradeStatus/${nonce}`,
|
status: `${base}/${task}safeUpgradeStatus/${nonce}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,6 +28,74 @@ class RestoreManager {
|
|||||||
}
|
}
|
||||||
this.startRestore(button);
|
this.startRestore(button);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '[data-create-snapshot]', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const button = $(event.currentTarget);
|
||||||
|
if (this.job) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.startSnapshot(button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
startSnapshot(button) {
|
||||||
|
let label = null;
|
||||||
|
if (typeof window !== 'undefined' && window.prompt) {
|
||||||
|
const promptMessage = translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_PROMPT || 'Enter an optional snapshot label';
|
||||||
|
const input = window.prompt(promptMessage, '');
|
||||||
|
if (input === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
label = input.trim();
|
||||||
|
if (label === '') {
|
||||||
|
label = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button.prop('disabled', true).addClass('is-loading');
|
||||||
|
|
||||||
|
const body = {};
|
||||||
|
if (label) {
|
||||||
|
body.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
request(urls.snapshot, { method: 'post', body }, (response) => {
|
||||||
|
button.prop('disabled', false).removeClass('is-loading');
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
toastr.error(translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FAILED || 'Snapshot creation failed.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status === 'error') {
|
||||||
|
toastr.error(response.message || translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FAILED || 'Snapshot creation failed.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = response.data || {};
|
||||||
|
const jobId = data.job_id || (data.job && data.job.id);
|
||||||
|
if (!jobId) {
|
||||||
|
const message = response.message || translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FAILED || 'Snapshot creation failed.';
|
||||||
|
toastr.error(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.job = {
|
||||||
|
id: jobId,
|
||||||
|
operation: 'snapshot',
|
||||||
|
snapshot: null,
|
||||||
|
label
|
||||||
|
};
|
||||||
|
this.pollFailures = 0;
|
||||||
|
|
||||||
|
const descriptor = label || jobId;
|
||||||
|
const runningMessage = translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_RUNNING
|
||||||
|
? translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_RUNNING.replace('%s', descriptor)
|
||||||
|
: 'Creating snapshot...';
|
||||||
|
toastr.info(runningMessage);
|
||||||
|
this.schedulePoll();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
startRestore(button) {
|
startRestore(button) {
|
||||||
@@ -62,6 +131,7 @@ class RestoreManager {
|
|||||||
this.job = {
|
this.job = {
|
||||||
id: jobId,
|
id: jobId,
|
||||||
snapshot,
|
snapshot,
|
||||||
|
operation: 'restore',
|
||||||
};
|
};
|
||||||
this.pollFailures = 0;
|
this.pollFailures = 0;
|
||||||
|
|
||||||
@@ -108,9 +178,18 @@ class RestoreManager {
|
|||||||
|
|
||||||
const stage = progress.stage || null;
|
const stage = progress.stage || null;
|
||||||
const status = job.status || progress.status || null;
|
const status = job.status || progress.status || null;
|
||||||
|
const operation = progress.operation || this.job.operation || null;
|
||||||
|
|
||||||
|
if (!this.job.snapshot && progress.snapshot) {
|
||||||
|
this.job.snapshot = progress.snapshot;
|
||||||
|
} else if (!this.job.snapshot && job.result && job.result.snapshot) {
|
||||||
|
this.job.snapshot = job.result.snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
if (stage === 'error' || status === 'error') {
|
if (stage === 'error' || status === 'error') {
|
||||||
const message = job.error || progress.message || translations.PLUGIN_ADMIN?.RESTORE_GRAV_FAILED || 'Snapshot restore failed.';
|
const message = job.error || progress.message || (operation === 'snapshot'
|
||||||
|
? translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FAILED || 'Snapshot creation failed.'
|
||||||
|
: translations.PLUGIN_ADMIN?.RESTORE_GRAV_FAILED || 'Snapshot restore failed.');
|
||||||
toastr.error(message);
|
toastr.error(message);
|
||||||
this.job = null;
|
this.job = null;
|
||||||
this.clearPoll();
|
this.clearPoll();
|
||||||
@@ -118,6 +197,19 @@ class RestoreManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stage === 'complete' || status === 'success') {
|
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 successMessage = translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_SUCCESS
|
||||||
|
? translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', snapshotLabel)
|
||||||
|
: (snapshotId ? `Snapshot ${snapshotId} created.` : 'Snapshot created.');
|
||||||
|
toastr.success(successMessage);
|
||||||
|
this.job = null;
|
||||||
|
this.clearPoll();
|
||||||
|
setTimeout(() => window.location.reload(), 1500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const snapshot = progress.snapshot || this.job.snapshot;
|
const snapshot = progress.snapshot || this.job.snapshot;
|
||||||
const version = (job.result && job.result.version) || progress.version || '';
|
const version = (job.result && job.result.version) || progress.version || '';
|
||||||
let successMessage;
|
let successMessage;
|
||||||
@@ -149,12 +241,18 @@ class RestoreManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.pollFailures += 1;
|
this.pollFailures += 1;
|
||||||
|
const operation = this.job.operation || 'restore';
|
||||||
const snapshot = this.job.snapshot || '';
|
const snapshot = this.job.snapshot || '';
|
||||||
|
|
||||||
if (this.pollFailures >= 3) {
|
if (this.pollFailures >= 3) {
|
||||||
const message = snapshot
|
let message;
|
||||||
? `Snapshot ${snapshot} restore is completing. Reloading...`
|
if (operation === 'snapshot') {
|
||||||
: 'Snapshot restore is completing. Reloading...';
|
message = translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FALLBACK || 'Snapshot creation may have completed. Reloading...';
|
||||||
|
} else {
|
||||||
|
message = snapshot
|
||||||
|
? `Snapshot ${snapshot} restore is completing. Reloading...`
|
||||||
|
: 'Snapshot restore is completing. Reloading...';
|
||||||
|
}
|
||||||
toastr.info(message);
|
toastr.info(message);
|
||||||
this.job = null;
|
this.job = null;
|
||||||
this.clearPoll();
|
this.clearPoll();
|
||||||
|
|||||||
157
themes/grav/js/admin.min.js
vendored
157
themes/grav/js/admin.min.js
vendored
@@ -10980,6 +10980,7 @@ var nonce = "admin-nonce".concat(paramSep).concat(external_GravAdmin_namespaceOb
|
|||||||
var base = "".concat(external_GravAdmin_namespaceObject.config.base_url_relative, "/update.json");
|
var base = "".concat(external_GravAdmin_namespaceObject.config.base_url_relative, "/update.json");
|
||||||
var urls = {
|
var urls = {
|
||||||
restore: "".concat(base, "/").concat(task, "safeUpgradeRestore/").concat(nonce),
|
restore: "".concat(base, "/").concat(task, "safeUpgradeRestore/").concat(nonce),
|
||||||
|
snapshot: "".concat(base, "/").concat(task, "safeUpgradeSnapshot/").concat(nonce),
|
||||||
status: "".concat(base, "/").concat(task, "safeUpgradeStatus/").concat(nonce)
|
status: "".concat(base, "/").concat(task, "safeUpgradeStatus/").concat(nonce)
|
||||||
};
|
};
|
||||||
var RestoreManager = /*#__PURE__*/function () {
|
var RestoreManager = /*#__PURE__*/function () {
|
||||||
@@ -10997,11 +10998,78 @@ var RestoreManager = /*#__PURE__*/function () {
|
|||||||
}
|
}
|
||||||
_this.startRestore(button);
|
_this.startRestore(button);
|
||||||
});
|
});
|
||||||
|
external_jQuery_default()(document).on('click', '[data-create-snapshot]', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var button = external_jQuery_default()(event.currentTarget);
|
||||||
|
if (_this.job) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_this.startSnapshot(button);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return restore_createClass(RestoreManager, [{
|
return restore_createClass(RestoreManager, [{
|
||||||
|
key: "startSnapshot",
|
||||||
|
value: function startSnapshot(button) {
|
||||||
|
var _this2 = this;
|
||||||
|
var label = null;
|
||||||
|
if (typeof window !== 'undefined' && window.prompt) {
|
||||||
|
var _translations$PLUGIN_;
|
||||||
|
var promptMessage = ((_translations$PLUGIN_ = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_ === void 0 ? void 0 : _translations$PLUGIN_.RESTORE_GRAV_SNAPSHOT_PROMPT) || 'Enter an optional snapshot label';
|
||||||
|
var input = window.prompt(promptMessage, '');
|
||||||
|
if (input === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
label = input.trim();
|
||||||
|
if (label === '') {
|
||||||
|
label = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
button.prop('disabled', true).addClass('is-loading');
|
||||||
|
var body = {};
|
||||||
|
if (label) {
|
||||||
|
body.label = label;
|
||||||
|
}
|
||||||
|
utils_request(urls.snapshot, {
|
||||||
|
method: 'post',
|
||||||
|
body: body
|
||||||
|
}, function (response) {
|
||||||
|
var _translations$PLUGIN_5;
|
||||||
|
button.prop('disabled', false).removeClass('is-loading');
|
||||||
|
if (!response) {
|
||||||
|
var _translations$PLUGIN_2;
|
||||||
|
utils_toastr.error(((_translations$PLUGIN_2 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_2 === void 0 ? void 0 : _translations$PLUGIN_2.RESTORE_GRAV_SNAPSHOT_FAILED) || 'Snapshot creation failed.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (response.status === 'error') {
|
||||||
|
var _translations$PLUGIN_3;
|
||||||
|
utils_toastr.error(response.message || ((_translations$PLUGIN_3 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_3 === void 0 ? void 0 : _translations$PLUGIN_3.RESTORE_GRAV_SNAPSHOT_FAILED) || 'Snapshot creation failed.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var data = response.data || {};
|
||||||
|
var jobId = data.job_id || data.job && data.job.id;
|
||||||
|
if (!jobId) {
|
||||||
|
var _translations$PLUGIN_4;
|
||||||
|
var message = response.message || ((_translations$PLUGIN_4 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_4 === void 0 ? void 0 : _translations$PLUGIN_4.RESTORE_GRAV_SNAPSHOT_FAILED) || 'Snapshot creation failed.';
|
||||||
|
utils_toastr.error(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_this2.job = {
|
||||||
|
id: jobId,
|
||||||
|
operation: 'snapshot',
|
||||||
|
snapshot: null,
|
||||||
|
label: label
|
||||||
|
};
|
||||||
|
_this2.pollFailures = 0;
|
||||||
|
var descriptor = label || jobId;
|
||||||
|
var runningMessage = (_translations$PLUGIN_5 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_5 !== void 0 && _translations$PLUGIN_5.RESTORE_GRAV_SNAPSHOT_RUNNING ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_RUNNING.replace('%s', descriptor) : 'Creating snapshot...';
|
||||||
|
utils_toastr.info(runningMessage);
|
||||||
|
_this2.schedulePoll();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, {
|
||||||
key: "startRestore",
|
key: "startRestore",
|
||||||
value: function startRestore(button) {
|
value: function startRestore(button) {
|
||||||
var _this2 = this;
|
var _this3 = this;
|
||||||
var snapshot = button.data('restore-snapshot');
|
var snapshot = button.data('restore-snapshot');
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
return;
|
return;
|
||||||
@@ -11014,44 +11082,45 @@ var RestoreManager = /*#__PURE__*/function () {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
body: body
|
body: body
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
var _translations$PLUGIN_4;
|
var _translations$PLUGIN_9;
|
||||||
button.prop('disabled', false).removeClass('is-loading');
|
button.prop('disabled', false).removeClass('is-loading');
|
||||||
if (!response) {
|
if (!response) {
|
||||||
var _translations$PLUGIN_;
|
var _translations$PLUGIN_6;
|
||||||
utils_toastr.error(((_translations$PLUGIN_ = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_ === void 0 ? void 0 : _translations$PLUGIN_.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.');
|
utils_toastr.error(((_translations$PLUGIN_6 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_6 === void 0 ? void 0 : _translations$PLUGIN_6.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (response.status === 'error') {
|
if (response.status === 'error') {
|
||||||
var _translations$PLUGIN_2;
|
var _translations$PLUGIN_7;
|
||||||
utils_toastr.error(response.message || ((_translations$PLUGIN_2 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_2 === void 0 ? void 0 : _translations$PLUGIN_2.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.');
|
utils_toastr.error(response.message || ((_translations$PLUGIN_7 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_7 === void 0 ? void 0 : _translations$PLUGIN_7.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var data = response.data || {};
|
var data = response.data || {};
|
||||||
var jobId = data.job_id || data.job && data.job.id;
|
var jobId = data.job_id || data.job && data.job.id;
|
||||||
if (!jobId) {
|
if (!jobId) {
|
||||||
var _translations$PLUGIN_3;
|
var _translations$PLUGIN_8;
|
||||||
var message = response.message || ((_translations$PLUGIN_3 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_3 === void 0 ? void 0 : _translations$PLUGIN_3.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.';
|
var message = response.message || ((_translations$PLUGIN_8 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_8 === void 0 ? void 0 : _translations$PLUGIN_8.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.';
|
||||||
utils_toastr.error(message);
|
utils_toastr.error(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_this2.job = {
|
_this3.job = {
|
||||||
id: jobId,
|
id: jobId,
|
||||||
snapshot: snapshot
|
snapshot: snapshot,
|
||||||
|
operation: 'restore'
|
||||||
};
|
};
|
||||||
_this2.pollFailures = 0;
|
_this3.pollFailures = 0;
|
||||||
var runningMessage = (_translations$PLUGIN_4 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_4 !== void 0 && _translations$PLUGIN_4.RESTORE_GRAV_RUNNING ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_RUNNING.replace('%s', snapshot) : "Restoring snapshot ".concat(snapshot, "...");
|
var runningMessage = (_translations$PLUGIN_9 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_9 !== void 0 && _translations$PLUGIN_9.RESTORE_GRAV_RUNNING ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_RUNNING.replace('%s', snapshot) : "Restoring snapshot ".concat(snapshot, "...");
|
||||||
utils_toastr.info(runningMessage);
|
utils_toastr.info(runningMessage);
|
||||||
_this2.schedulePoll();
|
_this3.schedulePoll();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "schedulePoll",
|
key: "schedulePoll",
|
||||||
value: function schedulePoll() {
|
value: function schedulePoll() {
|
||||||
var _this3 = this;
|
var _this4 = this;
|
||||||
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1200;
|
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1200;
|
||||||
this.clearPoll();
|
this.clearPoll();
|
||||||
this.pollTimer = setTimeout(function () {
|
this.pollTimer = setTimeout(function () {
|
||||||
return _this3.pollStatus();
|
return _this4.pollStatus();
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@@ -11065,7 +11134,7 @@ var RestoreManager = /*#__PURE__*/function () {
|
|||||||
}, {
|
}, {
|
||||||
key: "pollStatus",
|
key: "pollStatus",
|
||||||
value: function pollStatus() {
|
value: function pollStatus() {
|
||||||
var _this4 = this;
|
var _this5 = this;
|
||||||
if (!this.job) {
|
if (!this.job) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -11075,9 +11144,9 @@ var RestoreManager = /*#__PURE__*/function () {
|
|||||||
silentErrors: true
|
silentErrors: true
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
handled = true;
|
handled = true;
|
||||||
_this4.pollFailures = 0;
|
_this5.pollFailures = 0;
|
||||||
if (!response || response.status !== 'success') {
|
if (!response || response.status !== 'success') {
|
||||||
_this4.schedulePoll();
|
_this5.schedulePoll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var data = response.data || {};
|
var data = response.data || {};
|
||||||
@@ -11085,38 +11154,57 @@ var RestoreManager = /*#__PURE__*/function () {
|
|||||||
var progress = data.progress || {};
|
var progress = data.progress || {};
|
||||||
var stage = progress.stage || null;
|
var stage = progress.stage || null;
|
||||||
var status = job.status || progress.status || null;
|
var status = job.status || progress.status || null;
|
||||||
|
var operation = progress.operation || _this5.job.operation || null;
|
||||||
|
if (!_this5.job.snapshot && progress.snapshot) {
|
||||||
|
_this5.job.snapshot = progress.snapshot;
|
||||||
|
} else if (!_this5.job.snapshot && job.result && job.result.snapshot) {
|
||||||
|
_this5.job.snapshot = job.result.snapshot;
|
||||||
|
}
|
||||||
if (stage === 'error' || status === 'error') {
|
if (stage === 'error' || status === 'error') {
|
||||||
var _translations$PLUGIN_5;
|
var _translations$PLUGIN_0, _translations$PLUGIN_1;
|
||||||
var message = job.error || progress.message || ((_translations$PLUGIN_5 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_5 === void 0 ? void 0 : _translations$PLUGIN_5.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.';
|
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.');
|
||||||
utils_toastr.error(message);
|
utils_toastr.error(message);
|
||||||
_this4.job = null;
|
_this5.job = null;
|
||||||
_this4.clearPoll();
|
_this5.clearPoll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stage === 'complete' || status === 'success') {
|
if (stage === 'complete' || status === 'success') {
|
||||||
var _translations$PLUGIN_6, _translations$PLUGIN_7;
|
var _translations$PLUGIN_12, _translations$PLUGIN_13;
|
||||||
var snapshot = progress.snapshot || _this4.job.snapshot;
|
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.';
|
||||||
|
utils_toastr.success(_successMessage);
|
||||||
|
_this5.job = null;
|
||||||
|
_this5.clearPoll();
|
||||||
|
setTimeout(function () {
|
||||||
|
return window.location.reload();
|
||||||
|
}, 1500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var snapshot = progress.snapshot || _this5.job.snapshot;
|
||||||
var version = job.result && job.result.version || progress.version || '';
|
var version = job.result && job.result.version || progress.version || '';
|
||||||
var successMessage;
|
var successMessage;
|
||||||
if ((_translations$PLUGIN_6 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_6 !== void 0 && _translations$PLUGIN_6.RESTORE_GRAV_SUCCESS_MESSAGE && version) {
|
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);
|
successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshot).replace('%2$s', version);
|
||||||
} else if ((_translations$PLUGIN_7 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_7 !== void 0 && _translations$PLUGIN_7.RESTORE_GRAV_SUCCESS_SIMPLE) {
|
} 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);
|
successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshot);
|
||||||
} else {
|
} else {
|
||||||
successMessage = version ? "Snapshot ".concat(snapshot, " restored (Grav ").concat(version, ").") : "Snapshot ".concat(snapshot, " restored.");
|
successMessage = version ? "Snapshot ".concat(snapshot, " restored (Grav ").concat(version, ").") : "Snapshot ".concat(snapshot, " restored.");
|
||||||
}
|
}
|
||||||
utils_toastr.success(successMessage);
|
utils_toastr.success(successMessage);
|
||||||
_this4.job = null;
|
_this5.job = null;
|
||||||
_this4.clearPoll();
|
_this5.clearPoll();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
return window.location.reload();
|
return window.location.reload();
|
||||||
}, 1500);
|
}, 1500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_this4.schedulePoll();
|
_this5.schedulePoll();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
_this4.handleSilentFailure();
|
_this5.handleSilentFailure();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -11127,9 +11215,16 @@ var RestoreManager = /*#__PURE__*/function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.pollFailures += 1;
|
this.pollFailures += 1;
|
||||||
|
var operation = this.job.operation || 'restore';
|
||||||
var snapshot = this.job.snapshot || '';
|
var snapshot = this.job.snapshot || '';
|
||||||
if (this.pollFailures >= 3) {
|
if (this.pollFailures >= 3) {
|
||||||
var message = snapshot ? "Snapshot ".concat(snapshot, " restore is completing. Reloading...") : 'Snapshot restore is completing. Reloading...';
|
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...';
|
||||||
|
} else {
|
||||||
|
message = snapshot ? "Snapshot ".concat(snapshot, " restore is completing. Reloading...") : 'Snapshot restore is completing. Reloading...';
|
||||||
|
}
|
||||||
utils_toastr.info(message);
|
utils_toastr.info(message);
|
||||||
this.job = null;
|
this.job = null;
|
||||||
this.clearPoll();
|
this.clearPoll();
|
||||||
|
|||||||
@@ -55,6 +55,9 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="button-bar">
|
<div class="button-bar">
|
||||||
|
<button type="button" class="button primary" data-create-snapshot>
|
||||||
|
{{ "PLUGIN_ADMIN.RESTORE_GRAV_CREATE_SNAPSHOT"|t }}
|
||||||
|
</button>
|
||||||
<button type="submit" form="snapshot-delete-form" class="button danger" name="task" value="safeUpgradeDelete">
|
<button type="submit" form="snapshot-delete-form" class="button danger" name="task" value="safeUpgradeDelete">
|
||||||
{{ "PLUGIN_ADMIN.RESTORE_GRAV_DELETE_SELECTED"|t }}
|
{{ "PLUGIN_ADMIN.RESTORE_GRAV_DELETE_SELECTED"|t }}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user