Skip to content

Commit ae35f81

Browse files
authored
Merge pull request #61881 from nextcloud/fix/force-trashbin-deletion
fix(CalDav): Force trashbin deletion when re-creating item with same UID
2 parents a256d7e + f6caf5a commit ae35f81

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
@@ -1552,7 +1552,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
15521552
if ($found !== false) {
15531553
// the object existed previously but has been deleted
15541554
// remove the trashbin entry and continue as if it was a new object
1555-
$this->deleteCalendarObject($calendarId, $found['uri']);
1555+
$this->deleteCalendarObject($calendarId, $found['uri'], $calendarType, true);
15561556
}
15571557

15581558
$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
@@ -292,6 +292,46 @@ public function testMultipleCalendarObjectsWithSameUID(): void {
292292
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
293293
}
294294

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

0 commit comments

Comments
 (0)