fix: removed the -n option from options, added the check and made default answer to both questions true to support -n run directly

Signed-off-by: yemkareems <yemkareems@gmail.com>
This commit is contained in:
yemkareems 2025-11-19 15:52:47 +05:30
parent d420b3f157
commit 26e2ff9dca
No known key found for this signature in database
GPG key ID: 4293DA00B9478934
2 changed files with 13 additions and 17 deletions

View file

@ -278,12 +278,8 @@ class EncryptAll {
$this->writePasswordsToFile($newPasswords);
$this->output->writeln('');
if ($this->input->isInteractive()) {
$question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false);
if ($this->questionHelper->ask($this->input, $this->output, $question)) {
$this->sendPasswordsByMail();
}
} elseif (!$this->input->isInteractive() && $this->input->getOption('no-interaction')) {
$question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', true);
if ($this->questionHelper->ask($this->input, $this->output, $question)) {
$this->sendPasswordsByMail();
}
}

View file

@ -56,11 +56,6 @@ class EncryptAll extends Command {
$this->setHelp(
'This will encrypt all files for all users. '
. 'Please make sure that no user access his files during this process!'
)->addOption(
'no-interaction',
'n',
InputOption::VALUE_NONE,
'Do not ask any interactive question'
);
}
@ -68,6 +63,15 @@ class EncryptAll extends Command {
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
if (!$input->isInteractive() && !$input->getOption('no-interaction')) {
$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');
}
@ -83,14 +87,10 @@ class EncryptAll extends Command {
$output->writeln('Please ensure that no user accesses their files during this time!');
$output->writeln('Note: The encryption module you use determines which files get encrypted.');
$output->writeln('');
$isNoInteraction = $input->getOption('no-interaction');
$question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
if ($input->isInteractive() && $this->questionHelper->ask($input, $output, $question)) {
$question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', true);
if ($this->questionHelper->ask($input, $output, $question)) {
//run encryption with the answer yes in interactive mode
return $this->runEncryption($input, $output);
} elseif (!$input->isInteractive() && $isNoInteraction) {
//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');