aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/lib/Command')
-rw-r--r--apps/files_trashbin/lib/Command/CleanUp.php3
-rw-r--r--apps/files_trashbin/lib/Command/Expire.php5
-rw-r--r--apps/files_trashbin/lib/Command/ExpireTrash.php26
-rw-r--r--apps/files_trashbin/lib/Command/RestoreAllFiles.php1
-rw-r--r--apps/files_trashbin/lib/Command/Size.php9
5 files changed, 29 insertions, 15 deletions
diff --git a/apps/files_trashbin/lib/Command/CleanUp.php b/apps/files_trashbin/lib/Command/CleanUp.php
index daaa4003f7a..e9b4fa8ae60 100644
--- a/apps/files_trashbin/lib/Command/CleanUp.php
+++ b/apps/files_trashbin/lib/Command/CleanUp.php
@@ -11,6 +11,7 @@ use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IUserBackend;
use OCP\IUserManager;
+use OCP\Util;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputArgument;
@@ -96,7 +97,7 @@ class CleanUp extends Command {
$node = $this->rootFolder->get($path);
if ($verbose) {
- $output->writeln('Deleting <info>' . \OC_Helper::humanFileSize($node->getSize()) . "</info> in trash for <info>$uid</info>.");
+ $output->writeln('Deleting <info>' . Util::humanFileSize($node->getSize()) . "</info> in trash for <info>$uid</info>.");
}
$node->delete();
if ($this->rootFolder->nodeExists($path)) {
diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php
index f526438600e..73a42cd4749 100644
--- a/apps/files_trashbin/lib/Command/Expire.php
+++ b/apps/files_trashbin/lib/Command/Expire.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -9,6 +10,8 @@ namespace OCA\Files_Trashbin\Command;
use OC\Command\FileAccess;
use OCA\Files_Trashbin\Trashbin;
use OCP\Command\ICommand;
+use OCP\IUserManager;
+use OCP\Server;
class Expire implements ICommand {
use FileAccess;
@@ -22,7 +25,7 @@ class Expire implements ICommand {
}
public function handle() {
- $userManager = \OC::$server->getUserManager();
+ $userManager = Server::get(IUserManager::class);
if (!$userManager->userExists($this->user)) {
// User has been deleted already
return;
diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php
index 37b35689666..422d8379984 100644
--- a/apps/files_trashbin/lib/Command/ExpireTrash.php
+++ b/apps/files_trashbin/lib/Command/ExpireTrash.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH.
@@ -8,10 +9,10 @@ namespace OCA\Files_Trashbin\Command;
use OC\Files\View;
use OCA\Files_Trashbin\Expiration;
-use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
use OCP\IUser;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
@@ -25,6 +26,7 @@ class ExpireTrash extends Command {
* @param Expiration|null $expiration
*/
public function __construct(
+ private LoggerInterface $logger,
private ?IUserManager $userManager = null,
private ?Expiration $expiration = null,
) {
@@ -43,8 +45,9 @@ class ExpireTrash extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
+ $minAge = $this->expiration->getMinAgeAsTimestamp();
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
- if (!$maxAge) {
+ if ($minAge === false && $maxAge === false) {
$output->writeln('Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)');
return 1;
}
@@ -64,10 +67,12 @@ class ExpireTrash extends Command {
} else {
$p = new ProgressBar($output);
$p->start();
- $this->userManager->callForSeenUsers(function (IUser $user) use ($p): void {
+
+ $users = $this->userManager->getSeenUsers();
+ foreach ($users as $user) {
$p->advance();
$this->expireTrashForUser($user);
- });
+ }
$p->finish();
$output->writeln('');
}
@@ -75,12 +80,15 @@ class ExpireTrash extends Command {
}
public function expireTrashForUser(IUser $user) {
- $uid = $user->getUID();
- if (!$this->setupFS($uid)) {
- return;
+ try {
+ $uid = $user->getUID();
+ if (!$this->setupFS($uid)) {
+ return;
+ }
+ Trashbin::expire($uid);
+ } catch (\Throwable $e) {
+ $this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
}
- $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
- Trashbin::deleteExpiredFiles($dirContent, $uid);
}
/**
diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
index cb4e7f97ecd..ce31f759c0e 100644
--- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php
+++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
diff --git a/apps/files_trashbin/lib/Command/Size.php b/apps/files_trashbin/lib/Command/Size.php
index 11699ce25ea..9c19d4d92b3 100644
--- a/apps/files_trashbin/lib/Command/Size.php
+++ b/apps/files_trashbin/lib/Command/Size.php
@@ -13,6 +13,7 @@ use OCP\Command\IBus;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\Util;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -45,7 +46,7 @@ class Size extends Base {
$size = $input->getArgument('size');
if ($size) {
- $parsedSize = \OC_Helper::computerFileSize($size);
+ $parsedSize = Util::computerFileSize($size);
if ($parsedSize === false) {
$output->writeln('<error>Failed to parse input size</error>');
return -1;
@@ -70,7 +71,7 @@ class Size extends Base {
if ($globalSize < 0) {
$globalHumanSize = 'default (50% of available space)';
} else {
- $globalHumanSize = \OC_Helper::humanFileSize($globalSize);
+ $globalHumanSize = Util::humanFileSize($globalSize);
}
if ($user) {
@@ -79,7 +80,7 @@ class Size extends Base {
if ($userSize < 0) {
$userHumanSize = ($globalSize < 0) ? $globalHumanSize : "default($globalHumanSize)";
} else {
- $userHumanSize = \OC_Helper::humanFileSize($userSize);
+ $userHumanSize = Util::humanFileSize($userSize);
}
if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) {
@@ -106,7 +107,7 @@ class Size extends Base {
if (count($userValues)) {
$output->writeln('Per-user sizes:');
$this->writeArrayInOutputFormat($input, $output, array_map(function ($size) {
- return \OC_Helper::humanFileSize($size);
+ return Util::humanFileSize($size);
}, $userValues));
} else {
$output->writeln('No per-user sizes configured');