forked from PrestaShop/autoupgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PrestaShop#851 from M0rgan01/add-rollback-command
Add 'backup:restore' in symfony console
- Loading branch information
Showing
9 changed files
with
187 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* 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 [email protected] 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 <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Commands; | ||
|
||
use Exception; | ||
use PrestaShop\Module\AutoUpgrade\ErrorHandler; | ||
use PrestaShop\Module\AutoUpgrade\Log\CliLogger; | ||
use PrestaShop\Module\AutoUpgrade\Log\Logger; | ||
use PrestaShop\Module\AutoUpgrade\Log\StreamedLogger; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeContainer; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
abstract class AbstractCommand extends Command | ||
{ | ||
/** | ||
* @var Logger | ||
*/ | ||
protected $logger; | ||
/** | ||
* @var UpgradeContainer | ||
*/ | ||
protected $upgradeContainer; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
protected function setupContainer(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$this->logger = $output->isDecorated() ? new CliLogger($output) : new StreamedLogger(); | ||
if ($output->isQuiet()) { | ||
$this->logger->setFilter(Logger::ERROR); | ||
} elseif ($output->isVerbose()) { | ||
$this->logger->setFilter(Logger::DEBUG); | ||
} else { | ||
$this->logger->setFilter(Logger::INFO); | ||
} | ||
|
||
$prodRootDir = _PS_ROOT_DIR_; | ||
$this->logger->debug('Production root directory: ' . $prodRootDir); | ||
|
||
$adminDir = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . $input->getArgument('admin-dir'); | ||
$this->logger->debug('Admin directory: ' . $adminDir); | ||
define('_PS_ADMIN_DIR_', $adminDir); | ||
|
||
$this->upgradeContainer = new UpgradeContainer($prodRootDir, $adminDir); | ||
$this->logger->debug('Upgrade container initialized.'); | ||
|
||
$this->logger->debug('Logger initialized: ' . get_class($this->logger)); | ||
|
||
$this->upgradeContainer->setLogger($this->logger); | ||
(new ErrorHandler($this->logger))->enable(); | ||
$this->logger->debug('Error handler enabled.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/** | ||
* 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 [email protected] 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 <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Commands; | ||
|
||
use Exception; | ||
use PrestaShop\Module\AutoUpgrade\Task\ExitCode; | ||
use PrestaShop\Module\AutoUpgrade\Task\Runner\AllRollbackTasks; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class RestoreCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected static $defaultName = 'backup:restore'; | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Restore your store.') | ||
->setHelp( | ||
'This command allows you to restore your store from a backup.' . | ||
'See https://devdocs.prestashop-project.org/8/basics/keeping-up-to-date/upgrade-module/upgrade-cli/#rollback-cli for more details' | ||
) | ||
->addArgument('admin-dir', InputArgument::REQUIRED, 'The admin directory name.') | ||
->addOption('backup', null, InputOption::VALUE_REQUIRED, 'Specify the backup name to restore (this can be found in your folder <admin directory>/autoupgrade/backup/)'); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): ?int | ||
{ | ||
try { | ||
$this->setupContainer($input, $output); | ||
|
||
$backup = $input->getOption('backup'); | ||
|
||
if (!$backup) { | ||
$this->logger->error("The '--backup' option is required."); | ||
|
||
return ExitCode::FAIL; | ||
} | ||
|
||
$controller = new AllRollbackTasks($this->upgradeContainer); | ||
$controller->setOptions([ | ||
'backup' => $backup, | ||
]); | ||
$controller->init(); | ||
$exitCode = $controller->run(); | ||
$this->logger->debug('Process completed with exit code: ' . $exitCode); | ||
|
||
return $exitCode; | ||
} catch (Exception $e) { | ||
$this->logger->error('An error occurred during the restoration process: ' . $e->getMessage()); | ||
|
||
return ExitCode::FAIL; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.