From bf8b5030ff66c529519e88f4690a20218570026b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 12 Feb 2024 12:18:15 +0100 Subject: [PATCH 1/3] chore: Migrate to OCP version of QueuedJob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keeps compatibility with server master Signed-off-by: Côme Chilliet --- lib/Notification/BackgroundJob.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/Notification/BackgroundJob.php b/lib/Notification/BackgroundJob.php index 95ebe50e4..dd02078e0 100644 --- a/lib/Notification/BackgroundJob.php +++ b/lib/Notification/BackgroundJob.php @@ -1,4 +1,7 @@ * @@ -21,25 +24,18 @@ namespace OCA\FirstRunWizard\Notification; -use OC\BackgroundJob\QueuedJob; +use OCP\BackgroundJob\QueuedJob; use OCP\Notification\IManager as INotificationManager; class BackgroundJob extends QueuedJob { - - /** @var INotificationManager */ - protected $notificationManager; - - /** - * BackgroundJob constructor. - * - * @param INotificationManager $notificationManager - */ - public function __construct(INotificationManager $notificationManager) { - $this->notificationManager = $notificationManager; + public function __construct( + protected INotificationManager $notificationManager, + ) { } /** * @param array $argument + * @return void */ protected function run($argument) { $notification = $this->notificationManager->createNotification(); From 910688f73471a7eb3ce205cc396770bd3856b5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 12 Feb 2024 15:51:09 +0100 Subject: [PATCH 2/3] fix(job): Call parent constructor and use the time factory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/Notification/BackgroundJob.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Notification/BackgroundJob.php b/lib/Notification/BackgroundJob.php index dd02078e0..afc99904a 100644 --- a/lib/Notification/BackgroundJob.php +++ b/lib/Notification/BackgroundJob.php @@ -31,6 +31,7 @@ class BackgroundJob extends QueuedJob { public function __construct( protected INotificationManager $notificationManager, ) { + parent::__construct(); } /** @@ -45,7 +46,7 @@ protected function run($argument) { ->setUser($argument['uid']); if ($this->notificationManager->getCount($notification) === 0) { - $notification->setDateTime(new \DateTime()); + $notification->setDateTime($this->time->getDateTime()); $this->notificationManager->notify($notification); } } From 63a35bcebcb2a9855617cef505712320617746e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 12 Feb 2024 16:44:02 +0100 Subject: [PATCH 3/3] fix(job): Add missing timefactory parameter and adapt tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/Notification/BackgroundJob.php | 4 +++- tests/Notification/BackgroundJobTest.php | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Notification/BackgroundJob.php b/lib/Notification/BackgroundJob.php index afc99904a..e5a449d8e 100644 --- a/lib/Notification/BackgroundJob.php +++ b/lib/Notification/BackgroundJob.php @@ -24,14 +24,16 @@ namespace OCA\FirstRunWizard\Notification; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\QueuedJob; use OCP\Notification\IManager as INotificationManager; class BackgroundJob extends QueuedJob { public function __construct( + ITimeFactory $time, protected INotificationManager $notificationManager, ) { - parent::__construct(); + parent::__construct($time); } /** diff --git a/tests/Notification/BackgroundJobTest.php b/tests/Notification/BackgroundJobTest.php index d35eaaa84..1948bacf5 100644 --- a/tests/Notification/BackgroundJobTest.php +++ b/tests/Notification/BackgroundJobTest.php @@ -24,6 +24,7 @@ namespace OCA\FirstRunWizard\Tests\Notification; use OCA\FirstRunWizard\Notification\BackgroundJob; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\Notification\IManager; use OCP\Notification\INotification; use Test\TestCase; @@ -35,17 +36,17 @@ * @group DB */ class BackgroundJobTest extends TestCase { - /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ - protected $notificationManager; - - /** @var BackgroundJob */ - protected $job; + protected ITimeFactory $timeFactory; + protected IManager $notificationManager; + protected BackgroundJob $job; protected function setUp(): void { parent::setUp(); + $this->timeFactory = $this->createMock(ITimeFactory::class); $this->notificationManager = $this->createMock(IManager::class); $this->job = new BackgroundJob( - $this->notificationManager + $this->timeFactory, + $this->notificationManager, ); }