aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Command/ExpireTrash.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/lib/Command/ExpireTrash.php')
-rw-r--r--apps/files_trashbin/lib/Command/ExpireTrash.php75
1 files changed, 27 insertions, 48 deletions
diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php
index bcecbfceeff..422d8379984 100644
--- a/apps/files_trashbin/lib/Command/ExpireTrash.php
+++ b/apps/files_trashbin/lib/Command/ExpireTrash.php
@@ -1,35 +1,18 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud GmbH.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud GmbH.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
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;
@@ -39,25 +22,15 @@ use Symfony\Component\Console\Output\OutputInterface;
class ExpireTrash extends Command {
/**
- * @var Expiration
- */
- private $expiration;
-
- /**
- * @var IUserManager
- */
- private $userManager;
-
- /**
* @param IUserManager|null $userManager
* @param Expiration|null $expiration
*/
- public function __construct(IUserManager $userManager = null,
- Expiration $expiration = null) {
+ public function __construct(
+ private LoggerInterface $logger,
+ private ?IUserManager $userManager = null,
+ private ?Expiration $expiration = null,
+ ) {
parent::__construct();
-
- $this->userManager = $userManager;
- $this->expiration = $expiration;
}
protected function configure() {
@@ -72,9 +45,10 @@ class ExpireTrash extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
+ $minAge = $this->expiration->getMinAgeAsTimestamp();
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
- if (!$maxAge) {
- $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)");
+ 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;
}
@@ -93,10 +67,12 @@ class ExpireTrash extends Command {
} else {
$p = new ProgressBar($output);
$p->start();
- $this->userManager->callForSeenUsers(function (IUser $user) use ($p) {
+
+ $users = $this->userManager->getSeenUsers();
+ foreach ($users as $user) {
$p->advance();
$this->expireTrashForUser($user);
- });
+ }
$p->finish();
$output->writeln('');
}
@@ -104,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);
}
/**
@@ -122,7 +101,7 @@ class ExpireTrash extends Command {
\OC_Util::setupFS($user);
// Check if this user has a trashbin directory
- $view = new \OC\Files\View('/' . $user);
+ $view = new View('/' . $user);
if (!$view->is_dir('/files_trashbin/files')) {
return false;
}