From 582521f419c529e251940aec378dd0993a35b2e8 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 12 Mar 2021 14:47:49 -0700 Subject: [PATCH] fix: backup restore delete all files --- .../Controllers/Api/Client/Servers/BackupController.php | 2 +- resources/scripts/api/server/backups/index.ts | 6 ++++-- .../components/server/backups/BackupContextMenu.tsx | 9 ++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/Client/Servers/BackupController.php b/app/Http/Controllers/Api/Client/Servers/BackupController.php index 3457e1cc2..e56494c6d 100644 --- a/app/Http/Controllers/Api/Client/Servers/BackupController.php +++ b/app/Http/Controllers/Api/Client/Servers/BackupController.php @@ -213,7 +213,7 @@ class BackupController extends ClientApiController // actions against it via the Panel API. $server->update(['status' => Server::STATUS_RESTORING_BACKUP]); - $this->repository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate') === 'true'); + $this->repository->setServer($server)->restore($backup, $url ?? null, $request->input('truncate')); }); return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); diff --git a/resources/scripts/api/server/backups/index.ts b/resources/scripts/api/server/backups/index.ts index 016836364..4f1311fdf 100644 --- a/resources/scripts/api/server/backups/index.ts +++ b/resources/scripts/api/server/backups/index.ts @@ -1,5 +1,7 @@ import http from '@/api/http'; -export const restoreServerBackup = async (uuid: string, backup: string): Promise => { - await http.post(`/api/client/servers/${uuid}/backups/${backup}/restore`); +export const restoreServerBackup = async (uuid: string, backup: string, truncate?: boolean): Promise => { + await http.post(`/api/client/servers/${uuid}/backups/${backup}/restore`, { + truncate, + }); }; diff --git a/resources/scripts/components/server/backups/BackupContextMenu.tsx b/resources/scripts/components/server/backups/BackupContextMenu.tsx index bef067319..42311d222 100644 --- a/resources/scripts/components/server/backups/BackupContextMenu.tsx +++ b/resources/scripts/components/server/backups/BackupContextMenu.tsx @@ -25,6 +25,7 @@ export default ({ backup }: Props) => { const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState); const [ modal, setModal ] = useState(''); const [ loading, setLoading ] = useState(false); + const [ truncate, setTruncate ] = useState(false); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { mutate } = getServerBackups(); @@ -59,10 +60,10 @@ export default ({ backup }: Props) => { }); }; - const doRestorationAction = () => { + const doRestorationAction = (truncate: boolean) => { setLoading(true); clearFlashes('backups'); - restoreServerBackup(uuid, backup.uuid) + restoreServerBackup(uuid, backup.uuid, truncate) .then(() => setServerFromState(s => ({ ...s, status: 'restoring_backup', @@ -87,7 +88,7 @@ export default ({ backup }: Props) => { visible={modal === 'restore'} title={'Restore this backup?'} buttonText={'Restore backup'} - onConfirmed={() => doRestorationAction()} + onConfirmed={() => doRestorationAction(truncate)} onModalDismissed={() => setModal('')} >

@@ -108,6 +109,8 @@ export default ({ backup }: Props) => { css={tw`text-red-500! w-5! h-5! mr-2`} id={'restore_truncate'} value={'true'} + checked={truncate} + onChange={() => setTruncate(!truncate)} /> Remove all files and folders before restoring this backup.