Skip to content

Commit eda8a41

Browse files
Merge pull request #42619 from nextcloud/bugfix/noid/caldav-status-undefined-index-0
fix(dav): Fix user status "Undefined array key 0 at StatusService.php…
2 parents 7fdb16a + e981619 commit eda8a41

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

apps/dav/lib/CalDAV/Status/StatusService.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ public function processCalendarStatus(string $userId): void {
9494
}
9595

9696
// Filter events to see if we have any that apply to the calendar status
97-
$applicableEvents = array_filter($calendarEvents, function (array $calendarEvent) use ($userStatusTimestamp) {
97+
$applicableEvents = array_filter($calendarEvents, static function (array $calendarEvent) use ($userStatusTimestamp): bool {
98+
if (empty($calendarEvent['objects'])) {
99+
return false;
100+
}
98101
$component = $calendarEvent['objects'][0];
99-
if(isset($component['X-NEXTCLOUD-OUT-OF-OFFICE'])) {
102+
if (isset($component['X-NEXTCLOUD-OUT-OF-OFFICE'])) {
100103
return false;
101104
}
102-
if(isset($component['DTSTART']) && $userStatusTimestamp !== null) {
105+
if (isset($component['DTSTART']) && $userStatusTimestamp !== null) {
103106
/** @var DateTimeImmutable $dateTime */
104107
$dateTime = $component['DTSTART'][0];
105108
$timestamp = $dateTime->getTimestamp();
@@ -108,7 +111,7 @@ public function processCalendarStatus(string $userId): void {
108111
}
109112
}
110113
// Ignore events that are transparent
111-
if(isset($component['TRANSP']) && strcasecmp($component['TRANSP'][0], 'TRANSPARENT') === 0) {
114+
if (isset($component['TRANSP']) && strcasecmp($component['TRANSP'][0], 'TRANSPARENT') === 0) {
112115
return false;
113116
}
114117
return true;

apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,50 @@ public function testNoCalendarEvents(): void {
229229
$this->service->processCalendarStatus('admin');
230230
}
231231

232+
public function testCalendarNoEventObjects(): void {
233+
$user = $this->createConfiguredMock(IUser::class, [
234+
'getUID' => 'admin',
235+
]);
236+
237+
$this->userManager->expects(self::once())
238+
->method('get')
239+
->willReturn($user);
240+
$this->availabilityCoordinator->expects(self::once())
241+
->method('getCurrentOutOfOfficeData')
242+
->willReturn(null);
243+
$this->availabilityCoordinator->expects(self::never())
244+
->method('isInEffect');
245+
$this->cache->expects(self::once())
246+
->method('get')
247+
->willReturn(null);
248+
$this->cache->expects(self::once())
249+
->method('set');
250+
$this->calendarManager->expects(self::once())
251+
->method('getCalendarsForPrincipal')
252+
->willReturn([$this->createMock(CalendarImpl::class)]);
253+
$this->calendarManager->expects(self::once())
254+
->method('newQuery')
255+
->willReturn(new CalendarQuery('admin'));
256+
$this->timeFactory->expects(self::exactly(2))
257+
->method('getDateTime')
258+
->willReturn(new \DateTime());
259+
$this->userStatusService->expects(self::once())
260+
->method('findByUserId')
261+
->willThrowException(new DoesNotExistException(''));
262+
$this->calendarManager->expects(self::once())
263+
->method('searchForPrincipal')
264+
->willReturn([['objects' => []]]);
265+
$this->userStatusService->expects(self::once())
266+
->method('revertUserStatus');
267+
$this->logger->expects(self::once())
268+
->method('debug');
269+
$this->userStatusService->expects(self::never())
270+
->method('setUserStatus');
271+
272+
273+
$this->service->processCalendarStatus('admin');
274+
}
275+
232276
public function testCalendarEvent(): void {
233277
$user = $this->createConfiguredMock(IUser::class, [
234278
'getUID' => 'admin',

0 commit comments

Comments
 (0)