Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
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']);
$this->deleteCalendarObject($calendarId, $found['uri'], $calendarType, true);
}

$query = $this->db->getQueryBuilder();
Expand Down
40 changes: 40 additions & 0 deletions apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,46 @@ public function testMultipleCalendarObjectsWithSameUID(): void {
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
}

public function testCreateCalendarObjectWithSameUidAsObjectInTrashbin(): void {
$calendarId = $this->createTestCalendar();

$calData = <<<'EOD'
BEGIN:VCALENDAR
VERSION:2.0
PRODID:ownCloud Calendar
BEGIN:VEVENT
CREATED;VALUE=DATE-TIME:20130910T125139Z
UID:47d15e3ec8
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
SUMMARY:Test Event
DTSTART;VALUE=DATE-TIME:20130912T130000Z
DTEND;VALUE=DATE-TIME:20130912T140000Z
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
EOD;

$uri = static::getUniqueID('event') . '.ics';
$this->backend->createCalendarObject($calendarId, $uri, $calData);

// Soft-delete the object so it is moved to the trashbin but keeps its UID
$this->backend->deleteCalendarObject($calendarId, $uri);
$trashbinUri = str_replace('.ics', '-deleted.ics', $uri);
$trashedObject = $this->backend->getCalendarObject($calendarId, $trashbinUri);
$this->assertNotNull($trashedObject);

// Recreating an object with the same UID must purge the trashbin entry
// instead of violating the unique index on (calendarid, calendartype, uid)
$newUri = static::getUniqueID('event') . '.ics';
$this->backend->createCalendarObject($calendarId, $newUri, $calData);

$this->assertNull($this->backend->getCalendarObject($calendarId, $trashbinUri));
$newObject = $this->backend->getCalendarObject($calendarId, $newUri);
$this->assertNotNull($newObject);
$this->assertEquals($calData, $newObject['calendardata']);
}

public function testMultiCalendarObjects(): void {
$calendarId = $this->createTestCalendar();

Expand Down
Loading