aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php16
-rw-r--r--apps/files_trashbin/lib/Command/ExpireTrash.php15
-rw-r--r--apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php9
3 files changed, 28 insertions, 12 deletions
diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
index 38a2e4c7472..a12c8530702 100644
--- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
+++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
@@ -33,6 +33,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IAppConfig;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
class ExpireTrash extends TimedJob {
@@ -40,6 +41,7 @@ class ExpireTrash extends TimedJob {
private IAppConfig $appConfig,
private IUserManager $userManager,
private Expiration $expiration,
+ private LoggerInterface $logger,
ITimeFactory $time
) {
parent::__construct($time);
@@ -63,12 +65,16 @@ class ExpireTrash extends TimedJob {
$users = $this->userManager->getSeenUsers($offset);
foreach ($users as $user) {
- $uid = $user->getUID();
- if (!$this->setupFS($uid)) {
- continue;
+ 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]);
}
- $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
- Trashbin::deleteExpiredFiles($dirContent, $uid);
$offset++;
diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php
index e7e3f5adab8..5755d4720b3 100644
--- a/apps/files_trashbin/lib/Command/ExpireTrash.php
+++ b/apps/files_trashbin/lib/Command/ExpireTrash.php
@@ -30,6 +30,7 @@ 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;
@@ -107,12 +108,16 @@ 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;
+ }
+ $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]);
}
- $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
- Trashbin::deleteExpiredFiles($dirContent, $uid);
}
/**
diff --git a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
index d827a590263..56deb757c36 100644
--- a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
+++ b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
@@ -32,6 +32,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\IAppConfig;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class ExpireTrashTest extends TestCase {
@@ -47,6 +48,9 @@ class ExpireTrashTest extends TestCase {
/** @var IJobList&MockObject */
private $jobList;
+ /** @var LoggerInterface&MockObject */
+ private $logger;
+
/** @var ITimeFactory&MockObject */
private $time;
@@ -57,6 +61,7 @@ class ExpireTrashTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->expiration = $this->createMock(Expiration::class);
$this->jobList = $this->createMock(IJobList::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->time = $this->createMock(ITimeFactory::class);
$this->time->method('getTime')
@@ -76,7 +81,7 @@ class ExpireTrashTest extends TestCase {
->with('files_trashbin', 'background_job_expire_trash_offset', 0)
->willReturn(0);
- $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->time);
+ $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
$job->start($this->jobList);
}
@@ -87,7 +92,7 @@ class ExpireTrashTest extends TestCase {
$this->expiration->expects($this->never())
->method('getMaxAgeAsTimestamp');
- $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->time);
+ $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
$job->start($this->jobList);
}
}