From 263e2fa305ba2396d804c8a6f2f75d1fa4270eaf Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 11 Aug 2010 17:09:39 +0200 Subject: [PATCH] Add PUT support, CalDAV event can now be created and updated too. --- kronolith/docs/CHANGES | 1 + kronolith/lib/Driver/Ical.php | 68 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/kronolith/docs/CHANGES b/kronolith/docs/CHANGES index ea550c959..4f09069d9 100644 --- a/kronolith/docs/CHANGES +++ b/kronolith/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Add CalDAV client support (Request #8525). [jan] Send agenda emails with HTML part and convert to Horde_View. [mjr] More complete handling of recurring event exceptions when dealing with the iCalendar format (Request #9091). diff --git a/kronolith/lib/Driver/Ical.php b/kronolith/lib/Driver/Ical.php index dfe02633a..30db15095 100644 --- a/kronolith/lib/Driver/Ical.php +++ b/kronolith/lib/Driver/Ical.php @@ -277,7 +277,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $event = new Kronolith_Event_Ical($this); $event->status = Kronolith::STATUS_FREE; $event->permission = $this->getPermission(); - $event->fromiCalendar($component); + $event->fromDriver($component); // Force string so JSON encoding is consistent across drivers. $event->id = $id ? $id : 'ical' . $i; @@ -368,7 +368,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $event = new Kronolith_Event_Ical($this); $event->status = Kronolith::STATUS_FREE; $event->permission = $this->getPermission(); - $event->fromiCalendar($components[$eventId]); + $event->fromDriver($components[$eventId]); $event->id = 'ical' . $eventId; return $event; } @@ -377,6 +377,70 @@ class Kronolith_Driver_Ical extends Kronolith_Driver } /** + * Updates an existing event in the backend. + * + * @param Kronolith_Event $event The event to save. + * + * @return string The event id. + * @throws Horde_Mime_Exception + * @throws Kronolith_Exception + */ + protected function _updateEvent($event) + { + $response = $this->_saveEvent($event); + if (!in_array($response->code, array(200, 204))) { + Horde::logMessage(sprintf('Failed to update event on remote calendar: url = "%s", status = %s', + $url, $response->code), 'INFO'); + throw new Kronolith_Exception(_("The event could not be updated on the remote server.")); + } + return $event->id; + } + + /** + * Adds an event to the backend. + * + * @param Kronolith_Event $event The event to save. + * + * @return string The event id. + * @throws Horde_Mime_Exception + * @throws Kronolith_Exception + */ + protected function _addEvent($event) + { + $response = $this->_saveEvent($event); + if (!in_array($response->code, array(200, 201, 204))) { + Horde::logMessage(sprintf('Failed to create event on remote calendar: url = "%s", status = %s', + $url, $response->code), 'INFO'); + throw new Kronolith_Exception(_("The event could not be added to the remote server.")); + } + return $event->id; + } + + /** + * Updates an existing event in the backend. + * + * @param Kronolith_Event $event The event to save. + * + * @return string The event id. + * @throws Horde_Mime_Exception + * @throws Kronolith_Exception + */ + protected function _saveEvent($event) + { + $ical = new Horde_Icalendar(); + $ical->addComponent($event->toiCalendar($ical)); + + $url = trim($this->_getUrl(), '/') . '/' . $event->id; + try { + $response = $this->_getClient()->put($url, $ical->exportvCalendar()); + } catch (Horde_Http_Exception $e) { + Horde::logMessage($e, 'INFO'); + throw new Kronolith_Exception($e); + } + return $response; + } + + /** * Deletes an event. * * @param string $eventId The ID of the event to delete. -- 2.11.0