summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-08-23 16:55:42 +0200
committerGitHub <noreply@github.com>2022-08-23 16:55:42 +0200
commitb888c6146327d842e21988b0d90d6ade4f3a9435 (patch)
treeaa115b3d420cb6ccfa18a6a5af146eff8578b82c /apps/files_trashbin
parent5f90a6a5e2da08e7098cc44937c1713375823e74 (diff)
parent49334e4d9c278d33ce9fd4195b5a12af99821be2 (diff)
downloadnextcloud-server-b888c6146327d842e21988b0d90d6ade4f3a9435.tar.gz
nextcloud-server-b888c6146327d842e21988b0d90d6ade4f3a9435.zip
Merge pull request #33047 from nextcloud/fix/ijob-logger-deprecated
Deprecated ILogger from IJob
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php52
-rw-r--r--apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php24
2 files changed, 33 insertions, 43 deletions
diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
index 9e35273544b..c76033e0c79 100644
--- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
+++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
@@ -30,46 +30,30 @@ use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Expiration;
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\IUserManager;
-class ExpireTrash extends \OC\BackgroundJob\TimedJob {
+class ExpireTrash extends TimedJob {
+ private IConfig $config;
+ private Expiration $expiration;
+ private IUserManager $userManager;
- /** @var IConfig */
- private $config;
-
- /**
- * @var Expiration
- */
- private $expiration;
-
- /**
- * @var IUserManager
- */
- private $userManager;
-
- public function __construct(IConfig $config = null,
- IUserManager $userManager = null,
- Expiration $expiration = null) {
+ public function __construct(
+ IConfig $config,
+ IUserManager $userManager,
+ Expiration $expiration,
+ ITimeFactory $time
+ ) {
+ parent::__construct($time);
// Run once per 30 minutes
$this->setInterval(60 * 30);
- if ($config === null || $expiration === null || $userManager === null) {
- $this->fixDIForJobs();
- } else {
- $this->config = $config;
- $this->userManager = $userManager;
- $this->expiration = $expiration;
- }
- }
-
- protected function fixDIForJobs() {
- /** @var Application $application */
- $application = \OC::$server->query(Application::class);
- $this->config = $application->getContainer()->get(IConfig::class);
- $this->userManager = \OC::$server->getUserManager();
- $this->expiration = $application->getContainer()->query('Expiration');
+ $this->config = $config;
+ $this->userManager = $userManager;
+ $this->expiration = $expiration;
}
/**
@@ -101,10 +85,8 @@ class ExpireTrash extends \OC\BackgroundJob\TimedJob {
/**
* Act on behalf on trash item owner
- * @param string $user
- * @return boolean
*/
- protected function setupFS($user) {
+ protected function setupFS(string $user): bool {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user);
diff --git a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
index c49501608f7..bf5d6bc65ae 100644
--- a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
+++ b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php
@@ -27,12 +27,13 @@ namespace OCA\Files_Trashbin\Tests\BackgroundJob;
use OCA\Files_Trashbin\BackgroundJob\ExpireTrash;
use OCA\Files_Trashbin\Expiration;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
-use OCP\ILogger;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
+use Psr\Log\LoggerInterface;
class ExpireTrashTest extends TestCase {
/** @var IConfig|MockObject */
@@ -47,8 +48,8 @@ class ExpireTrashTest extends TestCase {
/** @var IJobList|MockObject */
private $jobList;
- /** @var ILogger|MockObject */
- private $logger;
+ /** @var ITimeFactory|MockObject */
+ private $time;
protected function setUp(): void {
parent::setUp();
@@ -57,7 +58,10 @@ 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(ILogger::class);
+
+ $this->time = $this->createMock(ITimeFactory::class);
+ $this->time->method('getTime')
+ ->willReturn(99999999999);
$this->jobList->expects($this->once())
->method('setLastRun');
@@ -66,8 +70,12 @@ class ExpireTrashTest extends TestCase {
}
public function testConstructAndRun(): void {
- $job = new ExpireTrash($this->config, $this->userManager, $this->expiration);
- $job->execute($this->jobList, $this->logger);
+ $this->config->method('getAppValue')
+ ->with('files_trashbin', 'background_job_expire_trash', 'yes')
+ ->willReturn('yes');
+
+ $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
+ $job->start($this->jobList);
}
public function testBackgroundJobDeactivated(): void {
@@ -77,7 +85,7 @@ class ExpireTrashTest extends TestCase {
$this->expiration->expects($this->never())
->method('getMaxAgeAsTimestamp');
- $job = new ExpireTrash($this->config, $this->userManager, $this->expiration);
- $job->execute($this->jobList, $this->logger);
+ $job = new ExpireTrash($this->config, $this->userManager, $this->expiration, $this->time);
+ $job->start($this->jobList);
}
}