Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(caldav): rename default calendar to keep it in the trashbin instead of purging it #50034

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions apps/dav/lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function getAddressesForPrincipal($principal) {
if ($result === null) {
$result = [];
}

// iterate through items and html decode values
foreach ($result as $key => $value) {
$result[$key] = urldecode($value);
Expand Down Expand Up @@ -197,12 +197,12 @@ public function calendarObjectChange(RequestInterface $request, ResponseInterfac
}
// 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);
}
Expand Down Expand Up @@ -430,12 +430,20 @@ public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
} 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);
Expand Down Expand Up @@ -572,7 +580,7 @@ private function isAvailableAtTime(string $email, \DateTimeInterface $start, \Da
$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;
}
Expand Down Expand Up @@ -704,6 +712,10 @@ private function createCalendar(CalendarHome $calendarHome, string $principalUri
]);
}

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.
*
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function testPropFindDefaultCalendarUrl(string $principalUri, ?string $ca
'{DAV:}displayname' => $displayName,
]);

$calendarHomeObject->expects($this->once())
$calendarHomeObject->expects($this->exactly($deleted ? 2 : 1))
->method('getCalDAVBackend')
->with()
->willReturn($calendarBackend);
Expand Down
Loading