aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFaraz Samapoor <fsa@adlas.at>2023-08-03 14:50:33 +0330
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-08-16 09:33:16 +0200
commit6b795da540d50f2ca1e70a284a7367390621b50b (patch)
tree2417c3354de450f08ecd7a440bf0f5c86b098e80
parentfc8b886295caf898fd563d2bf54e6233615602d7 (diff)
downloadnextcloud-server-6b795da540d50f2ca1e70a284a7367390621b50b.tar.gz
nextcloud-server-6b795da540d50f2ca1e70a284a7367390621b50b.zip
Uses early returns.
To improve code readability. Signed-off-by: Faraz Samapoor <fsa@adlas.at>
-rw-r--r--apps/encryption/lib/Command/DisableMasterKey.php32
-rw-r--r--apps/encryption/lib/Command/EnableMasterKey.php24
-rw-r--r--apps/encryption/lib/Command/FixEncryptedVersion.php24
3 files changed, 43 insertions, 37 deletions
diff --git a/apps/encryption/lib/Command/DisableMasterKey.php b/apps/encryption/lib/Command/DisableMasterKey.php
index f74399ad322..1912d09728d 100644
--- a/apps/encryption/lib/Command/DisableMasterKey.php
+++ b/apps/encryption/lib/Command/DisableMasterKey.php
@@ -33,21 +33,23 @@ class DisableMasterKey extends Command {
if (!$isMasterKeyEnabled) {
$output->writeln('Master key already disabled');
- } else {
- $question = new ConfirmationQuestion(
- 'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
- . 'There is no way to enable the master key again. '
- . 'We strongly recommend to keep the master key, it provides significant performance improvements '
- . 'and is easier to handle for both, users and administrators. '
- . 'Do you really want to switch to per-user keys? (y/n) ', false);
- if ($this->questionHelper->ask($input, $output, $question)) {
- $this->config->setAppValue('encryption', 'useMasterKey', '0');
- $output->writeln('Master key successfully disabled.');
- } else {
- $output->writeln('aborted.');
- return self::FAILURE;
- }
+ return self::SUCCESS;
}
- return self::SUCCESS;
+
+ $question = new ConfirmationQuestion(
+ 'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
+ . 'There is no way to enable the master key again. '
+ . 'We strongly recommend to keep the master key, it provides significant performance improvements '
+ . 'and is easier to handle for both, users and administrators. '
+ . 'Do you really want to switch to per-user keys? (y/n) ', false);
+
+ if ($this->questionHelper->ask($input, $output, $question)) {
+ $this->config->setAppValue('encryption', 'useMasterKey', '0');
+ $output->writeln('Master key successfully disabled.');
+ return self::SUCCESS;
+ }
+
+ $output->writeln('aborted.');
+ return self::FAILURE;
}
}
diff --git a/apps/encryption/lib/Command/EnableMasterKey.php b/apps/encryption/lib/Command/EnableMasterKey.php
index cb709b80004..0d8b893e0e2 100644
--- a/apps/encryption/lib/Command/EnableMasterKey.php
+++ b/apps/encryption/lib/Command/EnableMasterKey.php
@@ -35,18 +35,20 @@ class EnableMasterKey extends Command {
if ($isAlreadyEnabled) {
$output->writeln('Master key already enabled');
- } else {
- $question = new ConfirmationQuestion(
- 'Warning: Only available for fresh installations with no existing encrypted data! '
+ return self::SUCCESS;
+ }
+
+ $question = new ConfirmationQuestion(
+ 'Warning: Only available for fresh installations with no existing encrypted data! '
. 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
- if ($this->questionHelper->ask($input, $output, $question)) {
- $this->config->setAppValue('encryption', 'useMasterKey', '1');
- $output->writeln('Master key successfully enabled.');
- } else {
- $output->writeln('aborted.');
- return self::FAILURE;
- }
+
+ if ($this->questionHelper->ask($input, $output, $question)) {
+ $this->config->setAppValue('encryption', 'useMasterKey', '1');
+ $output->writeln('Master key successfully enabled.');
+ return self::SUCCESS;
}
- return self::SUCCESS;
+
+ $output->writeln('aborted.');
+ return self::FAILURE;
}
}
diff --git a/apps/encryption/lib/Command/FixEncryptedVersion.php b/apps/encryption/lib/Command/FixEncryptedVersion.php
index faeb0348222..d2764036b39 100644
--- a/apps/encryption/lib/Command/FixEncryptedVersion.php
+++ b/apps/encryption/lib/Command/FixEncryptedVersion.php
@@ -79,6 +79,11 @@ class FixEncryptedVersion extends Command {
$all = $input->getOption('all');
$pathOption = \trim(($input->getOption('path') ?? ''), '/');
+ if (!$user && !$all) {
+ $output->writeln("Either a user id or --all needs to be provided");
+ return self::FAILURE;
+ }
+
if ($user) {
if ($all) {
$output->writeln("Specifying a user id and --all are mutually exclusive");
@@ -91,18 +96,15 @@ class FixEncryptedVersion extends Command {
}
return $this->runForUser($user, $pathOption, $output);
- } elseif ($all) {
- $result = 0;
- $this->userManager->callForSeenUsers(function (IUser $user) use ($pathOption, $output, &$result) {
- $output->writeln("Processing files for " . $user->getUID());
- $result = $this->runForUser($user->getUID(), $pathOption, $output);
- return $result === 0;
- });
- return $result;
- } else {
- $output->writeln("Either a user id or --all needs to be provided");
- return self::FAILURE;
}
+
+ $result = 0;
+ $this->userManager->callForSeenUsers(function (IUser $user) use ($pathOption, $output, &$result) {
+ $output->writeln("Processing files for " . $user->getUID());
+ $result = $this->runForUser($user->getUID(), $pathOption, $output);
+ return $result === 0;
+ });
+ return $result;
}
private function runForUser(string $user, string $pathOption, OutputInterface $output): int {