diff options
author | Thomas Citharel <tcit@tcit.fr> | 2025-01-03 20:15:35 +0100 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-01-11 15:36:33 +0000 |
commit | 0747d038452babeefcb9b6faf0925aa7828f77a3 (patch) | |
tree | 0e10aa3a708eb56d1330cda9d340a0ee6a6dda07 | |
parent | f1899ed63372c09cefe6d2bb6419ac0bd93638f6 (diff) | |
download | nextcloud-server-backport/50034/stable30.tar.gz nextcloud-server-backport/50034/stable30.zip |
fix(caldav): rename default calendar to keep it in the trashbin instead of purging itbackport/50034/stable30
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>
-rw-r--r-- | apps/dav/lib/CalDAV/Schedule/Plugin.php | 28 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php | 2 |
2 files changed, 21 insertions, 9 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/Plugin.php b/apps/dav/lib/CalDAV/Schedule/Plugin.php index d7c2a735dae..1574792c6f0 100644 --- a/apps/dav/lib/CalDAV/Schedule/Plugin.php +++ b/apps/dav/lib/CalDAV/Schedule/Plugin.php @@ -143,7 +143,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); @@ -202,12 +202,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); } @@ -435,12 +435,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); @@ -577,7 +585,7 @@ EOF; $homePath = $result[0][200]['{' . self::NS_CALDAV . '}calendar-home-set']->getHref(); /** @var \OCA\DAV\CalDAV\Calendar $node */ foreach ($this->server->tree->getNodeForPath($homePath)->getChildren() as $node) { - + if (!$node instanceof ICalendar) { continue; } @@ -709,6 +717,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. * diff --git a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php index 15e598389c1..7a1d61a083b 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php @@ -353,7 +353,7 @@ class PluginTest extends TestCase { '{DAV:}displayname' => $displayName, ]); - $calendarHomeObject->expects($this->once()) + $calendarHomeObject->expects($this->exactly($deleted ? 2 : 1)) ->method('getCalDAVBackend') ->with() ->willReturn($calendarBackend); |