diff options
Diffstat (limited to 'apps/files_trashbin/lib/Command/ExpireTrash.php')
-rw-r--r-- | apps/files_trashbin/lib/Command/ExpireTrash.php | 26 |
1 files changed, 17 insertions, 9 deletions
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); } /** |