[Pkg-owncloud-commits] [php-sabredav] 32/42: Added getCalendarObjectByUID to PDO backend.
David Prévot
taffit at moszumanska.debian.org
Wed Oct 29 20:52:07 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit ac40003961a1b500332b45889cf1571b844b5775
Author: Evert Pot <me at evertpot.com>
Date: Thu Oct 23 20:44:57 2014 -0400
Added getCalendarObjectByUID to PDO backend.
Fixes #529
---
ChangeLog.md | 3 ++
lib/CalDAV/Backend/PDO.php | 44 ++++++++++++++++++++++++++
tests/Sabre/CalDAV/Backend/AbstractPDOTest.php | 20 ++++++++++++
3 files changed, 67 insertions(+)
diff --git a/ChangeLog.md b/ChangeLog.md
index c71404c..7467349 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -19,6 +19,9 @@ ChangeLog
backends are now deprecated. They still work, but will be removed in the
next major sabredav version. Every argument that is now deprecated can now
be accessed as a public property on the respective backends.
+* #529: Added getCalendarObjectByUID to PDO backend, speeding up scheduling
+ operations on large calendars.
+
2.1.0-alpha1 (2014-09-23)
-------------------------
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index 9d6e539..001d1b2 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -754,6 +754,50 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
}
/**
+ * Searches through all of a users calendars and calendar objects to find
+ * an object with a specific UID.
+ *
+ * This method should return the path to this object, relative to the
+ * calendar home, so this path usually only contains two parts:
+ *
+ * calendarpath/objectpath.ics
+ *
+ * If the uid is not found, return null.
+ *
+ * This method should only consider * objects that the principal owns, so
+ * any calendars owned by other principals that also appear in this
+ * collection should be ignored.
+ *
+ * @param string $principalUri
+ * @param string $uid
+ * @return string|null
+ */
+ function getCalendarObjectByUID($principalUri, $uid) {
+
+ $query = <<<SQL
+SELECT
+ calendars.uri AS calendaruri, calendarobjects.uri as objecturi
+FROM
+ calendarobjects
+LEFT JOIN
+ calendars
+ ON calendarobjects.calendarid = calendars.id
+WHERE
+ calendars.principaluri = ?
+ AND
+ calendarobjects.uid = ?
+SQL;
+
+ $stmt = $this->pdo->prepare($query);
+ $stmt->execute([$principalUri, $uid]);
+
+ if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ return $row['calendaruri'] . '/' . $row['objecturi'];
+ }
+
+ }
+
+ /**
* The getChanges method returns all the changes that have happened, since
* the specified syncToken in the specified calendar.
*
diff --git a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
index 13145a3..54fbc92 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
@@ -419,6 +419,26 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * @depends testCreateCalendarObject
+ */
+ function testGetCalendarObjectByUID() {
+
+ $backend = new PDO($this->pdo);
+ $returnedId = $backend->createCalendar('principals/user2','somerandomid',[]);
+
+ $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
+ $backend->createCalendarObject($returnedId, 'random-id', $object);
+
+ $this->assertNull(
+ $backend->getCalendarObjectByUID('principals/user2', 'bar')
+ );
+ $this->assertEquals(
+ 'somerandomid/random-id',
+ $backend->getCalendarObjectByUID('principals/user2', 'foo')
+ );
+
+ }
/**
* @depends testCreateCalendarObject
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list