diff options
author | Faraz Samapoor <fsa@adlas.at> | 2023-08-03 16:42:56 +0330 |
---|---|---|
committer | Faraz Samapoor <fsa@adlas.at> | 2023-08-03 16:42:56 +0330 |
commit | 90652fd30fcbe620d1b1bf87899eeae6f6c7c657 (patch) | |
tree | eb753d8cb166e9452d7ac4c92549116dddb60462 /apps/files_versions | |
parent | ab797062533bfac412eb9300c2ae01e380609b45 (diff) | |
download | nextcloud-server-90652fd30fcbe620d1b1bf87899eeae6f6c7c657.tar.gz nextcloud-server-90652fd30fcbe620d1b1bf87899eeae6f6c7c657.zip |
Uses early returns.
To improve code readability.
Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/lib/Command/CleanUp.php | 48 | ||||
-rw-r--r-- | apps/files_versions/lib/Command/ExpireVersions.php | 29 |
2 files changed, 40 insertions, 37 deletions
diff --git a/apps/files_versions/lib/Command/CleanUp.php b/apps/files_versions/lib/Command/CleanUp.php index 26a1c57ec74..2a19c57710e 100644 --- a/apps/files_versions/lib/Command/CleanUp.php +++ b/apps/files_versions/lib/Command/CleanUp.php @@ -75,37 +75,39 @@ class CleanUp extends Command { if (!empty($users)) { foreach ($users as $user) { - if ($this->userManager->userExists($user)) { - $output->writeln("Delete versions of <info>$user</info>"); - $this->deleteVersions($user, $path); - } else { + if (!$this->userManager->userExists($user)) { $output->writeln("<error>Unknown user $user</error>"); return self::FAILURE; } + + $output->writeln("Delete versions of <info>$user</info>"); + $this->deleteVersions($user, $path); } - } else { - $output->writeln('Delete all versions'); - foreach ($this->userManager->getBackends() as $backend) { - $name = get_class($backend); + return self::SUCCESS; + } - if ($backend instanceof IUserBackend) { - $name = $backend->getBackendName(); - } + $output->writeln('Delete all versions'); + foreach ($this->userManager->getBackends() as $backend) { + $name = get_class($backend); - $output->writeln("Delete versions for users on backend <info>$name</info>"); - - $limit = 500; - $offset = 0; - do { - $users = $backend->getUsers('', $limit, $offset); - foreach ($users as $user) { - $output->writeln(" <info>$user</info>"); - $this->deleteVersions($user); - } - $offset += $limit; - } while (count($users) >= $limit); + if ($backend instanceof IUserBackend) { + $name = $backend->getBackendName(); } + + $output->writeln("Delete versions for users on backend <info>$name</info>"); + + $limit = 500; + $offset = 0; + do { + $users = $backend->getUsers('', $limit, $offset); + foreach ($users as $user) { + $output->writeln(" <info>$user</info>"); + $this->deleteVersions($user); + } + $offset += $limit; + } while (count($users) >= $limit); } + return self::SUCCESS; } diff --git a/apps/files_versions/lib/Command/ExpireVersions.php b/apps/files_versions/lib/Command/ExpireVersions.php index 38c7929ff5b..d8e59b40dba 100644 --- a/apps/files_versions/lib/Command/ExpireVersions.php +++ b/apps/files_versions/lib/Command/ExpireVersions.php @@ -64,25 +64,26 @@ class ExpireVersions extends Command { $users = $input->getArgument('user_id'); if (!empty($users)) { foreach ($users as $user) { - if ($this->userManager->userExists($user)) { - $output->writeln("Remove deleted files of <info>$user</info>"); - $userObject = $this->userManager->get($user); - $this->expireVersionsForUser($userObject); - } else { + if (!$this->userManager->userExists($user)) { $output->writeln("<error>Unknown user $user</error>"); return self::FAILURE; } + + $output->writeln("Remove deleted files of <info>$user</info>"); + $userObject = $this->userManager->get($user); + $this->expireVersionsForUser($userObject); } - } else { - $p = new ProgressBar($output); - $p->start(); - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { - $p->advance(); - $this->expireVersionsForUser($user); - }); - $p->finish(); - $output->writeln(''); + return self::SUCCESS; } + + $p = new ProgressBar($output); + $p->start(); + $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { + $p->advance(); + $this->expireVersionsForUser($user); + }); + $p->finish(); + $output->writeln(''); return self::SUCCESS; } |