aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2023-02-07 18:37:58 +0100
committerThomas Citharel <tcit@tcit.fr>2023-02-09 14:43:27 +0100
commit4fd58aa45cdd4a15be0f3eafcd353715c37d4d63 (patch)
tree3fe8f0ba1f7d5d5cb328e9cd8f91e71ae1e39f55 /apps/dav/lib/CalDAV
parentd0eeb279b7ffe173d4a9911ce5e5b1a00cdb72da (diff)
downloadnextcloud-server-4fd58aa45cdd4a15be0f3eafcd353715c37d4d63.tar.gz
nextcloud-server-4fd58aa45cdd4a15be0f3eafcd353715c37d4d63.zip
fix(caldav): Correctly handle calendar recreation for invitations when the current calendar is in the trashbin
Follow-up to #32361, see https://github.com/nextcloud/calendar/issues/4098 for details Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r--apps/dav/lib/CalDAV/Schedule/Plugin.php37
1 files changed, 29 insertions, 8 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/Plugin.php b/apps/dav/lib/CalDAV/Schedule/Plugin.php
index ac8521acfee..0751638b697 100644
--- a/apps/dav/lib/CalDAV/Schedule/Plugin.php
+++ b/apps/dav/lib/CalDAV/Schedule/Plugin.php
@@ -48,7 +48,6 @@ use Sabre\VObject\Component;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser;
-use Sabre\VObject\Document;
use Sabre\VObject\FreeBusyGenerator;
use Sabre\VObject\ITip;
use Sabre\VObject\Parameter;
@@ -329,12 +328,12 @@ EOF;
/** @var CalendarHome $calendarHome */
$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
- if (!$calendarHome->childExists($uri)) {
+ $currentCalendarDeleted = false;
+ if (!$calendarHome->childExists($uri) || $currentCalendarDeleted = $this->isCalendarDeleted($calendarHome, $uri)) {
// If the default calendar doesn't exist
if ($isResourceOrRoom) {
- $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
- '{DAV:}displayname' => $displayName,
- ]);
+ // Resources or rooms can't be in the trashbin, so we're fine
+ $this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
} else {
// And we're not handling scheduling on resource/room booking
$userCalendars = [];
@@ -359,9 +358,16 @@ EOF;
$uri = $userCalendars[0]->getName();
} else {
// Otherwise if we have really nothing, create a new calendar
- $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
- '{DAV:}displayname' => $displayName,
- ]);
+ if ($currentCalendarDeleted) {
+ // If the calendar exists but is deleted, we need to purge it first
+ // This may cause some issues in a non synchronous database setup
+ $calendar = $this->getCalendar($calendarHome, $uri);
+ if ($calendar instanceof Calendar) {
+ $calendar->disableTrashbin();
+ $calendar->delete();
+ }
+ }
+ $this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
}
}
}
@@ -609,4 +615,19 @@ EOF;
return $email;
}
+
+ private function getCalendar(CalendarHome $calendarHome, string $uri): INode {
+ return $calendarHome->getChild($uri);
+ }
+
+ private function isCalendarDeleted(CalendarHome $calendarHome, string $uri): bool {
+ $calendar = $this->getCalendar($calendarHome, $uri);
+ return $calendar instanceof Calendar && $calendar->isDeleted();
+ }
+
+ private function createCalendar(CalendarHome $calendarHome, string $principalUri, string $uri, string $displayName): void {
+ $calendarHome->getCalDAVBackend()->createCalendar($principalUri, $uri, [
+ '{DAV:}displayname' => $displayName,
+ ]);
+ }
}