Skip to content
45 changes: 24 additions & 21 deletions core/Command/Encryption/EncryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ protected function configure() {
);
}

/**
* @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;
}

Comment thread
yemkareems marked this conversation as resolved.
if ($this->encryptionManager->isEnabled() === false) {
throw new \Exception('Server side encryption is not enabled');
}
Expand All @@ -84,21 +78,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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();
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()) {
Comment thread
yemkareems marked this conversation as resolved.
Outdated
//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;
}

try {
$defaultModule = $this->encryptionManager->getEncryptionModule();
$defaultModule->encryptAll($input, $output);
} catch (\Exception $ex) {
$this->resetMaintenanceAndTrashbin();
throw $ex;
}
private function runEncryption(InputInterface $input, OutputInterface $output): int {
Comment thread
yemkareems marked this conversation as resolved.
Outdated
$this->forceMaintenanceAndTrashbin();

try {
$defaultModule = $this->encryptionManager->getEncryptionModule();
$defaultModule->encryptAll($input, $output);
} catch (\Exception $ex) {
$this->resetMaintenanceAndTrashbin();
return self::SUCCESS;
throw $ex;
}
$output->writeln('aborted');
return self::FAILURE;

$this->resetMaintenanceAndTrashbin();
return self::SUCCESS;
}
}
Loading