summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-16 15:49:46 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-16 15:49:46 +0100
commit867fd94dc663652da1465de8537f01b8c7b4db07 (patch)
treeb7c682e73246f51a04faea271c3a01d870f20974 /apps
parent23e7a62717fe6ee84c54ce1d3c601b477119696e (diff)
downloadnextcloud-server-867fd94dc663652da1465de8537f01b8c7b4db07.tar.gz
nextcloud-server-867fd94dc663652da1465de8537f01b8c7b4db07.zip
Add scheduling backend
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/caldav/caldavbackend.php58
-rw-r--r--apps/dav/tests/unit/caldav/caldavbackendtest.php14
2 files changed, 68 insertions, 4 deletions
diff --git a/apps/dav/lib/caldav/caldavbackend.php b/apps/dav/lib/caldav/caldavbackend.php
index 6dd60c43336..4dcd1bed3de 100644
--- a/apps/dav/lib/caldav/caldavbackend.php
+++ b/apps/dav/lib/caldav/caldavbackend.php
@@ -982,7 +982,26 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @return array
*/
function getSchedulingObject($principalUri, $objectUri) {
- // TODO: Implement getSchedulingObject() method.
+ $query = $this->db->getQueryBuilder();
+ $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size'])
+ ->from('schedulingobjects')
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
+ ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
+ ->execute();
+
+ $row = $stmt->fetch(\PDO::FETCH_ASSOC);
+
+ if(!$row) {
+ return null;
+ }
+
+ return [
+ 'uri' => $row['uri'],
+ 'calendardata' => $row['calendardata'],
+ 'lastmodified' => $row['lastmodified'],
+ 'etag' => '"' . $row['etag'] . '"',
+ 'size' => (int)$row['size'],
+ ];
}
/**
@@ -997,7 +1016,24 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @return array
*/
function getSchedulingObjects($principalUri) {
- // TODO: Implement getSchedulingObjects() method.
+ $query = $this->db->getQueryBuilder();
+ $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size'])
+ ->from('schedulingobjects')
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
+ ->execute();
+
+ $result = [];
+ foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
+ $result[] = [
+ 'calendardata' => $row['calendardata'],
+ 'uri' => $row['uri'],
+ 'lastmodified' => $row['lastmodified'],
+ 'etag' => '"' . $row['etag'] . '"',
+ 'size' => (int)$row['size'],
+ ];
+ }
+
+ return $result;
}
/**
@@ -1008,7 +1044,11 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @return void
*/
function deleteSchedulingObject($principalUri, $objectUri) {
- // TODO: Implement deleteSchedulingObject() method.
+ $query = $this->db->getQueryBuilder();
+ $query->delete('schedulingobjects')
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)))
+ ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri)))
+ ->execute();
}
/**
@@ -1020,7 +1060,17 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
* @return void
*/
function createSchedulingObject($principalUri, $objectUri, $objectData) {
- // TODO: Implement createSchedulingObject() method.
+ $query = $this->db->getQueryBuilder();
+ $query->insert('schedulingobjects')
+ ->values([
+ 'principaluri' => $query->createNamedParameter($principalUri),
+ 'calendardata' => $query->createNamedParameter($objectData),
+ 'uri' => $query->createNamedParameter($objectUri),
+ 'lastmodified' => $query->createNamedParameter(time()),
+ 'etag' => $query->createNamedParameter(md5($objectData)),
+ 'size' => $query->createNamedParameter(strlen($objectData))
+ ])
+ ->execute();
}
/**
diff --git a/apps/dav/tests/unit/caldav/caldavbackendtest.php b/apps/dav/tests/unit/caldav/caldavbackendtest.php
index beb88a398b9..5e3d4288aa7 100644
--- a/apps/dav/tests/unit/caldav/caldavbackendtest.php
+++ b/apps/dav/tests/unit/caldav/caldavbackendtest.php
@@ -322,4 +322,18 @@ EOD;
$this->assertEquals(0, count($subscriptions));
}
+ public function testScheduling() {
+ $this->backend->createSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule', '');
+
+ $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER);
+ $this->assertEquals(1, count($sos));
+
+ $so = $this->backend->getSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule');
+ $this->assertNotNull($so);
+
+ $this->backend->deleteSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule');
+
+ $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER);
+ $this->assertEquals(0, count($sos));
+ }
}