[Pkg-owncloud-commits] [php-sabredav] 40/275: Providing a way to find a calendar object by its UID.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:55:49 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 085cb38770c3aa709c9728cddab1e73cf730d402
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Mon Jan 27 00:55:26 2014 -0500
Providing a way to find a calendar object by its UID.
---
bin/migrateto19.php | 70 +++++++++++++++++++++++++-
examples/sql/mysql.calendars.sql | 1 +
examples/sql/pgsql.calendars.sql | 1 +
examples/sql/sqlite.calendars.sql | 3 +-
lib/Sabre/CalDAV/Backend/PDO.php | 37 +++++++++++---
lib/Sabre/CalDAV/Backend/SchedulingSupport.php | 16 ++++++
lib/Sabre/CalDAV/Schedule/Plugin.php | 2 +-
tests/Sabre/CalDAV/Backend/MockScheduling.php | 38 ++++++++++++++
8 files changed, 159 insertions(+), 9 deletions(-)
diff --git a/bin/migrateto19.php b/bin/migrateto19.php
index a30748e..a39eded 100755
--- a/bin/migrateto19.php
+++ b/bin/migrateto19.php
@@ -77,7 +77,7 @@ switch($driver) {
foreach(['calendar', 'addressbook'] as $itemType) {
- $tableName = $itemType . 's';
+ $tableName = $itemType . 's';
$tableNameOld = $tableName . '_old';
$changesTable = $itemType . 'changes';
@@ -302,4 +302,72 @@ CREATE TABLE calendarsubscriptions (
}
+echo "Upgrading 'calendarobjects'\n";
+$addUid = false;
+try {
+ $result = $pdo->query('SELECT * FROM calendarobjects LIMIT 1');
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+
+ if (!$row) {
+ echo "No data in table. Going to try to add the uid field anyway.\n";
+ $addUid = true;
+ } elseif (array_key_exists('uid', $row)) {
+ echo "uid field eixsts. Assuming that this part of the migration has\n";
+ echo "Already been completed.\n";
+ } else {
+ echo "1.8 schema detected.\n";
+ $addUid = true;
+ }
+
+} catch (Exception $e) {
+ echo "Could not find a calendarobjects table. Skipping this part of the\n";
+ echo "upgrade.\n";
+}
+
+if ($addUid) {
+
+ switch($driver) {
+ case 'mysql' :
+ $pdo->exec('ALTER TABLE calendarobjects ADD uid VARCHAR(200)');
+ break;
+ case 'sqlite' :
+ $pdo->exec('ALTER TABLE calendarobjects ADD uid TEXT');
+ break;
+ }
+
+ $result = $pdo->query('SELECT id, calendardata FROM calendarobjects');
+ $stmt = $pdo->query('UPDATE calendarobjects SET uid = ? WHERE id = ?');
+ $counter = 0;
+
+ while($row = $result->fetch(\PDO::FETCH_ASSOC)) {
+
+ yoyo:
+
+ try {
+ $vobj = \Sabre\VObject\Reader::read($row['calendardata']);
+ } catch (\Exception $e) {
+ echo "Warning! Item with id $row[id] could not be parsed!\n";
+ goto yoyo;
+ }
+ $uid = null;
+ foreach($vobj->select() as $item) {
+ if ($item instanceof \Sabre\VObject\Component) {
+ if ($item->name === 'VTIMEZONE') {
+ continue;
+ }
+ if (!isset($item->UID)) {
+ echo "Warning! Item with id $item[id] does NOT have a UID property and this is required.\n";
+ goto yoyo;
+ }
+ $uid = (string)$uid;
+
+ }
+ }
+ $stmt->exec(array($uid, $row['id']));
+ $counter++;
+
+ }
+
+}
+
echo "Upgrade to 1.9 schema completed.\n";
diff --git a/examples/sql/mysql.calendars.sql b/examples/sql/mysql.calendars.sql
index 1d85f6f..9e27df1 100755
--- a/examples/sql/mysql.calendars.sql
+++ b/examples/sql/mysql.calendars.sql
@@ -9,6 +9,7 @@ CREATE TABLE calendarobjects (
componenttype VARCHAR(8),
firstoccurence INT(11) UNSIGNED,
lastoccurence INT(11) UNSIGNED,
+ uid VARCHAR(200),
UNIQUE(calendarid, uri)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
diff --git a/examples/sql/pgsql.calendars.sql b/examples/sql/pgsql.calendars.sql
index 1564e7e..1c1f5d3 100644
--- a/examples/sql/pgsql.calendars.sql
+++ b/examples/sql/pgsql.calendars.sql
@@ -9,6 +9,7 @@ CREATE TABLE calendars (
calendarcolor VARCHAR(10),
timezone TEXT,
components VARCHAR(20),
+ uid VARCHAR(200),
transparent SMALLINT NOT NULL DEFAULT '0'
);
diff --git a/examples/sql/sqlite.calendars.sql b/examples/sql/sqlite.calendars.sql
index e4b24c8..4a17f0d 100644
--- a/examples/sql/sqlite.calendars.sql
+++ b/examples/sql/sqlite.calendars.sql
@@ -8,7 +8,8 @@ CREATE TABLE calendarobjects (
size integer,
componenttype text,
firstoccurence integer,
- lastoccurence integer
+ lastoccurence integer,
+ uid text
);
CREATE TABLE calendars (
diff --git a/lib/Sabre/CalDAV/Backend/PDO.php b/lib/Sabre/CalDAV/Backend/PDO.php
index 384f418..14db6fd 100755
--- a/lib/Sabre/CalDAV/Backend/PDO.php
+++ b/lib/Sabre/CalDAV/Backend/PDO.php
@@ -528,7 +528,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
$extraData = $this->getDenormalizedData($calendarData);
- $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarObjectTableName.' (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence) VALUES (?,?,?,?,?,?,?,?,?)');
+ $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarObjectTableName.' (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid) VALUES (?,?,?,?,?,?,?,?,?,?)');
$stmt->execute([
$calendarId,
$objectUri,
@@ -539,6 +539,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
$extraData['componentType'],
$extraData['firstOccurence'],
$extraData['lastOccurence'],
+ $extraData['uid'],
]);
$this->addChange($calendarId, $objectUri, 1);
@@ -568,8 +569,8 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
$extraData = $this->getDenormalizedData($calendarData);
- $stmt = $this->pdo->prepare('UPDATE '.$this->calendarObjectTableName.' SET calendardata = ?, lastmodified = ?, etag = ?, size = ?, componenttype = ?, firstoccurence = ?, lastoccurence = ? WHERE calendarid = ? AND uri = ?');
- $stmt->execute([$calendarData, time(), $extraData['etag'], $extraData['size'], $extraData['componentType'], $extraData['firstOccurence'], $extraData['lastOccurence'], $calendarId, $objectUri]);
+ $stmt = $this->pdo->prepare('UPDATE '.$this->calendarObjectTableName.' SET calendardata = ?, lastmodified = ?, etag = ?, size = ?, componenttype = ?, firstoccurence = ?, lastoccurence = ?, uid = ? WHERE calendarid = ? AND uri = ?');
+ $stmt->execute([$calendarData, time(), $extraData['etag'], $extraData['size'], $extraData['componentType'], $extraData['firstOccurence'], $extraData['lastOccurence'], $extraData['uid'], $calendarId, $objectUri]);
$this->addChange($calendarId, $objectUri, 2);
@@ -582,11 +583,12 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
* calendar-queries.
*
* Returns an array with the following keys:
- * * etag
- * * size
- * * componentType
+ * * etag - An md5 checksum of the object without the quotes.
+ * * size - Size of the object in bytes
+ * * componentType - VEVENT, VTODO or VJOURNAL
* * firstOccurence
* * lastOccurence
+ * * uid - value of the UID property
*
* @param string $calendarData
* @return array
@@ -598,9 +600,11 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
$component = null;
$firstOccurence = null;
$lastOccurence = null;
+ $uid = null;
foreach($vObject->getComponents() as $component) {
if ($component->name!=='VTIMEZONE') {
$componentType = $component->name;
+ $uid = (string)$component->UID;
break;
}
}
@@ -648,6 +652,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
'componentType' => $componentType,
'firstOccurence' => $firstOccurence,
'lastOccurence' => $lastOccurence,
+ 'uid' => $uid,
];
}
@@ -1264,4 +1269,24 @@ 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.
+ *
+ * The returned data should contain all the information getCalendarObject
+ * also returns, but also include a 'calendarUri' property. This property
+ * should *just* be the basename of the calendar.
+ *
+ * Return false if the object cannot be found.
+ *
+ * @param string $principalUri
+ * @param string $uid
+ * @return array|bool
+ */
+ public function getCalendarObjectByUID($principalUri, $uid) {
+
+ throw new \Exception('Not implemented yet');
+
+ }
+
}
diff --git a/lib/Sabre/CalDAV/Backend/SchedulingSupport.php b/lib/Sabre/CalDAV/Backend/SchedulingSupport.php
index 838ba1b..43c0cb0 100644
--- a/lib/Sabre/CalDAV/Backend/SchedulingSupport.php
+++ b/lib/Sabre/CalDAV/Backend/SchedulingSupport.php
@@ -62,4 +62,20 @@ interface SchedulingSupport extends BackendInterface {
*/
public function createSchedulingObject($principalUri, $objectUri, $objectData);
+ /**
+ * Searches through all of a users calendars and calendar objects to find
+ * an object with a specific UID.
+ *
+ * The returned data should contain all the information getCalendarObject
+ * also returns, but also include a 'calendarUri' property. This property
+ * should *just* be the basename of the calendar.
+ *
+ * Return false if the object cannot be found.
+ *
+ * @param string $principalUri
+ * @param string $uid
+ * @return array|bool
+ */
+ public function getCalendarObjectByUID($principalUri, $uid);
+
}
diff --git a/lib/Sabre/CalDAV/Schedule/Plugin.php b/lib/Sabre/CalDAV/Schedule/Plugin.php
index 6d91d0c..e4b0ffe 100644
--- a/lib/Sabre/CalDAV/Schedule/Plugin.php
+++ b/lib/Sabre/CalDAV/Schedule/Plugin.php
@@ -506,6 +506,7 @@ class Plugin extends ServerPlugin {
'{DAV:}principal-URL',
$caldavNS . 'calendar-home-set',
$caldavNS . 'schedule-inbox-URL',
+ $caldavNS . 'schedule-default-calendar-URL',
'{http://sabredav.org/ns}email-address',
]
);
@@ -525,7 +526,6 @@ class Plugin extends ServerPlugin {
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
-
}
/**
diff --git a/tests/Sabre/CalDAV/Backend/MockScheduling.php b/tests/Sabre/CalDAV/Backend/MockScheduling.php
index 8aa1f79..3c7d849 100644
--- a/tests/Sabre/CalDAV/Backend/MockScheduling.php
+++ b/tests/Sabre/CalDAV/Backend/MockScheduling.php
@@ -89,4 +89,42 @@ class MockScheduling extends Mock implements SchedulingSupport {
}
+ /**
+ * Searches through all of a users calendars and calendar objects to find
+ * an object with a specific UID.
+ *
+ * The returned data should contain all the information getCalendarObject
+ * also returns, but also include a 'calendarUri' property. This property
+ * should *just* be the basename of the calendar.
+ *
+ * Return false if the object cannot be found.
+ *
+ * @param string $principalUri
+ * @param string $uid
+ * @return array|bool
+ */
+ public function getCalendarObjectByUID($principalUri, $uid) {
+
+ // Super slow mode...
+ foreach($this->getCalendarsForUser($principalUri) as $calendar) {
+ foreach($this->getCalendarObjects($calendar['id']) as $calendarObject) {
+ $vobj = \Sabre\VObject\Reader::read($calendarObject['calendardata']);
+ foreach($vobj->children as $child) {
+ if (!$child instanceof \Sabre\VObject\Component) {
+ continue;
+ }
+ if (!isset($child->UID)) {
+ continue;
+ }
+ if ($child->UID->getValue() !== $uid) {
+ continue 2;
+ }
+ $calendarObject['calendarUri'] = $calendar['uri'];
+ return $calendarObject;
+ }
+ }
+ }
+
+ }
+
}
--
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