diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php index f2c991471b6..4e1dec4de50 100644 --- a/core/Command/Encryption/EncryptAll.php +++ b/core/Command/Encryption/EncryptAll.php @@ -58,16 +58,10 @@ class EncryptAll extends Command { ); } + /** + * @throws \Exception + */ protected function execute(InputInterface $input, OutputInterface $output): int { - if (!$input->isInteractive()) { - $output->writeln('Invalid TTY.'); - $output->writeln('If you are trying to execute the command in a Docker '); - $output->writeln("container, do not forget to execute 'docker exec' with"); - $output->writeln("the '-i' and '-t' options."); - $output->writeln(''); - return 1; - } - if ($this->encryptionManager->isEnabled() === false) { throw new \Exception('Server side encryption is not enabled'); } @@ -84,21 +78,30 @@ class EncryptAll extends Command { $output->writeln('Note: The encryption module you use determines which files get encrypted.'); $output->writeln(''); $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); - if ($this->questionHelper->ask($input, $output, $question)) { - $this->forceMaintenanceAndTrashbin(); - - try { - $defaultModule = $this->encryptionManager->getEncryptionModule(); - $defaultModule->encryptAll($input, $output); - } catch (\Exception $ex) { - $this->resetMaintenanceAndTrashbin(); - throw $ex; - } - - $this->resetMaintenanceAndTrashbin(); - return self::SUCCESS; + if ($input->isInteractive() && $this->questionHelper->ask($input, $output, $question)) { + //run encryption with the answer yes in interactive mode + return $this->runEncryption($input, $output); + } elseif (!$input->isInteractive()) { + //run encryption without the question in non-interactive mode if -n option is available + return $this->runEncryption($input, $output); } + //abort on no in interactive mode $output->writeln('aborted'); return self::FAILURE; } + + private function runEncryption(InputInterface $input, OutputInterface $output): int { + $this->forceMaintenanceAndTrashbin(); + + try { + $defaultModule = $this->encryptionManager->getEncryptionModule(); + $defaultModule->encryptAll($input, $output); + } catch (\Exception $ex) { + $this->resetMaintenanceAndTrashbin(); + throw $ex; + } + + $this->resetMaintenanceAndTrashbin(); + return self::SUCCESS; + } }