From 9c9c77515002d622fe3be47d1d9d2b1caea65c33 Mon Sep 17 00:00:00 2001 From: Alexis Guyomar Date: Wed, 8 Jan 2025 18:10:51 +0100 Subject: [PATCH 1/5] feat: add restore page dialogs --- _dev/src/ts/dialogs/DeleteBackupDialog.ts | 34 ++++++++ _dev/src/ts/dialogs/RestoreBackupDialog.ts | 34 ++++++++ .../ts/pages/RestorePageBackupSelection.ts | 4 +- _dev/src/ts/routing/ScriptHandler.ts | 4 + classes/Router/Router.php | 16 +++- classes/Router/Routes.php | 6 +- .../RestorePageBackupSelectionController.php | 78 ++++++++++++++++++- .../components/backup-selection.html.twig | 4 +- .../dialogs/dialog-delete-backup.html.twig | 30 +++++++ .../dialog-restore-from-backup.html.twig | 28 +++++++ 10 files changed, 224 insertions(+), 14 deletions(-) create mode 100644 _dev/src/ts/dialogs/DeleteBackupDialog.ts create mode 100644 _dev/src/ts/dialogs/RestoreBackupDialog.ts create mode 100644 views/templates/dialogs/dialog-delete-backup.html.twig create mode 100644 views/templates/dialogs/dialog-restore-from-backup.html.twig diff --git a/_dev/src/ts/dialogs/DeleteBackupDialog.ts b/_dev/src/ts/dialogs/DeleteBackupDialog.ts new file mode 100644 index 000000000..8611a5a60 --- /dev/null +++ b/_dev/src/ts/dialogs/DeleteBackupDialog.ts @@ -0,0 +1,34 @@ +import DomLifecycle from '../types/DomLifecycle'; +import api from '../api/RequestHandler'; + +export default class DeleteBackupDialog implements DomLifecycle { + protected readonly formId = 'backup_to_delete'; + + public mount = (): void => { + this.#form.addEventListener('submit', this.#onSubmit); + }; + + public beforeDestroy = (): void => { + this.#form.removeEventListener('submit', this.#onSubmit); + }; + + get #form(): HTMLFormElement { + const form = document.forms.namedItem(this.formId); + if (!form) { + throw new Error('Form not found'); + } + if (!form.dataset.routeToConfirmDelete) { + throw new Error(`Missing data route to confirm delete from form dataset.`); + } + + return form; + } + + #onSubmit = async (event: SubmitEvent): Promise => { + event.preventDefault(); + + const form = event.target as HTMLFormElement; + + await api.post(form.dataset.routeToConfirmDelete!, new FormData(this.#form)); + }; +} diff --git a/_dev/src/ts/dialogs/RestoreBackupDialog.ts b/_dev/src/ts/dialogs/RestoreBackupDialog.ts new file mode 100644 index 000000000..272ab962b --- /dev/null +++ b/_dev/src/ts/dialogs/RestoreBackupDialog.ts @@ -0,0 +1,34 @@ +import DomLifecycle from '../types/DomLifecycle'; +import api from '../api/RequestHandler'; + +export default class RestoreBackupDialog implements DomLifecycle { + protected readonly formId = 'backup_to_restore'; + + public mount = (): void => { + this.#form.addEventListener('submit', this.#onSubmit); + }; + + public beforeDestroy = (): void => { + this.#form.removeEventListener('submit', this.#onSubmit); + }; + + get #form(): HTMLFormElement { + const form = document.forms.namedItem(this.formId); + if (!form) { + throw new Error('Form not found'); + } + if (!form.dataset.routeToConfirmRestore) { + throw new Error(`Missing data route to confirm delete from form dataset.`); + } + + return form; + } + + #onSubmit = async (event: SubmitEvent): Promise => { + event.preventDefault(); + + const form = event.target as HTMLFormElement; + + await api.post(form.dataset.routeToConfirmRestore!, new FormData(this.#form)); + }; +} diff --git a/_dev/src/ts/pages/RestorePageBackupSelection.ts b/_dev/src/ts/pages/RestorePageBackupSelection.ts index d81649494..f5030ec45 100644 --- a/_dev/src/ts/pages/RestorePageBackupSelection.ts +++ b/_dev/src/ts/pages/RestorePageBackupSelection.ts @@ -39,9 +39,9 @@ export default class RestorePageBackupSelection extends StepPage { let routeToSubmit: string | undefined; if ((event.submitter as HTMLButtonElement)?.value === 'delete') { - routeToSubmit = this.#form.dataset.routeToDelete; + routeToSubmit = this.#form.dataset.routeToSubmitDelete; } else { - routeToSubmit = this.#form.dataset.routeToSubmit; + routeToSubmit = this.#form.dataset.routeToSubmitRestore; } if (!routeToSubmit) { diff --git a/_dev/src/ts/routing/ScriptHandler.ts b/_dev/src/ts/routing/ScriptHandler.ts index d92af31c4..081237f6a 100644 --- a/_dev/src/ts/routing/ScriptHandler.ts +++ b/_dev/src/ts/routing/ScriptHandler.ts @@ -10,6 +10,8 @@ import RestorePageBackupSelection from '../pages/RestorePageBackupSelection'; import RestorePageRestore from '../pages/RestorePageRestore'; import RestorePagePostRestore from '../pages/RestorePagePostRestore'; +import RestoreBackupDialog from '../dialogs/RestoreBackupDialog'; +import DeleteBackupDialog from '../dialogs/DeleteBackupDialog'; import StartUpdateDialog from '../dialogs/StartUpdateDialog'; import SendErrorReportDialog from '../dialogs/SendErrorReportDialog'; @@ -38,6 +40,8 @@ export default class ScriptHandler { 'restore-page-restore': RestorePageRestore, 'restore-page-post-restore': RestorePagePostRestore, + 'restore-backup-dialog': RestoreBackupDialog, + 'delete-backup-dialog': DeleteBackupDialog, 'start-update-dialog': StartUpdateDialog, 'send-error-report-dialog': SendErrorReportDialog }; diff --git a/classes/Router/Router.php b/classes/Router/Router.php index 093eebaad..33c11d906 100644 --- a/classes/Router/Router.php +++ b/classes/Router/Router.php @@ -178,13 +178,21 @@ public function __construct(UpgradeContainer $upgradeContainer) 'controller' => RestorePageBackupSelectionController::class, 'method' => 'save', ], - Routes::RESTORE_STEP_BACKUP_SELECTION_SUBMIT_FORM => [ + Routes::RESTORE_STEP_BACKUP_SELECTION_SUBMIT_RESTORE_FORM => [ 'controller' => RestorePageBackupSelectionController::class, - 'method' => 'submit', + 'method' => 'submitRestore', + ], + Routes::RESTORE_STEP_BACKUP_SELECTION_CONFIRM_RESTORE_FORM => [ + 'controller' => RestorePageBackupSelectionController::class, + 'method' => 'startRestore', + ], + Routes::RESTORE_STEP_BACKUP_SELECTION_SUBMIT_DELETE_FORM => [ + 'controller' => RestorePageBackupSelectionController::class, + 'method' => 'submitDelete', ], - Routes::RESTORE_STEP_BACKUP_SELECTION_DELETE_FORM => [ + Routes::RESTORE_STEP_BACKUP_SELECTION_CONFIRM_DELETE_FORM => [ 'controller' => RestorePageBackupSelectionController::class, - 'method' => 'delete', + 'method' => 'confirmDelete', ], /* step: restore */ Routes::RESTORE_PAGE_RESTORE => [ diff --git a/classes/Router/Routes.php b/classes/Router/Routes.php index ba8dc4b58..e1eecb8d6 100644 --- a/classes/Router/Routes.php +++ b/classes/Router/Routes.php @@ -48,8 +48,10 @@ class Routes const RESTORE_PAGE_BACKUP_SELECTION = 'restore-page-backup-selection'; const RESTORE_STEP_BACKUP_SELECTION = 'restore-step-backup-selection'; const RESTORE_STEP_BACKUP_SELECTION_SAVE_FORM = 'restore-step-backup-selection-save-form'; - const RESTORE_STEP_BACKUP_SELECTION_SUBMIT_FORM = 'restore-step-backup-selection-submit-form'; - const RESTORE_STEP_BACKUP_SELECTION_DELETE_FORM = 'restore-step-backup-selection-delete-form'; + const RESTORE_STEP_BACKUP_SELECTION_CONFIRM_RESTORE_FORM = 'restore-step-backup-selection-confirm-restore-form'; + const RESTORE_STEP_BACKUP_SELECTION_SUBMIT_RESTORE_FORM = 'restore-step-backup-selection-submit-restore-form'; + const RESTORE_STEP_BACKUP_SELECTION_CONFIRM_DELETE_FORM = 'restore-step-backup-selection-confirm-delete-form'; + const RESTORE_STEP_BACKUP_SELECTION_SUBMIT_DELETE_FORM = 'restore-step-backup-selection-submit-delete-form'; /* step: restore */ const RESTORE_PAGE_RESTORE = 'restore-page-restore'; diff --git a/controllers/admin/self-managed/RestorePageBackupSelectionController.php b/controllers/admin/self-managed/RestorePageBackupSelectionController.php index 17d81eee2..b6de4641d 100644 --- a/controllers/admin/self-managed/RestorePageBackupSelectionController.php +++ b/controllers/admin/self-managed/RestorePageBackupSelectionController.php @@ -7,14 +7,18 @@ use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; use PrestaShop\Module\AutoUpgrade\Router\Routes; use PrestaShop\Module\AutoUpgrade\Task\TaskType; +use PrestaShop\Module\AutoUpgrade\Twig\PageSelectors; use PrestaShop\Module\AutoUpgrade\Twig\Steps\RestoreSteps; use PrestaShop\Module\AutoUpgrade\Twig\Steps\Stepper; use Symfony\Component\HttpFoundation\JsonResponse; +use PrestaShop\Module\AutoUpgrade\Exceptions\BackupException; class RestorePageBackupSelectionController extends AbstractPageWithStepController { const CURRENT_STEP = RestoreSteps::STEP_BACKUP_SELECTION; const FORM_NAME = 'backup_choice'; + const DELETE_BACKUP_FORM_NAME = 'backup_to_delete'; + const RESTORE_BACKUP_FORM_NAME = 'backup_to_restore'; const FORM_FIELDS = [ RestoreConfiguration::BACKUP_NAME => RestoreConfiguration::BACKUP_NAME, ]; @@ -65,8 +69,8 @@ protected function getParams(): array [ 'form_backup_selection_name' => self::FORM_NAME, 'form_route_to_save' => Routes::RESTORE_STEP_BACKUP_SELECTION_SAVE_FORM, - 'form_route_to_submit' => Routes::RESTORE_STEP_BACKUP_SELECTION_SUBMIT_FORM, - 'form_route_to_delete' => Routes::RESTORE_STEP_BACKUP_SELECTION_DELETE_FORM, + 'form_route_to_submit_restore' => Routes::RESTORE_STEP_BACKUP_SELECTION_SUBMIT_RESTORE_FORM, + 'form_route_to_submit_delete' => Routes::RESTORE_STEP_BACKUP_SELECTION_SUBMIT_DELETE_FORM, 'form_fields' => self::FORM_FIELDS, 'current_backup' => $currentBackup, 'backups_available' => $backupsAvailable, @@ -74,7 +78,40 @@ protected function getParams(): array ); } - public function delete(): JsonResponse + /** + * @return array + * @throws BackupException + */ + private function getDialogParams(): array + { + $backupName = $this->request->request->get(RestoreConfiguration::BACKUP_NAME); + $backupDate = $this->upgradeContainer->getBackupFinder()->parseBackupMetadata($backupName)['datetime']; + + return [ + 'backup_name' => $backupName, + 'backup_date' => $backupDate, + 'form_fields' => self::FORM_FIELDS, + ]; + } + + public function submitDelete(): JsonResponse + { + $onlyBackup = count($this->upgradeContainer->getBackupFinder()->getAvailableBackups()) === 1; + + return $this->displayDialog('dialog-delete-backup', + array_merge( + $this->getDialogParams(), + [ + 'only_backup' => $onlyBackup, + 'form_name' => self::DELETE_BACKUP_FORM_NAME, + 'form_route_to_confirm_delete' => Routes::RESTORE_STEP_BACKUP_SELECTION_CONFIRM_DELETE_FORM, + ] + ), + 'delete-backup-dialog' + ); + } + + public function confirmDelete(): JsonResponse { $backup = $this->request->request->get(self::FORM_FIELDS[RestoreConfiguration::BACKUP_NAME]); $this->upgradeContainer->getBackupManager()->deleteBackup($backup); @@ -92,10 +129,28 @@ public function save(): JsonResponse return AjaxResponseBuilder::nextRouteResponse(Routes::RESTORE_STEP_BACKUP_SELECTION); } + public function submitRestore(): JsonResponse + { + $backupName = $this->request->request->get(RestoreConfiguration::BACKUP_NAME); + $backupVersion = $this->upgradeContainer->getBackupFinder()->parseBackupMetadata($backupName)['version']; + + return $this->displayDialog('dialog-restore-from-backup', + array_merge( + $this->getDialogParams(), + [ + 'backup_version' => $backupVersion, + 'form_name' => self::RESTORE_BACKUP_FORM_NAME, + 'form_route_to_confirm_restore' => Routes::RESTORE_STEP_BACKUP_SELECTION_CONFIRM_RESTORE_FORM, + ] + ), + 'restore-backup-dialog' + ); + } + /** * @throws \Exception */ - public function submit(): JsonResponse + public function startRestore(): JsonResponse { $this->saveBackupConfiguration(); @@ -117,4 +172,19 @@ private function saveBackupConfiguration(): void $restoreConfiguration->merge($config); $configurationStorage->save($restoreConfiguration); } + + /** + * @param array $params + */ + private function displayDialog(string $dialogName, array $params, string $scriptName): JsonResponse + { + return AjaxResponseBuilder::hydrationResponse( + PageSelectors::DIALOG_PARENT_ID, + $this->getTwig()->render( + '@ModuleAutoUpgrade/dialogs/' . $dialogName . '.html.twig', + $params + ), + ['addScript' => $scriptName] + ); + } } diff --git a/views/templates/components/backup-selection.html.twig b/views/templates/components/backup-selection.html.twig index 5c4350b0e..553ec0968 100644 --- a/views/templates/components/backup-selection.html.twig +++ b/views/templates/components/backup-selection.html.twig @@ -2,8 +2,8 @@ class="form-group backup-selection" action="" data-route-to-save="{{ form_route_to_save }}" - data-route-to-submit="{{ form_route_to_submit }}" - data-route-to-delete="{{ form_route_to_delete }}" + data-route-to-submit-restore="{{ form_route_to_submit_restore }}" + data-route-to-submit-delete="{{ form_route_to_submit_delete }}" id="{{ form_backup_selection_name }}" name="{{ form_backup_selection_name }}" > diff --git a/views/templates/dialogs/dialog-delete-backup.html.twig b/views/templates/dialogs/dialog-delete-backup.html.twig new file mode 100644 index 000000000..df9679ef7 --- /dev/null +++ b/views/templates/dialogs/dialog-delete-backup.html.twig @@ -0,0 +1,30 @@ +{% extends "@ModuleAutoUpgrade/components/dialog.html.twig" %} + +{% set title = 'Delete backup'|trans({}) %} +{% set dialogSize = 'sm' %} +{% set message = only_backup ? + 'You are about to delete the %backup_name% backup made on %backup_date%. As it\'s your only backup, you will be redirected to the module\'s home page.'|trans({'%backup_name%': '' ~ backup_name ~ '', '%backup_date%': '' ~ backup_date ~ ''}) : + 'You are about to delete the %backup_name% backup made on %backup_date%.'|trans({'%backup_date%': '' ~ backup_name ~ '', '%backup_date%': '' ~ backup_date ~ ''}) %} + +{% block dialog_content %} + {{ parent() }} +{% endblock %} + +{% block dialog_extra_content %}{% endblock %} + +{% block dialog_footer %} + +{% endblock %} diff --git a/views/templates/dialogs/dialog-restore-from-backup.html.twig b/views/templates/dialogs/dialog-restore-from-backup.html.twig new file mode 100644 index 000000000..1b4677b40 --- /dev/null +++ b/views/templates/dialogs/dialog-restore-from-backup.html.twig @@ -0,0 +1,28 @@ +{% extends "@ModuleAutoUpgrade/components/dialog.html.twig" %} + +{% set title = 'Restore from a backup?'|trans({}) %} +{% set dialogSize = 'sm' %} +{% set message = 'You are about to restore %backup_version% using the backup from %backup_date%.'|trans({'%backup_version%': ' PrestaShop ' ~ backup_version ~ '', '%backup_date%': '' ~ backup_date ~ ''}) %} + +{% block dialog_content %} + {{ parent() }} +{% endblock %} + +{% block dialog_extra_content %}{% endblock %} + +{% block dialog_footer %} + +{% endblock %} From 335ab515b6d519d3ebd0887911e44b8fa160487c Mon Sep 17 00:00:00 2001 From: Alexis Guyomar Date: Wed, 8 Jan 2025 18:11:27 +0100 Subject: [PATCH 2/5] fix: cs fixer --- .../self-managed/RestorePageBackupSelectionController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/admin/self-managed/RestorePageBackupSelectionController.php b/controllers/admin/self-managed/RestorePageBackupSelectionController.php index b6de4641d..5f9140265 100644 --- a/controllers/admin/self-managed/RestorePageBackupSelectionController.php +++ b/controllers/admin/self-managed/RestorePageBackupSelectionController.php @@ -3,6 +3,7 @@ namespace PrestaShop\Module\AutoUpgrade\Controller; use PrestaShop\Module\AutoUpgrade\AjaxResponseBuilder; +use PrestaShop\Module\AutoUpgrade\Exceptions\BackupException; use PrestaShop\Module\AutoUpgrade\Parameters\RestoreConfiguration; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; use PrestaShop\Module\AutoUpgrade\Router\Routes; @@ -11,7 +12,6 @@ use PrestaShop\Module\AutoUpgrade\Twig\Steps\RestoreSteps; use PrestaShop\Module\AutoUpgrade\Twig\Steps\Stepper; use Symfony\Component\HttpFoundation\JsonResponse; -use PrestaShop\Module\AutoUpgrade\Exceptions\BackupException; class RestorePageBackupSelectionController extends AbstractPageWithStepController { @@ -80,6 +80,7 @@ protected function getParams(): array /** * @return array + * * @throws BackupException */ private function getDialogParams(): array From f4add9ed60f8fa3bec241cf406daf96ca297f634 Mon Sep 17 00:00:00 2001 From: tblivet Date: Thu, 9 Jan 2025 11:13:16 +0100 Subject: [PATCH 3/5] fix: dialog size and typo --- _dev/src/ts/dialogs/RestoreBackupDialog.ts | 2 +- views/templates/dialogs/dialog-delete-backup.html.twig | 5 +++-- views/templates/dialogs/dialog-restore-from-backup.html.twig | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/_dev/src/ts/dialogs/RestoreBackupDialog.ts b/_dev/src/ts/dialogs/RestoreBackupDialog.ts index 272ab962b..db50d623c 100644 --- a/_dev/src/ts/dialogs/RestoreBackupDialog.ts +++ b/_dev/src/ts/dialogs/RestoreBackupDialog.ts @@ -18,7 +18,7 @@ export default class RestoreBackupDialog implements DomLifecycle { throw new Error('Form not found'); } if (!form.dataset.routeToConfirmRestore) { - throw new Error(`Missing data route to confirm delete from form dataset.`); + throw new Error(`Missing data route to confirm restore from form dataset.`); } return form; diff --git a/views/templates/dialogs/dialog-delete-backup.html.twig b/views/templates/dialogs/dialog-delete-backup.html.twig index df9679ef7..c53e04301 100644 --- a/views/templates/dialogs/dialog-delete-backup.html.twig +++ b/views/templates/dialogs/dialog-delete-backup.html.twig @@ -1,10 +1,11 @@ {% extends "@ModuleAutoUpgrade/components/dialog.html.twig" %} {% set title = 'Delete backup'|trans({}) %} -{% set dialogSize = 'sm' %} +{% set dialogSize = 'md' %} +{% set dialogDanger = true %} {% set message = only_backup ? 'You are about to delete the %backup_name% backup made on %backup_date%. As it\'s your only backup, you will be redirected to the module\'s home page.'|trans({'%backup_name%': '' ~ backup_name ~ '', '%backup_date%': '' ~ backup_date ~ ''}) : - 'You are about to delete the %backup_name% backup made on %backup_date%.'|trans({'%backup_date%': '' ~ backup_name ~ '', '%backup_date%': '' ~ backup_date ~ ''}) %} + 'You are about to delete the %backup_name% backup made on %backup_date%.'|trans({'%backup_name%': '' ~ backup_name ~ '', '%backup_date%': '' ~ backup_date ~ ''}) %} {% block dialog_content %} {{ parent() }} diff --git a/views/templates/dialogs/dialog-restore-from-backup.html.twig b/views/templates/dialogs/dialog-restore-from-backup.html.twig index 1b4677b40..304127fe6 100644 --- a/views/templates/dialogs/dialog-restore-from-backup.html.twig +++ b/views/templates/dialogs/dialog-restore-from-backup.html.twig @@ -1,7 +1,7 @@ {% extends "@ModuleAutoUpgrade/components/dialog.html.twig" %} {% set title = 'Restore from a backup?'|trans({}) %} -{% set dialogSize = 'sm' %} +{% set dialogSize = 'md' %} {% set message = 'You are about to restore %backup_version% using the backup from %backup_date%.'|trans({'%backup_version%': ' PrestaShop ' ~ backup_version ~ '', '%backup_date%': '' ~ backup_date ~ ''}) %} {% block dialog_content %} From 95a9bdf41d204627f9159c84c19764e0a1b7cf98 Mon Sep 17 00:00:00 2001 From: tblivet Date: Thu, 9 Jan 2025 17:01:16 +0100 Subject: [PATCH 4/5] fix: dialog --- .../components/DialogBackupDelete.stories.js | 9 +++- .../DialogRestoreFromBackup.stories.js | 48 +++++++++++++++++++ .../stories/pages/BackupSelection.stories.js | 2 +- .../stories/pages/PostRestore.stories.js | 2 +- storybook/stories/pages/Restore.stories.js | 2 +- .../dialogs/dialog-backup-delete.html.twig | 31 ------------ .../templates/dialogs/dialog-backup.html.twig | 20 ++++---- .../dialogs/dialog-delete-backup.html.twig | 24 ++++------ .../dialogs/dialog-error-report.html.twig | 20 ++++---- .../dialog-restore-from-backup.html.twig | 24 ++++------ .../templates/dialogs/dialog-update.html.twig | 40 +++++++--------- 11 files changed, 112 insertions(+), 110 deletions(-) create mode 100644 storybook/stories/components/DialogRestoreFromBackup.stories.js delete mode 100644 views/templates/dialogs/dialog-backup-delete.html.twig diff --git a/storybook/stories/components/DialogBackupDelete.stories.js b/storybook/stories/components/DialogBackupDelete.stories.js index 14aa08aa2..43be2536d 100644 --- a/storybook/stories/components/DialogBackupDelete.stories.js +++ b/storybook/stories/components/DialogBackupDelete.stories.js @@ -23,7 +23,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -import DialogBackupDelete from "../../../views/templates/dialogs/dialog-backup-delete.html.twig"; +import DialogBackupDelete from "../../../views/templates/dialogs/dialog-delete-backup.html.twig"; export default { title: "Components/Dialog", @@ -34,7 +34,12 @@ export const BackupDelete = { args: { backup_name: "autoupgrade_save_8.1.6", backup_date: "15/07/2024 8:00", - is_only_backup: true, + only_backup: true, + form_name: "delete-backup", + form_route_to_confirm_delete: "/", + form_fields: { + BACKUP_NAME: "backup_name", + }, }, play: async () => { const dialog = document.querySelector('.dialog'); diff --git a/storybook/stories/components/DialogRestoreFromBackup.stories.js b/storybook/stories/components/DialogRestoreFromBackup.stories.js new file mode 100644 index 000000000..336655a80 --- /dev/null +++ b/storybook/stories/components/DialogRestoreFromBackup.stories.js @@ -0,0 +1,48 @@ +/** + * Copyright since 2007 PrestaShop SA and Contributors + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License 3.0 (AFL-3.0) + * that is bundled with this package in the file LICENSE.md. + * It is also available through the world-wide-web at this URL: + * https://opensource.org/licenses/AFL-3.0 + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@prestashop.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + * versions in the future. If you wish to customize PrestaShop for your + * needs please refer to https://devdocs.prestashop.com/ for more information. + * + * @author PrestaShop SA and Contributors + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ + +import DialogRestoreFromBackup from "../../../views/templates/dialogs/dialog-restore-from-backup.html.twig"; + +export default { + title: "Components/Dialog", + component: DialogRestoreFromBackup, + args: { + backup_version: "1.7.8.1", + backup_name: "backup-name", + backup_date: "2024-01-01", + form_name: "backup_to_restore", + form_route_to_confirm_restore: "/", + form_fields: { + BACKUP_NAME: "backup_name", + }, + }, +}; + +export const RestoreFromBackup = { + play: async () => { + const dialog = document.querySelector('.dialog'); + dialog.showModal(); + }, +}; diff --git a/storybook/stories/pages/BackupSelection.stories.js b/storybook/stories/pages/BackupSelection.stories.js index 7b667c1ef..4fb75cabf 100644 --- a/storybook/stories/pages/BackupSelection.stories.js +++ b/storybook/stories/pages/BackupSelection.stories.js @@ -23,7 +23,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -import BackupSelectionPage from "../../../views/templates/pages/rollback.html.twig"; +import BackupSelectionPage from "../../../views/templates/pages/restore.html.twig"; import { Default as BackupSelectionComponent } from "../components/BackupSelection.stories"; import { BackupSelection as Stepper } from "../components/Stepper.stories"; diff --git a/storybook/stories/pages/PostRestore.stories.js b/storybook/stories/pages/PostRestore.stories.js index 0e15ceae5..d879a05e0 100644 --- a/storybook/stories/pages/PostRestore.stories.js +++ b/storybook/stories/pages/PostRestore.stories.js @@ -23,7 +23,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -import PostRestorePage from "../../../views/templates/pages/rollback.html.twig"; +import PostRestorePage from "../../../views/templates/pages/restore.html.twig"; import { PostRestore as Stepper } from "../components/Stepper.stories"; export default { diff --git a/storybook/stories/pages/Restore.stories.js b/storybook/stories/pages/Restore.stories.js index cb2b8f479..12ea97eb4 100644 --- a/storybook/stories/pages/Restore.stories.js +++ b/storybook/stories/pages/Restore.stories.js @@ -23,7 +23,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -import RestorePage from "../../../views/templates/pages/rollback.html.twig"; +import RestorePage from "../../../views/templates/pages/restore.html.twig"; import { RestoreLogsProgress as LogsProgress } from "../components/LogsProgress.stories"; import { RestoreLogsViewer as LogsViewer } from "../components/LogsViewer.stories"; import { Restore as Stepper } from "../components/Stepper.stories"; diff --git a/views/templates/dialogs/dialog-backup-delete.html.twig b/views/templates/dialogs/dialog-backup-delete.html.twig deleted file mode 100644 index 9e50e8741..000000000 --- a/views/templates/dialogs/dialog-backup-delete.html.twig +++ /dev/null @@ -1,31 +0,0 @@ -{% extends "@ModuleAutoUpgrade/components/dialog.html.twig" %} - -{% set title = 'Delete backup'|trans({}) %} -{% set message = 'You are about to delete the [1]%backup_name%[/1] backup made on [1]%backup_date%[/1]. %redirect_message%'|trans({ - '%backup_name%': backup_name, - '%backup_date%': backup_date, - '%redirect_message%': is_only_backup ? 'As it\'s your only backup, you will be redirected to the module\'s home page.'|trans : '', - '[1]': '', - '[/1]': '' -}) %} -{% set dialogDanger = true %} - -{% block dialog_content %} - {{ parent() }} -{% endblock %} - -{% block dialog_extra_content %}{% endblock %} - -{% block dialog_footer %} - -{% endblock %} diff --git a/views/templates/dialogs/dialog-backup.html.twig b/views/templates/dialogs/dialog-backup.html.twig index eab9d332e..b4591f551 100644 --- a/views/templates/dialogs/dialog-backup.html.twig +++ b/views/templates/dialogs/dialog-backup.html.twig @@ -10,17 +10,13 @@ {% block dialog_extra_content %}{% endblock %} -{% block dialog_footer %} - + {% endblock %} diff --git a/views/templates/dialogs/dialog-delete-backup.html.twig b/views/templates/dialogs/dialog-delete-backup.html.twig index c53e04301..ec493b949 100644 --- a/views/templates/dialogs/dialog-delete-backup.html.twig +++ b/views/templates/dialogs/dialog-delete-backup.html.twig @@ -13,19 +13,15 @@ {% block dialog_extra_content %}{% endblock %} -{% block dialog_footer %} - +
+ + +
{% endblock %} diff --git a/views/templates/dialogs/dialog-error-report.html.twig b/views/templates/dialogs/dialog-error-report.html.twig index 4bea3fc04..4aedd77e8 100644 --- a/views/templates/dialogs/dialog-error-report.html.twig +++ b/views/templates/dialogs/dialog-error-report.html.twig @@ -50,17 +50,13 @@ {% endblock %} -{% block dialog_footer %} - + {% endblock %} diff --git a/views/templates/dialogs/dialog-restore-from-backup.html.twig b/views/templates/dialogs/dialog-restore-from-backup.html.twig index 304127fe6..8b9b6b1af 100644 --- a/views/templates/dialogs/dialog-restore-from-backup.html.twig +++ b/views/templates/dialogs/dialog-restore-from-backup.html.twig @@ -10,19 +10,15 @@ {% block dialog_extra_content %}{% endblock %} -{% block dialog_footer %} - +
+ + +
{% endblock %} diff --git a/views/templates/dialogs/dialog-update.html.twig b/views/templates/dialogs/dialog-update.html.twig index 008a8fc3e..cd0036ca0 100644 --- a/views/templates/dialogs/dialog-update.html.twig +++ b/views/templates/dialogs/dialog-update.html.twig @@ -31,27 +31,23 @@ {% endif %} {% endblock %} -{% block dialog_footer %} - + {% endblock %} From 57f77f8c9951069627d1825ea2cefc71e66ebef1 Mon Sep 17 00:00:00 2001 From: Alexis Guyomar Date: Fri, 10 Jan 2025 15:55:09 +0100 Subject: [PATCH 5/5] fix: add throwable --- .../RestorePageBackupSelectionController.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/controllers/admin/self-managed/RestorePageBackupSelectionController.php b/controllers/admin/self-managed/RestorePageBackupSelectionController.php index 5f9140265..da36ab7f3 100644 --- a/controllers/admin/self-managed/RestorePageBackupSelectionController.php +++ b/controllers/admin/self-managed/RestorePageBackupSelectionController.php @@ -12,6 +12,9 @@ use PrestaShop\Module\AutoUpgrade\Twig\Steps\RestoreSteps; use PrestaShop\Module\AutoUpgrade\Twig\Steps\Stepper; use Symfony\Component\HttpFoundation\JsonResponse; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\Error\SyntaxError; class RestorePageBackupSelectionController extends AbstractPageWithStepController { @@ -95,6 +98,9 @@ private function getDialogParams(): array ]; } + /** + * @throws BackupException + */ public function submitDelete(): JsonResponse { $onlyBackup = count($this->upgradeContainer->getBackupFinder()->getAvailableBackups()) === 1; @@ -130,6 +136,9 @@ public function save(): JsonResponse return AjaxResponseBuilder::nextRouteResponse(Routes::RESTORE_STEP_BACKUP_SELECTION); } + /** + * @throws BackupException + */ public function submitRestore(): JsonResponse { $backupName = $this->request->request->get(RestoreConfiguration::BACKUP_NAME); @@ -175,7 +184,9 @@ private function saveBackupConfiguration(): void } /** - * @param array $params + * @throws LoaderError + * @throws RuntimeError + * @throws SyntaxError */ private function displayDialog(string $dialogName, array $params, string $scriptName): JsonResponse {