Skip to content

Commit 205a4bc

Browse files
DerDreschnerbackportbot[bot]
authored andcommitted
fix(CalDav): Force trashbin deletion when re-creating item with same UID
Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
1 parent 789b29e commit 205a4bc

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

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

0 commit comments

Comments
 (0)