Skip to content

Commit

Permalink
Merge pull request #19 from WeareJH/chore/ISSUE-15-confirmation-requi…
Browse files Browse the repository at this point in the history
…red-for-import-command

ISSUE-15 Asking for confirmation before import command is executed
  • Loading branch information
bartoszkubicki committed Jan 15, 2024
2 parents 2f5e194 + 4193991 commit eb597f7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Console/ImportFromRemoteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -77,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('<fg=cyan;options=bold>Restoring local admin accounts ...</>');
$this->dbFacade->restoreLocalAdminAccountsFromBackup($sourceProjectMeta);
}
} catch (\Exception $e) {
} catch (Exception $e) {
$output->writeln("<error>{$e->getMessage()}</error>");
} finally {
if (isset($sourceProjectMeta)) {
Expand All @@ -87,6 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->dbFacade->cleanUpAdminAccountsBackup($sourceProjectMeta);
}
}
return 0;

return Command::SUCCESS;
}
}

0 comments on commit eb597f7

Please sign in to comment.