mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-01 19:06:16 +01:00
restore tool - but not curretly working
This commit is contained in:
@@ -933,6 +933,102 @@ class AdminController extends AdminBaseController
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a safe-upgrade snapshot via Tools.
|
||||
*
|
||||
* Route: POST /tools/restore-grav?task:safeUpgradeRestore
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function taskSafeUpgradeRestore()
|
||||
{
|
||||
if (!$this->authorizeTask('install grav', ['admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post = $this->getPost($_POST ?? []);
|
||||
$snapshotId = isset($post['snapshot']) ? (string)$post['snapshot'] : '';
|
||||
|
||||
if ($snapshotId === '') {
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESTORE_GRAV_INVALID'), 'error');
|
||||
$this->setRedirect('/tools/restore-grav');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$manager = $this->getSafeUpgradeManager();
|
||||
$result = $manager->restoreSnapshot($snapshotId);
|
||||
|
||||
if (($result['status'] ?? 'error') === 'success') {
|
||||
$manifest = $result['manifest'] ?? [];
|
||||
$version = $manifest['source_version'] ?? $manifest['target_version'] ?? 'unknown';
|
||||
$this->admin->setMessage(
|
||||
sprintf($this->admin::translate('PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS'), $snapshotId, $version),
|
||||
'info'
|
||||
);
|
||||
} else {
|
||||
$message = $result['message'] ?? $this->admin::translate('PLUGIN_ADMIN.RESTORE_GRAV_FAILED');
|
||||
$this->admin->setMessage($message, 'error');
|
||||
}
|
||||
|
||||
$this->setRedirect('/tools/restore-grav');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete one or more safe-upgrade snapshots via Tools.
|
||||
*
|
||||
* Route: POST /tools/restore-grav?task:safeUpgradeDelete
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function taskSafeUpgradeDelete()
|
||||
{
|
||||
if (!$this->authorizeTask('install grav', ['admin.super'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post = $this->getPost($_POST ?? []);
|
||||
$snapshots = $post['snapshots'] ?? [];
|
||||
if (is_string($snapshots)) {
|
||||
$snapshots = [$snapshots];
|
||||
}
|
||||
|
||||
if (empty($snapshots)) {
|
||||
$this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.RESTORE_GRAV_INVALID'), 'error');
|
||||
$this->setRedirect('/tools/restore-grav');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$manager = $this->getSafeUpgradeManager();
|
||||
$results = $manager->deleteSnapshots($snapshots);
|
||||
|
||||
$success = array_filter($results, static function ($item) {
|
||||
return ($item['status'] ?? 'error') === 'success';
|
||||
});
|
||||
$failed = array_filter($results, static function ($item) {
|
||||
return ($item['status'] ?? 'error') !== 'success';
|
||||
});
|
||||
|
||||
if ($success) {
|
||||
$this->admin->setMessage(
|
||||
sprintf($this->admin::translate('PLUGIN_ADMIN.RESTORE_GRAV_DELETE_SUCCESS'), count($success)),
|
||||
'info'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($failed as $entry) {
|
||||
$message = $entry['message'] ?? $this->admin::translate('PLUGIN_ADMIN.RESTORE_GRAV_DELETE_FAILED');
|
||||
$this->admin->setMessage($message, 'error');
|
||||
}
|
||||
|
||||
$this->setRedirect('/tools/restore-grav');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles uninstalling plugins and themes
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user