aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2025-01-03 20:15:35 +0100
committerThomas Citharel <tcit@tcit.fr>2025-01-06 11:45:05 +0100
commitef0e2213ea9ac78b155e5d86e89f46ec28ee96a8 (patch)
tree0c913f0aa3c731274bdafd5d8e697b19e7bca61d /apps/dav/lib/CalDAV
parent72e82417f2d8acb84303d59a2250c1bb98411b24 (diff)
downloadnextcloud-server-ef0e2213ea9ac78b155e5d86e89f46ec28ee96a8.tar.gz
nextcloud-server-ef0e2213ea9ac78b155e5d86e89f46ec28ee96a8.zip
fix(caldav): rename default calendar to keep it in the trashbin instead of purging itrename-deleted-default-calendar-in-trashbin
When doing a PROPFIND on default-calendar-url, if the current default calendar (fallbacking on personal uri) is in the trashbin, it's being purged so that it's recreated. This leads to loss of data. We can simply rename the calendar URI and add a unique suffix so that it doesn't conflict with the new calendar being created. Shares are fine because they reference the resourceid and not the calendar URI. Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r--apps/dav/lib/CalDAV/Schedule/Plugin.php28
1 files changed, 20 insertions, 8 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/Plugin.php b/apps/dav/lib/CalDAV/Schedule/Plugin.php
index eeeebe16b88..abb3f578d04 100644
--- a/apps/dav/lib/CalDAV/Schedule/Plugin.php
+++ b/apps/dav/lib/CalDAV/Schedule/Plugin.php
@@ -138,7 +138,7 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
if ($result === null) {
$result = [];
}
-
+
// iterate through items and html decode values
foreach ($result as $key => $value) {
$result[$key] = urldecode($value);
@@ -197,12 +197,12 @@ class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
}
// process request
$this->processICalendarChange($currentObject, $vCal, $addresses, [], $modified);
-
+
if ($currentObject) {
// Destroy circular references so PHP will GC the object.
$currentObject->destroy();
}
-
+
} catch (SameOrganizerForAllComponentsException $e) {
$this->handleSameOrganizerException($e, $vCal, $calendarPath);
}
@@ -430,12 +430,20 @@ EOF;
} else {
// Otherwise if we have really nothing, create a new calendar
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
+ // If the calendar exists but is in the trash bin, we try to rename its uri
+ // so that we can create the new one and still restore the previous one
+ // otherwise we just purge the calendar by removing it before recreating it
$calendar = $this->getCalendar($calendarHome, $uri);
if ($calendar instanceof Calendar) {
- $calendar->disableTrashbin();
- $calendar->delete();
+ $backend = $calendarHome->getCalDAVBackend();
+ if ($backend instanceof CalDavBackend) {
+ // If the CalDAV backend supports moving calendars
+ $this->moveCalendar($backend, $principalUrl, $uri, $uri . '-back-' . time());
+ } else {
+ // Otherwise just purge the calendar
+ $calendar->disableTrashbin();
+ $calendar->delete();
+ }
}
}
$this->createCalendar($calendarHome, $principalUrl, $uri, $displayName);
@@ -572,7 +580,7 @@ EOF;
$homePath = $result[0][200]['{' . self::NS_CALDAV . '}calendar-home-set']->getHref();
/** @var Calendar $node */
foreach ($this->server->tree->getNodeForPath($homePath)->getChildren() as $node) {
-
+
if (!$node instanceof ICalendar) {
continue;
}
@@ -704,6 +712,10 @@ EOF;
]);
}
+ private function moveCalendar(CalDavBackend $calDavBackend, string $principalUri, string $oldUri, string $newUri): void {
+ $calDavBackend->moveCalendar($oldUri, $principalUri, $principalUri, $newUri);
+ }
+
/**
* Try to handle the given exception gracefully or throw it if necessary.
*