aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis <louis@chmn.me>2024-11-25 12:10:12 +0100
committerGitHub <noreply@github.com>2024-11-25 12:10:12 +0100
commitaa393aa7441ed0cf684af6340f2418e04b51e675 (patch)
treec84e9d690d09c5a1b38264fdcd3a056ca4d548af
parent8502fe48c2d8c2a96c8ca5f66ff3136c02ef3390 (diff)
parent590b1e8698f459b00a98267ba65fa6825a7e0f8a (diff)
downloadnextcloud-server-aa393aa7441ed0cf684af6340f2418e04b51e675.tar.gz
nextcloud-server-aa393aa7441ed0cf684af6340f2418e04b51e675.zip
Merge pull request #49433 from nextcloud/artonge/feat/maintenance_warn_encrypt_all
feat: Warn about maintenance in EncryptAll command
-rw-r--r--core/Command/Encryption/EncryptAll.php13
-rw-r--r--tests/Core/Command/Encryption/EncryptAllTest.php9
2 files changed, 8 insertions, 14 deletions
diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php
index 868c240e26d..684591f4586 100644
--- a/core/Command/Encryption/EncryptAll.php
+++ b/core/Command/Encryption/EncryptAll.php
@@ -17,7 +17,6 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
class EncryptAll extends Command {
protected bool $wasTrashbinEnabled = false;
- protected bool $wasMaintenanceModeEnabled = false;
public function __construct(
protected IManager $encryptionManager,
@@ -33,7 +32,6 @@ class EncryptAll extends Command {
*/
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');
}
@@ -42,7 +40,7 @@ class EncryptAll extends Command {
* 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');
}
@@ -73,6 +71,11 @@ class EncryptAll extends Command {
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.');
@@ -92,9 +95,9 @@ class EncryptAll extends Command {
}
$this->resetMaintenanceAndTrashbin();
- return 0;
+ return self::SUCCESS;
}
$output->writeln('aborted');
- return 1;
+ return self::FAILURE;
}
}
diff --git a/tests/Core/Command/Encryption/EncryptAllTest.php b/tests/Core/Command/Encryption/EncryptAllTest.php
index 933f919ba7f..6e72e87b973 100644
--- a/tests/Core/Command/Encryption/EncryptAllTest.php
+++ b/tests/Core/Command/Encryption/EncryptAllTest.php
@@ -71,15 +71,6 @@ class EncryptAllTest extends TestCase {
// 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');