Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIDDLEWARE] backup selection #1148

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions classes/Router/Middlewares/HasBackupAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PrestaShop\Module\AutoUpgrade\Router\Middlewares;

use PrestaShop\Module\AutoUpgrade\Router\Routes;

class HasBackupAvailable extends AbstractMiddleware
{
public function process(): ?string
{
$backups = $this->upgradeContainer->getBackupFinder()->getAvailableBackups();

if (empty($backups)) {
return Routes::HOME_PAGE;
}

return null;
}
}
4 changes: 4 additions & 0 deletions classes/Router/RoutesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PrestaShop\Module\AutoUpgrade\Controller\UpdatePageUpdateController;
use PrestaShop\Module\AutoUpgrade\Controller\UpdatePageUpdateOptionsController;
use PrestaShop\Module\AutoUpgrade\Controller\UpdatePageVersionChoiceController;
use PrestaShop\Module\AutoUpgrade\Router\Middlewares\HasBackupAvailable;
use PrestaShop\Module\AutoUpgrade\Router\Middlewares\LocalChannelXmlAndZipAreValid;
use PrestaShop\Module\AutoUpgrade\Router\Middlewares\UpdateIsConfigured;

Expand Down Expand Up @@ -142,6 +143,9 @@ class RoutesConfig
Routes::RESTORE_PAGE_BACKUP_SELECTION => [
'controller' => RestorePageBackupSelectionController::class,
'method' => 'index',
'middleware' => [
HasBackupAvailable::class,
],
],
Routes::RESTORE_STEP_BACKUP_SELECTION => [
'controller' => RestorePageBackupSelectionController::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ class RestorePageBackupSelectionController extends AbstractPageWithStepControlle
RestoreConfiguration::BACKUP_NAME => RestoreConfiguration::BACKUP_NAME,
];

public function index()
{
$backups = $this->upgradeContainer->getBackupFinder()->getAvailableBackups();

if (!empty($backups)) {
return parent::index();
}

return AjaxResponseBuilder::nextRouteResponse(Routes::HOME_PAGE);
}

protected function getPageTemplate(): string
{
return 'restore';
Expand Down
Loading