mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix: support -n option to encrypt-all command to allow to run in non-interactive mode
Signed-off-by: yemkareems <yemkareems@gmail.com>
This commit is contained in:
parent
b3fd79fff3
commit
7e546c8377
1 changed files with 25 additions and 22 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue