Skip to content

Commit

Permalink
Debug log what happens during reminders processing
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Sep 3, 2021
1 parent 46837e2 commit 9f352df
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions apps/dav/lib/CalDAV/Reminder/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
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;
use Sabre\VObject\InvalidDataException;
use Sabre\VObject\ParseException;
use Sabre\VObject\Recur\EventIterator;
use Sabre\VObject\Recur\NoInstancesException;
use function sprintf;
use function strcasecmp;

class ReminderService {
Expand Down Expand Up @@ -81,28 +83,23 @@ 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
*/
/** @var LoggerInterface */
private $logger;

public function __construct(Backend $backend,
NotificationProviderManager $notificationProviderManager,
IUserManager $userManager,
IGroupManager $groupManager,
CalDavBackend $caldavBackend,
ITimeFactory $timeFactory) {
ITimeFactory $timeFactory,
LoggerInterface $logger) {
$this->backend = $backend;
$this->notificationProviderManager = $notificationProviderManager;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->caldavBackend = $caldavBackend;
$this->timeFactory = $timeFactory;
$this->logger = $logger;
}

/**
Expand All @@ -111,8 +108,9 @@ public function __construct(Backend $backend,
* @throws NotificationProvider\ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException
*/
public function processReminders():void {
public function processReminders() :void {
$reminders = $this->backend->getRemindersToProcess();
$this->logger->debug(sprintf("%d reminders to process", count($reminders)));

foreach ($reminders as $reminder) {
$calendarData = is_resource($reminder['calendardata'])
Expand All @@ -121,22 +119,26 @@ public function processReminders():void {

$vcalendar = $this->parseCalendarData($calendarData);
if (!$vcalendar) {
$this->logger->debug(sprintf("Reminder %d does not belong to a valid calendar", $reminder['id']));
$this->backend->removeReminder($reminder['id']);
continue;
}

$vevent = $this->getVEventByRecurrenceId($vcalendar, $reminder['recurrence_id'], $reminder['is_recurrence_exception']);
if (!$vevent) {
$this->logger->debug(sprintf("Reminder %d does not belong to a valid event", $reminder['id']));
$this->backend->removeReminder($reminder['id']);
continue;
}

if ($this->wasEventCancelled($vevent)) {
$this->logger->debug(sprintf("Reminder %d belongs to a cancelled event", $reminder['id']));
$this->deleteOrProcessNext($reminder, $vevent);
continue;
}

if (!$this->notificationProviderManager->hasProvider($reminder['type'])) {
$this->logger->debug(sprintf("Reminder %d does not belong to a valid notification provider", $reminder['id']));
$this->deleteOrProcessNext($reminder, $vevent);
continue;
}
Expand All @@ -147,6 +149,7 @@ public function processReminders():void {
$users[] = $user;
}

$this->logger->debug(sprintf("Reminder %d will be sent to %d users", $reminder['id'], count($users)));
$notificationProvider = $this->notificationProviderManager->getProvider($reminder['type']);
$notificationProvider->send($vevent, $reminder['displayname'], $users);

Expand Down

0 comments on commit 9f352df

Please sign in to comment.