Skip to content

Commit 263542c

Browse files
committed
fix(caldav): Correctly handle calendar recreation for invitations when the current calendar is in the trashbin
Follow-up to #32361, see nextcloud/calendar#4098 for details Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 6077003 commit 263542c

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

apps/dav/lib/CalDAV/Schedule/Plugin.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
use Sabre\VObject\Component\VCalendar;
4949
use Sabre\VObject\Component\VEvent;
5050
use Sabre\VObject\DateTimeParser;
51-
use Sabre\VObject\Document;
5251
use Sabre\VObject\FreeBusyGenerator;
5352
use Sabre\VObject\ITip;
5453
use Sabre\VObject\Parameter;
@@ -329,12 +328,12 @@ public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
329328

330329
/** @var CalendarHome $calendarHome */
331330
$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
332-
if (!$calendarHome->childExists($uri)) {
331+
$currentCalendarDeleted = false;
332+
if (!$calendarHome->childExists($uri) || $currentCalendarDeleted = $this->isCalendarDeleted($calendarHome, $uri)) {
333333
// If the default calendar doesn't exist
334334
if ($isResourceOrRoom) {
335-
$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
336-
'{DAV:}displayname' => $displayName,
337-
]);
335+
// Resources or rooms can't be in the trashbin, so we're fine
336+
$this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
338337
} else {
339338
// And we're not handling scheduling on resource/room booking
340339
$userCalendars = [];
@@ -359,9 +358,16 @@ public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
359358
$uri = $userCalendars[0]->getName();
360359
} else {
361360
// Otherwise if we have really nothing, create a new calendar
362-
$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
363-
'{DAV:}displayname' => $displayName,
364-
]);
361+
if ($currentCalendarDeleted) {
362+
// If the calendar exists but is deleted, we need to purge it first
363+
// This may cause some issues in a non synchronous database setup
364+
$calendar = $this->getCalendar($calendarHome, $uri);
365+
if ($calendar instanceof Calendar) {
366+
$calendar->disableTrashbin();
367+
$calendar->delete();
368+
}
369+
}
370+
$this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
365371
}
366372
}
367373
}
@@ -609,4 +615,19 @@ private function stripOffMailTo(string $email): string {
609615

610616
return $email;
611617
}
618+
619+
private function getCalendar(CalendarHome $calendarHome, $uri): INode {
620+
return $calendarHome->getChild($uri);
621+
}
622+
623+
private function isCalendarDeleted(CalendarHome $calendarHome, $uri): bool {
624+
$calendar = $this->getCalendar($calendarHome, $uri);
625+
return $calendar instanceof Calendar && $calendar->isDeleted();
626+
}
627+
628+
private function createCalendar(CalendarHome $calendarHome, string $principalUri, string $uri, string $displayName): void {
629+
$calendarHome->getCalDAVBackend()->createCalendar($principalUri, $uri, [
630+
'{DAV:}displayname' => $displayName,
631+
]);
632+
}
612633
}

0 commit comments

Comments
 (0)