[Pkg-owncloud-commits] [php-sabredav] 94/275: Handling event updates by the organizer and processing for the attendee.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:55:56 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 a9c0c41a2ee1745274b2ac894b3faf74f35b6093
Author: Evert Pot <me at evertpot.com>
Date: Thu Jul 17 23:44:30 2014 -0400
Handling event updates by the organizer and processing for the attendee.
---
lib/CalDAV/Schedule/Plugin.php | 125 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 112 insertions(+), 13 deletions(-)
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index ed54e9d..8e4e52e 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -192,6 +192,7 @@ class Plugin extends ServerPlugin {
$server->on('method:POST', [$this,'httpPost']);
$server->on('propFind', [$this, 'propFind']);
$server->on('beforeCreateFile', [$this, 'beforeCreateFile']);
+ $server->on('beforeWriteContent', [$this, 'beforeWriteContent']);
$server->on('schedule', [$this, 'scheduleLocalDelivery']);
/**
@@ -377,13 +378,99 @@ class Plugin extends ServerPlugin {
if (!isset($vObj->VEVENT)) {
return;
}
+ $vevent = $vObj->VEVENT[0];
+
+ $organizer = null;
+
+ if ($vevent[0]->ORGANIZER) {
+ $organizer = (string)$vevent->ORGANIZER;
+ }
+
+ // If the object doesn't have organizer or attendee information, we can
+ // ignore it.
+ if (!$organizer || !isset($vevent->ATTENDEE)) {
+ return;
+ }
+
+ $addresses = $this->getAddressesForPrincipal(
+ $parentNode->getOwner()
+ );
+
+ // We're only handling creation of new objects by the ORGANIZER.
+ // Support for ATTENDEE will come later.
+ if (!in_array($organizer, $addresses)) {
+ return;
+ }
+
+ $broker = new VObject\ITip\Broker();
+ $messages = $broker->parseNewEvent($vObj);
+
+ foreach($messages as $message) {
+
+ $this->deliver($message);
+
+ foreach($vObj->VEVENT->ATTENDEE as $attendee) {
+
+ if ($attendee->getValue() === $message->recipient) {
+ $attendee['SCHEDULE-STATUS'] = $message->scheduleStatus;
+ break;
+ }
+
+ }
+
+ }
+
+ // After all this exciting action we set $data to the updated event
+ // that contains all the new status information (if any).
+ $newData = $vObj->serialize();
+ if ($newData !== $data) {
+ $data = $newData;
+
+ // Setting $modified tells sabredav that the object has changed,
+ // and that no ETag must be sent back.
+ $modified = true;
+ }
+
+ }
+
+ /**
+ * This method is triggered before a file gets updated with new content.
+ *
+ * We use this event to process any changes to scheduling objects.
+ *
+ * @param string $path
+ * @param DAV\IFile $node
+ * @param resource|string $data
+ * @param bool $modified
+ * @return void
+ */
+ public function beforeWriteContent($path, DAV\IFile $node, &$data, &$modified) {
+
+ if (!$parentNode instanceof ICalendar) {
+ return;
+ }
+
+ // It's a calendar, so the contents are most likely an iCalendar
+ // object. It's time to start processing this.
+ //
+ // This step also ensures that $data is re-propagated with a string
+ // version of the object.
+ if (is_resource($data)) {
+ $data = stream_get_contents($data);
+ }
+
+ $vObj = VObject\Reader::read($data);
+
+ // At the moment we only support VEVENT. VTODO may come later.
+ if (!isset($vObj->VEVENT)) {
+ return;
+ }
// At the moment we only process the first VEVENT. Any other overridden
// event will get ignored for the moment.
$vevent = $vObj->VEVENT[0];
$organizer = null;
- $attendees = [];
if ($vevent->ORGANIZER) {
$organizer = (string)$vevent->ORGANIZER;
@@ -405,8 +492,11 @@ class Plugin extends ServerPlugin {
return;
}
+ // Fetching the current event body.
+ $oldEvent = Reader::read($node->get());
+
$broker = new VObject\ITip\Broker();
- $messages = $broker->createEvent($vObj);
+ $messages = $broker->parseUpdatedEvent($vObj, $oldEvent);
foreach($messages as $message) {
@@ -433,7 +523,6 @@ class Plugin extends ServerPlugin {
// and that no ETag must be sent back.
$modified = true;
}
-
}
/**
@@ -526,22 +615,32 @@ class Plugin extends ServerPlugin {
$home = $this->server->tree->getNodeForPath($homePath);
$inbox = $this->server->tree->getNodeForPath($inboxPath);
- $result = $home->getCalendarObjectByUID($uid);
+ $currentObject = null;
+ $objectNode = null;
+ $isNewNode = false;
- if (!$result) {
- // This was a new item
+ $result = $home->getCalendarObjectByUID($uid);
+ if ($result) {
+ // There was an existing object, we need to update probably.
+ $objectPath = $homePath . '/' . $result;
+ $objectNode = $this->server->tree->getNodeForPath($objectPath);
+ $currentObject = Reader::read($objectNode->get());
+ } else {
+ $isNewNode = true;
+ }
- $calendar = $this->server->tree->getNodeForPath($calendarPath);
+ $broker = new VObject\ITip\Broker();
+ $newObject = $broker->processMessage($iTipMessage, $currentObject);
- $inbox->createFile($newFileName, $iTipMessage->message->serialize());
- $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+ $inbox->createFile($newFileName, $iTipMessage->message->serialize());
+ if ($isNewNode) {
+ $calendar = $this->server->tree->getNodeForPath($calendarPath);
+ $calendar->createFile($newFileName, $newObject->serialize());
} else {
-
- // We need to find the current version of the calendar object.
- throw new \Exception('Not implemented');
-
+ $objectNode->put($newObject->serialize());
}
+ $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
}
--
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