From eb4aa23577b42a268c5475887a4b8a3c2a6bea6d Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Tue, 9 Jul 2019 03:03:27 +0200 Subject: [PATCH] allow non-interactive installation (#932) --- src/Command/InstallCommand.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index b152096e..964508fa 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -76,16 +76,9 @@ class InstallCommand extends Command { $io = new SymfonyStyle($input, $output); - $io->title('Welcome to the interactive Kimai installer!'); + $io->title('Kimai installer - v' . Constants::VERSION); - if (!$input->isInteractive()) { - $io->error('Installation only works in interactive mode'); - - return self::ERROR_INTERACTIVE; - } - - $rows = $this->checkPermissions(); - $result = $this->confirmAbortToReviewPermissions($io, $input, $output, $rows); + $result = $this->reviewPermissions($io, $input, $output); if (true !== $result) { return $result; } @@ -95,7 +88,6 @@ class InstallCommand extends Command // $io->note(sprintf('You have chosen the "%s" environment', $environment)); $environment = getenv('APP_ENV'); - // create database if necessary try { $this->createDatabase($io, $input, $output); } catch (\Exception $ex) { @@ -132,8 +124,11 @@ class InstallCommand extends Command protected function rebuildCaches(string $environment, SymfonyStyle $io, InputInterface $input, OutputInterface $output) { - if (!$this->askConfirmation($input, $output, 'Do you want me to rebuild the caches (yes) or skip this step (no)?', true)) { - return; + if ($input->isInteractive()) { + $question = 'Do you want me to rebuild the caches (yes) or skip this step (no)?'; + if (!$this->askConfirmation($input, $output, $question, true)) { + return; + } } $io->text('Rebuilding your cache now, please be patient ...'); @@ -196,8 +191,14 @@ class InstallCommand extends Command return $rows; } - protected function confirmAbortToReviewPermissions(SymfonyStyle $io, InputInterface $input, OutputInterface $output, array $permissions) + protected function reviewPermissions(SymfonyStyle $io, InputInterface $input, OutputInterface $output) { + if (!$input->isInteractive()) { + return true; + } + + $permissions = $this->checkPermissions(); + if (empty($permissions)) { return true; } @@ -217,6 +218,8 @@ class InstallCommand extends Command return self::ERROR_PERMISSIONS; } $io->writeln(''); + + return true; } protected function importMigrations(SymfonyStyle $io, OutputInterface $output)