]> source.dussan.org Git - nextcloud-server.git/commitdiff
Debug log what happens during reminders processing 28703/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Fri, 3 Sep 2021 12:13:49 +0000 (14:13 +0200)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Wed, 1 Jun 2022 09:38:02 +0000 (11:38 +0200)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
apps/dav/lib/CalDAV/Reminder/ReminderService.php
apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php

index b33bc8a175a724af206b5e8f12c1a94de0124c7f..2a0654690528572266001ec755de7ea3f78123bd 100644 (file)
@@ -38,6 +38,7 @@ use OCP\IGroup;
 use OCP\IGroupManager;
 use OCP\IUser;
 use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
 use Sabre\VObject;
 use Sabre\VObject\Component\VAlarm;
 use Sabre\VObject\Component\VEvent;
@@ -46,6 +47,7 @@ use Sabre\VObject\ParseException;
 use Sabre\VObject\Recur\EventIterator;
 use Sabre\VObject\Recur\MaxInstancesExceededException;
 use Sabre\VObject\Recur\NoInstancesException;
+use function count;
 use function strcasecmp;
 
 class ReminderService {
@@ -71,6 +73,9 @@ class ReminderService {
        /** @var IConfig */
        private $config;
 
+       /** @var LoggerInterface */
+       private $logger;
+
        public const REMINDER_TYPE_EMAIL = 'EMAIL';
        public const REMINDER_TYPE_DISPLAY = 'DISPLAY';
        public const REMINDER_TYPE_AUDIO = 'AUDIO';
@@ -86,24 +91,14 @@ class ReminderService {
                self::REMINDER_TYPE_AUDIO
        ];
 
-       /**
-        * ReminderService constructor.
-        *
-        * @param Backend $backend
-        * @param NotificationProviderManager $notificationProviderManager
-        * @param IUserManager $userManager
-        * @param IGroupManager $groupManager
-        * @param CalDavBackend $caldavBackend
-        * @param ITimeFactory $timeFactory
-        * @param IConfig $config
-        */
        public function __construct(Backend $backend,
                                                                NotificationProviderManager $notificationProviderManager,
                                                                IUserManager $userManager,
                                                                IGroupManager $groupManager,
                                                                CalDavBackend $caldavBackend,
                                                                ITimeFactory $timeFactory,
-                                                               IConfig $config) {
+                                                               IConfig $config,
+                                                               LoggerInterface $logger) {
                $this->backend = $backend;
                $this->notificationProviderManager = $notificationProviderManager;
                $this->userManager = $userManager;
@@ -111,6 +106,7 @@ class ReminderService {
                $this->caldavBackend = $caldavBackend;
                $this->timeFactory = $timeFactory;
                $this->config = $config;
+               $this->logger = $logger;
        }
 
        /**
@@ -119,8 +115,11 @@ class ReminderService {
         * @throws NotificationProvider\ProviderNotAvailableException
         * @throws NotificationTypeDoesNotExistException
         */
-       public function processReminders():void {
+       public function processReminders() :void {
                $reminders = $this->backend->getRemindersToProcess();
+               $this->logger->debug('{numReminders} reminders to process', [
+                       'numReminders' => count($reminders),
+               ]);
 
                foreach ($reminders as $reminder) {
                        $calendarData = is_resource($reminder['calendardata'])
@@ -133,22 +132,34 @@ class ReminderService {
 
                        $vcalendar = $this->parseCalendarData($calendarData);
                        if (!$vcalendar) {
+                               $this->logger->debug('Reminder {id} does not belong to a valid calendar', [
+                                       'id' => $reminder['id'],
+                               ]);
                                $this->backend->removeReminder($reminder['id']);
                                continue;
                        }
 
                        $vevent = $this->getVEventByRecurrenceId($vcalendar, $reminder['recurrence_id'], $reminder['is_recurrence_exception']);
                        if (!$vevent) {
+                               $this->logger->debug('Reminder {id} does not belong to a valid event', [
+                                       'id' => $reminder['id'],
+                               ]);
                                $this->backend->removeReminder($reminder['id']);
                                continue;
                        }
 
                        if ($this->wasEventCancelled($vevent)) {
+                               $this->logger->debug('Reminder {id} belongs to a cancelled event', [
+                                       'id' => $reminder['id'],
+                               ]);
                                $this->deleteOrProcessNext($reminder, $vevent);
                                continue;
                        }
 
                        if (!$this->notificationProviderManager->hasProvider($reminder['type'])) {
+                               $this->logger->debug('Reminder {id} does not belong to a valid notification provider', [
+                                       'id' => $reminder['id'],
+                               ]);
                                $this->deleteOrProcessNext($reminder, $vevent);
                                continue;
                        }
@@ -164,6 +175,10 @@ class ReminderService {
                                $users[] = $user;
                        }
 
+                       $this->logger->debug('Reminder {id} will be sent to {numUsers} users', [
+                               'id' => $reminder['id'],
+                               'numUsers' => count($users),
+                       ]);
                        $notificationProvider = $this->notificationProviderManager->getProvider($reminder['type']);
                        $notificationProvider->send($vevent, $reminder['displayname'], $users);
 
index 39fbf1c79ffc264db470dd452901ce4bec0843b4..6242e8d0355a591abcb94ee4adcefb4fffdc59e8 100644 (file)
@@ -39,37 +39,39 @@ use OCP\IGroupManager;
 use OCP\IUser;
 use OCP\IUserManager;
 use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
 use Test\TestCase;
 
 class ReminderServiceTest extends TestCase {
 
-       /** @var Backend|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var Backend|MockObject */
        private $backend;
 
-       /** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var NotificationProviderManager|MockObject */
        private $notificationProviderManager;
 
-       /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var IUserManager|MockObject */
        private $userManager;
 
-       /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject*/
+       /** @var IGroupManager|MockObject*/
        private $groupManager;
 
-       /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
-       private $userSession;
-
-       /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var CalDavBackend|MockObject */
        private $caldavBackend;
 
-       /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject  */
+       /** @var ITimeFactory|MockObject  */
        private $timeFactory;
 
-       /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+       /** @var IConfig|MockObject */
        private $config;
 
        /** @var ReminderService */
        private $reminderService;
 
+       /** @var MockObject|LoggerInterface */
+       private $logger;
+
        public const CALENDAR_DATA = <<<EOD
 BEGIN:VCALENDAR
 PRODID:-//Nextcloud calendar v1.6.4
@@ -199,16 +201,20 @@ EOD;
                $this->caldavBackend = $this->createMock(CalDavBackend::class);
                $this->timeFactory = $this->createMock(ITimeFactory::class);
                $this->config = $this->createMock(IConfig::class);
+               $this->logger = $this->createMock(LoggerInterface::class);
 
                $this->caldavBackend->method('getShares')->willReturn([]);
 
-               $this->reminderService = new ReminderService($this->backend,
+               $this->reminderService = new ReminderService(
+                       $this->backend,
                        $this->notificationProviderManager,
                        $this->userManager,
                        $this->groupManager,
                        $this->caldavBackend,
                        $this->timeFactory,
-                       $this->config);
+                       $this->config,
+                       $this->logger,
+               );
        }
 
        public function testOnCalendarObjectDelete():void {