Skip to content

Commit

Permalink
Merge pull request #49433 from nextcloud/artonge/feat/maintenance_war…
Browse files Browse the repository at this point in the history
…n_encrypt_all

feat: Warn about maintenance in EncryptAll command
  • Loading branch information
artonge authored Nov 25, 2024
2 parents 8502fe4 + 590b1e8 commit aa393aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
13 changes: 8 additions & 5 deletions core/Command/Encryption/EncryptAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class EncryptAll extends Command {
protected bool $wasTrashbinEnabled = false;
protected bool $wasMaintenanceModeEnabled = false;

public function __construct(
protected IManager $encryptionManager,
Expand All @@ -33,7 +32,6 @@ public function __construct(
*/
protected function forceMaintenanceAndTrashbin(): void {
$this->wasTrashbinEnabled = (bool)$this->appManager->isEnabledForUser('files_trashbin');
$this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance');
$this->config->setSystemValue('maintenance', true);
$this->appManager->disableApp('files_trashbin');
}
Expand All @@ -42,7 +40,7 @@ protected function forceMaintenanceAndTrashbin(): void {
* Reset the maintenance mode and re-enable the trashbin app
*/
protected function resetMaintenanceAndTrashbin(): void {
$this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled);
$this->config->setSystemValue('maintenance', false);
if ($this->wasTrashbinEnabled) {
$this->appManager->enableApp('files_trashbin');
}
Expand Down Expand Up @@ -73,6 +71,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new \Exception('Server side encryption is not enabled');
}

if ($this->config->getSystemValueBool('maintenance')) {
$output->writeln('<error>This command cannot be run with maintenance mode enabled.</error>');
return self::FAILURE;
}

$output->writeln("\n");
$output->writeln('You are about to encrypt all files stored in your Nextcloud installation.');
$output->writeln('Depending on the number of available files, and their size, this may take quite some time.');
Expand All @@ -92,9 +95,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$this->resetMaintenanceAndTrashbin();
return 0;
return self::SUCCESS;
}
$output->writeln('aborted');
return 1;
return self::FAILURE;
}
}
9 changes: 0 additions & 9 deletions tests/Core/Command/Encryption/EncryptAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ public function testEncryptAll(): void {
// trash bin needs to be disabled in order to avoid adding dummy files to the users
// trash bin which gets deleted during the encryption process
$this->appManager->expects($this->once())->method('disableApp')->with('files_trashbin');
// enable single user mode to avoid that other user login during encryption
// destructor should disable the single user mode again
$this->config->expects($this->once())->method('getSystemValueBool')->with('maintenance', false)->willReturn(false);
$this->config->expects($this->exactly(2))
->method('setSystemValue')
->withConsecutive(
['maintenance', true],
['maintenance', false],
);

$instance = new EncryptAll($this->encryptionManager, $this->appManager, $this->config, $this->questionHelper);
$this->invokePrivate($instance, 'forceMaintenanceAndTrashbin');
Expand Down

0 comments on commit aa393aa

Please sign in to comment.