From 7a4cc21f8eaac1462fc304e229e98aaa191d8e86 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 28 Sep 2022 11:38:29 +0200 Subject: [PATCH] Allow adding file as argument in restore --- src/Console/RestoreDatabase.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Console/RestoreDatabase.php b/src/Console/RestoreDatabase.php index 8a561d9..5f7c220 100644 --- a/src/Console/RestoreDatabase.php +++ b/src/Console/RestoreDatabase.php @@ -29,21 +29,24 @@ class RestoreDatabase extends Command protected function configure(): void { $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('file', InputArgument::OPTIONAL, 'Backup file name'); } protected function execute(InputInterface $input, OutputInterface $output): int { $question = $this->getHelper('question'); $db = $this->getDatabaseName($input, $output); - - $finder = new Finder(); - $finder->in(__DIR__ . '/../..'); - $files = [sprintf('%s_backup.sql', $db)]; - foreach ($finder->files()->name('*_backup.sql') as $file) { - $files[] = $file->getFilename(); + $fileName = $input->getArgument('file'); + if (!$fileName){ + $finder = new Finder(); + $finder->in(__DIR__ . '/../..'); + $files = [sprintf('%s_backup.sql', $db)]; + foreach ($finder->files()->name('*_backup.sql') as $file) { + $files[] = $file->getFilename(); + } + $selectQuestion = new ChoiceQuestion('Backup name (*_backup.sql): ', $files); + $fileName = $question->ask($input, $output, $selectQuestion); } - $selectQuestion = new ChoiceQuestion('Backup name (*_backup.sql): ', $files); - $fileName = $question->ask($input, $output, $selectQuestion); $this->bs->restore($db, $fileName);