aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php')
-rw-r--r--apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php43
1 files changed, 29 insertions, 14 deletions
diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
index 4e1c1b95fde..bb383dab78d 100644
--- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
+++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -12,15 +13,16 @@ use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
-use OCP\IConfig;
-use OCP\IUser;
+use OCP\IAppConfig;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
class ExpireTrash extends TimedJob {
public function __construct(
- private IConfig $config,
+ private IAppConfig $appConfig,
private IUserManager $userManager,
private Expiration $expiration,
+ private LoggerInterface $logger,
ITimeFactory $time,
) {
parent::__construct($time);
@@ -28,12 +30,8 @@ class ExpireTrash extends TimedJob {
$this->setInterval(60 * 30);
}
- /**
- * @param $argument
- * @throws \Exception
- */
protected function run($argument) {
- $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes');
+ $backgroundJob = $this->appConfig->getValueString('files_trashbin', 'background_job_expire_trash', 'yes');
if ($backgroundJob === 'no') {
return;
}
@@ -43,15 +41,32 @@ class ExpireTrash extends TimedJob {
return;
}
- $this->userManager->callForSeenUsers(function (IUser $user): void {
- $uid = $user->getUID();
- if (!$this->setupFS($uid)) {
+ $stopTime = time() + 60 * 30; // Stops after 30 minutes.
+ $offset = $this->appConfig->getValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
+ $users = $this->userManager->getSeenUsers($offset);
+
+ foreach ($users as $user) {
+ try {
+ $uid = $user->getUID();
+ if (!$this->setupFS($uid)) {
+ continue;
+ }
+ $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
+ Trashbin::deleteExpiredFiles($dirContent, $uid);
+ } catch (\Throwable $e) {
+ $this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
+ }
+
+ $offset++;
+
+ if ($stopTime < time()) {
+ $this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', $offset);
+ \OC_Util::tearDownFS();
return;
}
- $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
- Trashbin::deleteExpiredFiles($dirContent, $uid);
- });
+ }
+ $this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
\OC_Util::tearDownFS();
}