Add PUT support, CalDAV event can now be created and updated too.
authorJan Schneider <jan@horde.org>
Wed, 11 Aug 2010 15:09:39 +0000 (17:09 +0200)
committerJan Schneider <jan@horde.org>
Wed, 11 Aug 2010 15:34:56 +0000 (17:34 +0200)
kronolith/docs/CHANGES
kronolith/lib/Driver/Ical.php

index ea550c9..4f09069 100644 (file)
@@ -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).
index dfe0263..30db150 100644 (file)
@@ -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.