diff --git a/apps/dav/lib/CalDAV/Schedule/Plugin.php b/apps/dav/lib/CalDAV/Schedule/Plugin.php index eeeebe16b8851..04f6445cee6a5 100644 --- a/apps/dav/lib/CalDAV/Schedule/Plugin.php +++ b/apps/dav/lib/CalDAV/Schedule/Plugin.php @@ -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); @@ -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); } @@ -430,12 +430,11 @@ 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 rename its uri + // so that we can create the new one and still restore the previous one $calendar = $this->getCalendar($calendarHome, $uri); if ($calendar instanceof Calendar) { - $calendar->disableTrashbin(); - $calendar->delete(); + $this->moveCalendar($calendarHome, $principalUrl, $uri, $uri . '-back-' . time()); } } $this->createCalendar($calendarHome, $principalUrl, $uri, $displayName); @@ -572,7 +571,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; } @@ -704,6 +703,10 @@ private function createCalendar(CalendarHome $calendarHome, string $principalUri ]); } + private function moveCalendar(CalendarHome $calendarHome, string $principalUri, string $oldUri, string $newUri): void { + $calendarHome->getCalDAVBackend()->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 8d20fd5f9df47..f656a0fa33c79 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php @@ -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);