aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorFaraz Samapoor <fsa@adlas.at>2023-08-03 16:35:09 +0330
committerFaraz Samapoor <fsa@adlas.at>2023-08-03 16:35:09 +0330
commitab797062533bfac412eb9300c2ae01e380609b45 (patch)
tree8a7be677f0c28ce339a2963ff29d10258f2f618d /apps/files_versions
parent9e096ef430b188793d0ce8865fd57de44d495896 (diff)
downloadnextcloud-server-ab797062533bfac412eb9300c2ae01e380609b45.tar.gz
nextcloud-server-ab797062533bfac412eb9300c2ae01e380609b45.zip
Refactors files_version app commands.
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.php29
-rw-r--r--apps/files_versions/lib/Command/Expire.php21
-rw-r--r--apps/files_versions/lib/Command/ExpireVersions.php38
3 files changed, 24 insertions, 64 deletions
diff --git a/apps/files_versions/lib/Command/CleanUp.php b/apps/files_versions/lib/Command/CleanUp.php
index d7bb4caa483..26a1c57ec74 100644
--- a/apps/files_versions/lib/Command/CleanUp.php
+++ b/apps/files_versions/lib/Command/CleanUp.php
@@ -34,24 +34,14 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CleanUp extends Command {
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IRootFolder */
- protected $rootFolder;
-
- /**
- * @param IRootFolder $rootFolder
- * @param IUserManager $userManager
- */
- public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
+ public function __construct(
+ protected IRootFolder $rootFolder,
+ protected IUserManager $userManager,
+ ) {
parent::__construct();
- $this->userManager = $userManager;
- $this->rootFolder = $rootFolder;
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('versions:cleanup')
->setDescription('Delete versions')
@@ -76,7 +66,7 @@ class CleanUp extends Command {
if ($path) {
if (!preg_match('#^/([^/]+)/files(/.*)?$#', $path, $pathMatches)) {
$output->writeln("<error>Invalid path given</error>");
- return 1;
+ return self::FAILURE;
}
$users = [ $pathMatches[1] ];
@@ -90,7 +80,7 @@ class CleanUp extends Command {
$this->deleteVersions($user, $path);
} else {
$output->writeln("<error>Unknown user $user</error>");
- return 1;
+ return self::FAILURE;
}
}
} else {
@@ -116,15 +106,12 @@ class CleanUp extends Command {
} while (count($users) >= $limit);
}
}
- return 0;
+ return self::SUCCESS;
}
/**
* delete versions for the given user
- *
- * @param string $user
- * @param string|null $path
*/
protected function deleteVersions(string $user, string $path = null): void {
\OC_Util::tearDownFS();
diff --git a/apps/files_versions/lib/Command/Expire.php b/apps/files_versions/lib/Command/Expire.php
index 62b2343a5e0..3744df10093 100644
--- a/apps/files_versions/lib/Command/Expire.php
+++ b/apps/files_versions/lib/Command/Expire.php
@@ -33,22 +33,13 @@ use Psr\Log\LoggerInterface;
class Expire implements ICommand {
use FileAccess;
- /**
- * @var string
- */
- private $fileName;
-
- /**
- * @var string
- */
- private $user;
-
- public function __construct(string $user, string $fileName) {
- $this->user = $user;
- $this->fileName = $fileName;
+ public function __construct(
+ private string $user,
+ private string $fileName,
+ ) {
}
- public function handle() {
+ public function handle(): void {
/** @var IUserManager $userManager */
$userManager = \OC::$server->get(IUserManager::class);
if (!$userManager->userExists($this->user)) {
@@ -62,7 +53,7 @@ class Expire implements ICommand {
// In case of external storage and session credentials, the expiration
// fails because the command does not have those credentials
- /** @var LoggerInterface */
+ /** @var LoggerInterface $logger */
$logger = \OC::$server->get(LoggerInterface::class);
$logger->warning($e->getMessage(), [
'exception' => $e,
diff --git a/apps/files_versions/lib/Command/ExpireVersions.php b/apps/files_versions/lib/Command/ExpireVersions.php
index 43068e21451..38c7929ff5b 100644
--- a/apps/files_versions/lib/Command/ExpireVersions.php
+++ b/apps/files_versions/lib/Command/ExpireVersions.php
@@ -36,30 +36,14 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExpireVersions extends Command {
-
- /**
- * @var Expiration
- */
- private $expiration;
-
- /**
- * @var IUserManager
- */
- private $userManager;
-
- /**
- * @param IUserManager $userManager
- * @param Expiration $expiration
- */
- public function __construct(IUserManager $userManager,
- Expiration $expiration) {
+ public function __construct(
+ private IUserManager $userManager,
+ private Expiration $expiration,
+ ) {
parent::__construct();
-
- $this->userManager = $userManager;
- $this->expiration = $expiration;
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('versions:expire')
->setDescription('Expires the users file versions')
@@ -74,7 +58,7 @@ class ExpireVersions extends Command {
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
$output->writeln("Auto expiration is configured - expiration will be handled automatically according to the expiration patterns detailed at the following link https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/file_versioning.html.");
- return 1;
+ return self::FAILURE;
}
$users = $input->getArgument('user_id');
@@ -86,7 +70,7 @@ class ExpireVersions extends Command {
$this->expireVersionsForUser($userObject);
} else {
$output->writeln("<error>Unknown user $user</error>");
- return 1;
+ return self::FAILURE;
}
}
} else {
@@ -99,10 +83,10 @@ class ExpireVersions extends Command {
$p->finish();
$output->writeln('');
}
- return 0;
+ return self::SUCCESS;
}
- public function expireVersionsForUser(IUser $user) {
+ public function expireVersionsForUser(IUser $user): void {
$uid = $user->getUID();
if (!$this->setupFS($uid)) {
return;
@@ -112,10 +96,8 @@ class ExpireVersions extends Command {
/**
* Act on behalf on versions item owner
- * @param string $user
- * @return boolean
*/
- protected function setupFS($user) {
+ protected function setupFS(string $user): bool {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user);