[Pkg-owncloud-commits] [php-sabredav] 12/42: calendar-timezone support for calendar-query and calendar-multiget.
David Prévot
taffit at moszumanska.debian.org
Fri Nov 28 22:47:48 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 fbc02ec7a17f7ab26306cda258b7d84354d0f195
Author: Evert Pot <me at evertpot.com>
Date: Thu Nov 13 19:38:14 2014 -0500
calendar-timezone support for calendar-query and calendar-multiget.
---
composer.json | 2 +-
lib/CalDAV/Plugin.php | 77 ++++++++++++++++++----
.../Sabre/CalDAV/ExpandEventsFloatingTimeTest.php | 61 +++++++++++++++--
3 files changed, 118 insertions(+), 22 deletions(-)
diff --git a/composer.json b/composer.json
index ba56d58..8f9a6ae 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,7 @@
],
"require": {
"php": ">=5.4.1",
- "sabre/vobject": "~3.3.2",
+ "sabre/vobject": "~3.3 at dev",
"sabre/event" : "~2.0.0",
"sabre/http" : "~3.0.0",
"ext-dom": "*",
diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index 8c9f14b..78f3a9b 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -2,15 +2,15 @@
namespace Sabre\CalDAV;
-use
- Sabre\DAV,
- Sabre\DAV\Property\HrefList,
- Sabre\DAVACL,
- Sabre\VObject,
- Sabre\HTTP,
- Sabre\HTTP\URLUtil,
- Sabre\HTTP\RequestInterface,
- Sabre\HTTP\ResponseInterface;
+use DateTimeZone;
+use Sabre\DAV;
+use Sabre\DAV\Property\HrefList;
+use Sabre\DAVACL;
+use Sabre\VObject;
+use Sabre\HTTP;
+use Sabre\HTTP\URLUtil;
+use Sabre\HTTP\RequestInterface;
+use Sabre\HTTP\ResponseInterface;
/**
* CalDAV plugin
@@ -456,12 +456,36 @@ class Plugin extends DAV\ServerPlugin {
$uris[] = $this->server->calculateUri($elem->nodeValue);
}
+ $tz = null;
+
+ $timeZones = [];
+
foreach($this->server->getPropertiesForMultiplePaths($uris, $properties) as $uri=>$objProps) {
if (($needsJson || $expand) && isset($objProps[200]['{' . self::NS_CALDAV . '}calendar-data'])) {
$vObject = VObject\Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']);
+
if ($expand) {
- $vObject->expand($start, $end);
+ // We're expanding, and for that we need to figure out the
+ // calendar's timezone.
+ list($calendarPath) = URLUtil::splitPath($uri);
+ if (!isset($timeZones[$calendarPath])) {
+ // Checking the calendar-timezone property.
+ $tzProp = '{' . self::NS_CALDAV . '}calendar-timezone';
+ $tzResult = $this->server->getProperties($calendarPath, [$tzProp]);
+ if (isset($tzResult[$tzProp])) {
+ // This property contains a VCALENDAR with a single
+ // VTIMEZONE.
+ $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
+ $timeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
+ } else {
+ // Defaulting to UTC.
+ $timeZone = new DateTimeZone('UTC');
+ }
+ $timeZones[$calendarPath] = $timeZone;
+ }
+
+ $vObject->expand($start, $end, $timeZones[$calendarPath]);
}
if ($needsJson) {
$objProps[200]['{' . self::NS_CALDAV . '}calendar-data'] = json_encode($vObject->jsonSerialize());
@@ -497,6 +521,8 @@ class Plugin extends DAV\ServerPlugin {
$parser = new CalendarQueryParser($dom);
$parser->parse();
+ $path = $this->server->getRequestUri();
+
// TODO: move this into CalendarQueryParser
$xpath = new \DOMXPath($dom);
$xpath->registerNameSpace('cal',Plugin::NS_CALDAV);
@@ -509,6 +535,24 @@ class Plugin extends DAV\ServerPlugin {
// The default result is an empty array
$result = [];
+ $calendarTimeZone = null;
+ if ($parser->expand) {
+ // We're expanding, and for that we need to figure out the
+ // calendar's timezone.
+ $tzProp = '{' . self::NS_CALDAV . '}calendar-timezone';
+ $tzResult = $this->server->getProperties($path, [$tzProp]);
+ if (isset($tzResult[$tzProp])) {
+ // This property contains a VCALENDAR with a single
+ // VTIMEZONE.
+ $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
+ $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
+ unset($vtimezoneObj);
+ } else {
+ // Defaulting to UTC.
+ $calendarTimeZone = new DateTimeZone('UTC');
+ }
+ }
+
// The calendarobject was requested directly. In this case we handle
// this locally.
if ($depth == 0 && $node instanceof ICalendarObject) {
@@ -527,7 +571,7 @@ class Plugin extends DAV\ServerPlugin {
}
$properties = $this->server->getPropertiesForPath(
- $this->server->getRequestUri(),
+ $path,
$requestedProperties,
0
);
@@ -550,9 +594,10 @@ class Plugin extends DAV\ServerPlugin {
if (!$requestedCalendarData) {
unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
} else {
- if ($parser->expand) {
- $vObject->expand($parser->expand['start'], $parser->expand['end']);
+
+ if ($parser->expand) {
+ $vObject->expand($parser->expand['start'], $parser->expand['end'], $calendarTimeZone);
}
if ($needsJson) {
$properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = json_encode($vObject->jsonSerialize());
@@ -575,6 +620,8 @@ class Plugin extends DAV\ServerPlugin {
$nodePaths = $node->calendarQuery($parser->filters);
+ $timeZones = [];
+
foreach($nodePaths as $path) {
list($properties) =
@@ -582,9 +629,11 @@ class Plugin extends DAV\ServerPlugin {
if (($needsJson || $parser->expand)) {
$vObject = VObject\Reader::read($properties[200]['{' . self::NS_CALDAV . '}calendar-data']);
+
if ($parser->expand) {
- $vObject->expand($parser->expand['start'], $parser->expand['end']);
+ $vObject->expand($parser->expand['start'], $parser->expand['end'], $calendarTimeZone);
}
+
if ($needsJson) {
$properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = json_encode($vObject->jsonSerialize());
} else {
diff --git a/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php b/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
index 2c4df9f..b58f194 100644
--- a/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
+++ b/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
@@ -18,7 +18,7 @@ class ExpandEventsFloatingTimeTest extends \Sabre\DAVServerTest {
'name' => 'Calendar',
'principaluri' => 'principals/user1',
'uri' => 'calendar1',
- 'timezone' => 'BEGIN:VCALENDAR
+ '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
@@ -64,13 +64,11 @@ END:VCALENDAR
),
);
- function testExpand() {
+ function testExpandCalendarQuery() {
- $request = HTTP\Sapi::createFromServerArray([
- 'REQUEST_METHOD' => 'REPORT',
- 'HTTP_CONTENT_TYPE' => 'application/xml',
- 'REQUEST_URI' => '/calendars/user1/calendar1',
- 'HTTP_DEPTH' => '1',
+ $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
+ 'Depth' => 1,
+ 'Content-Type' => 'application/xml',
]);
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
@@ -119,5 +117,54 @@ END:VCALENDAR
}
}
+ function testExpandMultiGet() {
+
+ $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
+ 'Depth' => 1,
+ 'Content-Type' => 'application/xml',
+ ]);
+
+ $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
+<C:calendar-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
+ <D:prop>
+ <C:calendar-data>
+ <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
+ </C:calendar-data>
+ <D:getetag/>
+ </D:prop>
+ <D:href>/calendars/user1/calendar1/event.ics</D:href>
+</C:calendar-multiget>');
+
+ $response = $this->request($request);
+
+ $this->assertEquals(207, $response->getStatus());
+
+ // Everts super awesome xml parser.
+ $body = substr(
+ $response->body,
+ $start = strpos($response->body, 'BEGIN:VCALENDAR'),
+ strpos($response->body, 'END:VCALENDAR') - $start + 13
+ );
+ $body = str_replace('
','',$body);
+
+ $vObject = VObject\Reader::read($body);
+
+ // check if DTSTARTs and DTENDs are correct
+ foreach ($vObject->VEVENT as $vevent) {
+ /** @var $vevent Sabre\VObject\Component\VEvent */
+ foreach ($vevent->children as $child) {
+ /** @var $child Sabre\VObject\Property */
+
+ if ($child->name == 'DTSTART') {
+ // DTSTART should be the UTC equivalent of given floating time
+ $this->assertEquals($child->getValue(), '20141108T043000Z');
+ } elseif ($child->name == 'DTEND') {
+ // DTEND should be the UTC equivalent of given floating time
+ $this->assertEquals($child->getValue(), '20141108T063000Z');
+ }
+ }
+ }
+ }
+
}
--
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