From 4193991c77b33676ab591718b852b698080d2dc7 Mon Sep 17 00:00:00 2001 From: Bartosz Kubicki Date: Fri, 12 Jan 2024 17:34:34 +0100 Subject: [PATCH] ISSUE-15 Asking for confirmation before import command is executed --- src/Console/ImportFromRemoteCommand.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Console/ImportFromRemoteCommand.php b/src/Console/ImportFromRemoteCommand.php index 2a87984..0147d53 100644 --- a/src/Console/ImportFromRemoteCommand.php +++ b/src/Console/ImportFromRemoteCommand.php @@ -4,11 +4,13 @@ namespace Jh\StrippedDbProvider\Console; +use Exception; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Question\ConfirmationQuestion; use Jh\StrippedDbProvider\Model\DbFacade; use Jh\StrippedDbProvider\Model\ProjectMeta; @@ -50,6 +52,17 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output): int { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + 'Are you sure you want to import database from S3? It will override current environment database [yes/no]', + false, + '/^yes/i' + ); + + if (!$helper->ask($input, $output, $question)) { + return Command::SUCCESS; + } + try { $sourceProjectMeta = new ProjectMeta($input->getArgument(self::ARGUMENT_PROJECT_NAME)); $backupAdminAccounts = !$input->getOption(self::OPTION_NO_ADMIN_ACCOUNT_BACKUP); @@ -77,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Restoring local admin accounts ...'); $this->dbFacade->restoreLocalAdminAccountsFromBackup($sourceProjectMeta); } - } catch (\Exception $e) { + } catch (Exception $e) { $output->writeln("{$e->getMessage()}"); } finally { if (isset($sourceProjectMeta)) { @@ -87,6 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->dbFacade->cleanUpAdminAccountsBackup($sourceProjectMeta); } } - return 0; + + return Command::SUCCESS; } }