Skip to content

Commit 60bc9db

Browse files
authored
Merge pull request #61890 from nextcloud/backport/61881/stable32
[stable32] fix(CalDav): Force trashbin deletion when re-creating item with same UID
2 parents 7c5c207 + 8baf2f2 commit 60bc9db

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
15411541
if ($found !== false) {
15421542
// the object existed previously but has been deleted
15431543
// remove the trashbin entry and continue as if it was a new object
1544-
$this->deleteCalendarObject($calendarId, $found['uri']);
1544+
$this->deleteCalendarObject($calendarId, $found['uri'], $calendarType, true);
15451545
}
15461546

15471547
$query = $this->db->getQueryBuilder();

apps/dav/tests/unit/CalDAV/CalDavBackendTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,46 @@ public function testMultipleCalendarObjectsWithSameUID(): void {
295295
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
296296
}
297297

298+
public function testCreateCalendarObjectWithSameUidAsObjectInTrashbin(): void {
299+
$calendarId = $this->createTestCalendar();
300+
301+
$calData = <<<'EOD'
302+
BEGIN:VCALENDAR
303+
VERSION:2.0
304+
PRODID:ownCloud Calendar
305+
BEGIN:VEVENT
306+
CREATED;VALUE=DATE-TIME:20130910T125139Z
307+
UID:47d15e3ec8
308+
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
309+
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
310+
SUMMARY:Test Event
311+
DTSTART;VALUE=DATE-TIME:20130912T130000Z
312+
DTEND;VALUE=DATE-TIME:20130912T140000Z
313+
CLASS:PUBLIC
314+
END:VEVENT
315+
END:VCALENDAR
316+
EOD;
317+
318+
$uri = static::getUniqueID('event') . '.ics';
319+
$this->backend->createCalendarObject($calendarId, $uri, $calData);
320+
321+
// Soft-delete the object so it is moved to the trashbin but keeps its UID
322+
$this->backend->deleteCalendarObject($calendarId, $uri);
323+
$trashbinUri = str_replace('.ics', '-deleted.ics', $uri);
324+
$trashedObject = $this->backend->getCalendarObject($calendarId, $trashbinUri);
325+
$this->assertNotNull($trashedObject);
326+
327+
// Recreating an object with the same UID must purge the trashbin entry
328+
// instead of violating the unique index on (calendarid, calendartype, uid)
329+
$newUri = static::getUniqueID('event') . '.ics';
330+
$this->backend->createCalendarObject($calendarId, $newUri, $calData);
331+
332+
$this->assertNull($this->backend->getCalendarObject($calendarId, $trashbinUri));
333+
$newObject = $this->backend->getCalendarObject($calendarId, $newUri);
334+
$this->assertNotNull($newObject);
335+
$this->assertEquals($calData, $newObject['calendardata']);
336+
}
337+
298338
public function testMultiCalendarObjects(): void {
299339
$calendarId = $this->createTestCalendar();
300340

0 commit comments

Comments
 (0)