diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-06-28 12:55:26 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-08-08 17:03:19 +0200 |
commit | 48d9c4d2b093e12ec3bf3cd29295da0f2277028f (patch) | |
tree | d66f1d2f54e8ae745fc7ce7bf067ce2072eeac6a /apps/files_trashbin | |
parent | 19a2d6f6e7d54eb9318279809bf6c3f40bf566e2 (diff) | |
download | nextcloud-server-48d9c4d2b093e12ec3bf3cd29295da0f2277028f.tar.gz nextcloud-server-48d9c4d2b093e12ec3bf3cd29295da0f2277028f.zip |
Port existing server code to new interface
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php | 52 | ||||
-rw-r--r-- | apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php | 13 |
2 files changed, 26 insertions, 39 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..d8cce61ca52 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,9 +48,12 @@ class ExpireTrashTest extends TestCase { /** @var IJobList|MockObject */ private $jobList; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; + /** @var ITimeFactory|MockObject */ + private $time; + protected function setUp(): void { parent::setUp(); @@ -58,6 +62,7 @@ class ExpireTrashTest extends TestCase { $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->jobList->expects($this->once()) ->method('setLastRun'); @@ -77,7 +82,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); } } |