From 1d1cd33ee20450f3b595536cfcc7a13a085a5fe6 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 27 Jan 2024 08:17:35 +0100 Subject: [PATCH] capture invalid calendar event Signed-off-by: dartcafe --- lib/Service/CalendarService.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php index 7f4d46a35..5b52f268a 100644 --- a/lib/Service/CalendarService.php +++ b/lib/Service/CalendarService.php @@ -39,6 +39,7 @@ use OCP\Calendar\ICalendar; use OCP\Calendar\IManager as CalendarManager; use OCP\ISession; +use Psr\Log\LoggerInterface; class CalendarService { /** @var ICalendar[] */ @@ -52,6 +53,7 @@ public function __construct( private Preferences $preferences, private PreferencesService $preferencesService, private UserMapper $userMapper, + private LoggerInterface $logger, ) { $this->preferences = $this->preferencesService->get(); $this->currentUser = $this->userMapper->getCurrentUser(); @@ -130,16 +132,21 @@ public function getEvents(int $optionId): array { $events = []; $foundEvents = $this->searchEventsByTimeRange($timerange['from'], $timerange['to']); - if (!$foundEvents) { - return []; - } - + // if (!$foundEvents) { + // return []; + // } + foreach ($foundEvents as $event) { $calendar = $this->getCalendarFromEvent($event); if ($calendar === null) { continue; } + if (!isset($event['objects'][0])) { + $this->logger->warning('Skipping invalid calendar entry', ['calendarEvent' => json_encode($event)]); + continue; + } + $calendarEvent = new CalendarEvent($event, $calendar, $timerange['from'], $timerange['to'], $timezone); if ($calendarEvent->getOccurrences()) {