From 8247afe86493f05f8d155596c69145def4955502 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Sun, 2 Oct 2022 10:44:15 +0200 Subject: [PATCH] Allow reimporting prev. deleted items by deleting trashbin item Signed-off-by: Anna Larch --- apps/dav/lib/CalDAV/CalDavBackend.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 8f578046f6f5c..7387fea8ba631 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1275,17 +1275,19 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca } // For a more specific error message we also try to explicitly look up the UID but as a deleted entry $qbDel = $this->db->getQueryBuilder(); - $qbDel->select($qb->func()->count('*')) + $qbDel->select('*') ->from('calendarobjects') ->where($qbDel->expr()->eq('calendarid', $qbDel->createNamedParameter($calendarId))) ->andWhere($qbDel->expr()->eq('uid', $qbDel->createNamedParameter($extraData['uid']))) ->andWhere($qbDel->expr()->eq('calendartype', $qbDel->createNamedParameter($calendarType))) ->andWhere($qbDel->expr()->isNotNull('deleted_at')); $result = $qbDel->executeQuery(); - $count = (int) $result->fetchOne(); + $found = $result->fetch(); $result->closeCursor(); - if ($count !== 0) { - throw new BadRequest('Deleted calendar object with uid already exists in this calendar collection.'); + if ($found !== false) { + // the object existed previously but has been deleted + // remove the trashbin entry and continue as if it was a new object + $this->deleteCalendarObject($calendarId, $found['uri']); } $query = $this->db->getQueryBuilder();