Skip to content

Commit 7e546c8

Browse files
committed
fix: support -n option to encrypt-all command to allow to run in non-interactive mode
Signed-off-by: yemkareems <[email protected]>
1 parent b3fd79f commit 7e546c8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

core/Command/Encryption/EncryptAll.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,10 @@ protected function configure() {
5858
);
5959
}
6060

61+
/**
62+
* @throws \Exception
63+
*/
6164
protected function execute(InputInterface $input, OutputInterface $output): int {
62-
if (!$input->isInteractive()) {
63-
$output->writeln('Invalid TTY.');
64-
$output->writeln('If you are trying to execute the command in a Docker ');
65-
$output->writeln("container, do not forget to execute 'docker exec' with");
66-
$output->writeln("the '-i' and '-t' options.");
67-
$output->writeln('');
68-
return 1;
69-
}
70-
7165
if ($this->encryptionManager->isEnabled() === false) {
7266
throw new \Exception('Server side encryption is not enabled');
7367
}
@@ -84,21 +78,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8478
$output->writeln('Note: The encryption module you use determines which files get encrypted.');
8579
$output->writeln('');
8680
$question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
87-
if ($this->questionHelper->ask($input, $output, $question)) {
88-
$this->forceMaintenanceAndTrashbin();
81+
if ($input->isInteractive() && $this->questionHelper->ask($input, $output, $question)) {
82+
//run encryption with the answer yes in interactive mode
83+
return $this->runEncryption($input, $output);
84+
} elseif (!$input->isInteractive()) {
85+
//run encryption without the question in non-interactive mode if -n option is available
86+
return $this->runEncryption($input, $output);
87+
}
88+
//abort on no in interactive mode
89+
$output->writeln('aborted');
90+
return self::FAILURE;
91+
}
8992

90-
try {
91-
$defaultModule = $this->encryptionManager->getEncryptionModule();
92-
$defaultModule->encryptAll($input, $output);
93-
} catch (\Exception $ex) {
94-
$this->resetMaintenanceAndTrashbin();
95-
throw $ex;
96-
}
93+
private function runEncryption(InputInterface $input, OutputInterface $output): int {
94+
$this->forceMaintenanceAndTrashbin();
9795

96+
try {
97+
$defaultModule = $this->encryptionManager->getEncryptionModule();
98+
$defaultModule->encryptAll($input, $output);
99+
} catch (\Exception $ex) {
98100
$this->resetMaintenanceAndTrashbin();
99-
return self::SUCCESS;
101+
throw $ex;
100102
}
101-
$output->writeln('aborted');
102-
return self::FAILURE;
103+
104+
$this->resetMaintenanceAndTrashbin();
105+
return self::SUCCESS;
103106
}
104107
}

0 commit comments

Comments
 (0)