Merge pull request #7042 from nextcloud/bugfix/noid/ensure_unique_uid_for_calendar_objects
ensure uid for calendar objects is unique
This commit is contained in:
commit
b754a2e385
|
@ -961,6 +961,20 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
||||||
function createCalendarObject($calendarId, $objectUri, $calendarData) {
|
function createCalendarObject($calendarId, $objectUri, $calendarData) {
|
||||||
$extraData = $this->getDenormalizedData($calendarData);
|
$extraData = $this->getDenormalizedData($calendarData);
|
||||||
|
|
||||||
|
$q = $this->db->getQueryBuilder();
|
||||||
|
$q->select($q->createFunction('COUNT(*)'))
|
||||||
|
->from('calendarobjects')
|
||||||
|
->where($q->expr()->eq('calendarid', $q->createNamedParameter($calendarId)))
|
||||||
|
->andWhere($q->expr()->eq('uid', $q->createNamedParameter($extraData['uid'])));
|
||||||
|
|
||||||
|
$result = $q->execute();
|
||||||
|
$count = (int) $result->fetchColumn();
|
||||||
|
$result->closeCursor();
|
||||||
|
|
||||||
|
if ($count !== 0) {
|
||||||
|
throw new \Sabre\DAV\Exception\BadRequest('Calendar object with uid already exists in this calendar collection.');
|
||||||
|
}
|
||||||
|
|
||||||
$query = $this->db->getQueryBuilder();
|
$query = $this->db->getQueryBuilder();
|
||||||
$query->insert('calendarobjects')
|
$query->insert('calendarobjects')
|
||||||
->values([
|
->values([
|
||||||
|
|
|
@ -140,13 +140,15 @@ abstract class AbstractCalDavBackend extends TestCase {
|
||||||
|
|
||||||
protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') {
|
protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') {
|
||||||
|
|
||||||
|
$randomPart = self::getUniqueID();
|
||||||
|
|
||||||
$calData = <<<EOD
|
$calData = <<<EOD
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
PRODID:ownCloud Calendar
|
PRODID:ownCloud Calendar
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
UID:47d15e3ec8
|
UID:47d15e3ec8-$randomPart
|
||||||
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
|
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
|
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
|
||||||
SUMMARY:Test Event
|
SUMMARY:Test Event
|
||||||
|
|
|
@ -275,18 +275,20 @@ EOD;
|
||||||
$this->assertCount(0, $calendarObjects);
|
$this->assertCount(0, $calendarObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultiCalendarObjects() {
|
/**
|
||||||
|
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||||
|
* @expectedExceptionMessage Calendar object with uid already exists in this calendar collection.
|
||||||
|
*/
|
||||||
|
public function testMultipleCalendarObjectsWithSameUID() {
|
||||||
$calendarId = $this->createTestCalendar();
|
$calendarId = $this->createTestCalendar();
|
||||||
|
|
||||||
// create an event
|
|
||||||
$calData = <<<'EOD'
|
$calData = <<<'EOD'
|
||||||
BEGIN:VCALENDAR
|
BEGIN:VCALENDAR
|
||||||
VERSION:2.0
|
VERSION:2.0
|
||||||
PRODID:ownCloud Calendar
|
PRODID:ownCloud Calendar
|
||||||
BEGIN:VEVENT
|
BEGIN:VEVENT
|
||||||
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
UID:47d15e3ec8
|
UID:47d15e3ec8-1
|
||||||
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
|
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
|
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
|
||||||
SUMMARY:Test Event
|
SUMMARY:Test Event
|
||||||
|
@ -296,21 +298,85 @@ CLASS:PUBLIC
|
||||||
END:VEVENT
|
END:VEVENT
|
||||||
END:VCALENDAR
|
END:VCALENDAR
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
|
$uri0 = static::getUniqueID('event');
|
||||||
|
$uri1 = static::getUniqueID('event');
|
||||||
|
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
|
||||||
|
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMultiCalendarObjects() {
|
||||||
|
|
||||||
|
$calendarId = $this->createTestCalendar();
|
||||||
|
|
||||||
|
// create an event
|
||||||
|
$calData = [];
|
||||||
|
$calData[] = <<<'EOD'
|
||||||
|
BEGIN:VCALENDAR
|
||||||
|
VERSION:2.0
|
||||||
|
PRODID:ownCloud Calendar
|
||||||
|
BEGIN:VEVENT
|
||||||
|
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
|
UID:47d15e3ec8-1
|
||||||
|
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;
|
||||||
|
|
||||||
|
$calData[] = <<<'EOD'
|
||||||
|
BEGIN:VCALENDAR
|
||||||
|
VERSION:2.0
|
||||||
|
PRODID:ownCloud Calendar
|
||||||
|
BEGIN:VEVENT
|
||||||
|
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
|
UID:47d15e3ec8-2
|
||||||
|
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;
|
||||||
|
|
||||||
|
$calData[] = <<<'EOD'
|
||||||
|
BEGIN:VCALENDAR
|
||||||
|
VERSION:2.0
|
||||||
|
PRODID:ownCloud Calendar
|
||||||
|
BEGIN:VEVENT
|
||||||
|
CREATED;VALUE=DATE-TIME:20130910T125139Z
|
||||||
|
UID:47d15e3ec8-3
|
||||||
|
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;
|
||||||
|
|
||||||
$uri0 = static::getUniqueID('card');
|
$uri0 = static::getUniqueID('card');
|
||||||
$this->dispatcher->expects($this->at(0))
|
$this->dispatcher->expects($this->at(0))
|
||||||
->method('dispatch')
|
->method('dispatch')
|
||||||
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
|
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
|
||||||
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
|
$this->backend->createCalendarObject($calendarId, $uri0, $calData[0]);
|
||||||
$uri1 = static::getUniqueID('card');
|
$uri1 = static::getUniqueID('card');
|
||||||
$this->dispatcher->expects($this->at(0))
|
$this->dispatcher->expects($this->at(0))
|
||||||
->method('dispatch')
|
->method('dispatch')
|
||||||
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
|
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
|
||||||
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
|
$this->backend->createCalendarObject($calendarId, $uri1, $calData[1]);
|
||||||
$uri2 = static::getUniqueID('card');
|
$uri2 = static::getUniqueID('card');
|
||||||
$this->dispatcher->expects($this->at(0))
|
$this->dispatcher->expects($this->at(0))
|
||||||
->method('dispatch')
|
->method('dispatch')
|
||||||
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
|
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
|
||||||
$this->backend->createCalendarObject($calendarId, $uri2, $calData);
|
$this->backend->createCalendarObject($calendarId, $uri2, $calData[2]);
|
||||||
|
|
||||||
// get all the cards
|
// get all the cards
|
||||||
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
|
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
|
||||||
|
@ -326,9 +392,15 @@ EOD;
|
||||||
$this->assertArrayHasKey('etag', $card);
|
$this->assertArrayHasKey('etag', $card);
|
||||||
$this->assertArrayHasKey('size', $card);
|
$this->assertArrayHasKey('size', $card);
|
||||||
$this->assertArrayHasKey('classification', $card);
|
$this->assertArrayHasKey('classification', $card);
|
||||||
$this->assertEquals($calData, $card['calendardata']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usort($calendarObjects, function($a, $b) {
|
||||||
|
return $a['id'] - $b['id'];
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertEquals($calData[1], $calendarObjects[0]['calendardata']);
|
||||||
|
$this->assertEquals($calData[2], $calendarObjects[1]['calendardata']);
|
||||||
|
|
||||||
// delete the card
|
// delete the card
|
||||||
$this->dispatcher->expects($this->at(0))
|
$this->dispatcher->expects($this->at(0))
|
||||||
->method('dispatch')
|
->method('dispatch')
|
||||||
|
@ -371,7 +443,26 @@ EOD;
|
||||||
|
|
||||||
public function testGetCalendarObjectByUID() {
|
public function testGetCalendarObjectByUID() {
|
||||||
$calendarId = $this->createTestCalendar();
|
$calendarId = $this->createTestCalendar();
|
||||||
$this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
|
$uri = static::getUniqueID('calobj');
|
||||||
|
$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;
|
||||||
|
|
||||||
|
|
||||||
|
$this->backend->createCalendarObject($calendarId, $uri, $calData);
|
||||||
|
|
||||||
$co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8');
|
$co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8');
|
||||||
$this->assertNotNull($co);
|
$this->assertNotNull($co);
|
||||||
|
|
Loading…
Reference in New Issue