Catch Icalendar exceptions.
authorJan Schneider <jan@horde.org>
Wed, 4 Aug 2010 16:13:58 +0000 (18:13 +0200)
committerJan Schneider <jan@horde.org>
Wed, 4 Aug 2010 16:13:58 +0000 (18:13 +0200)
kronolith/lib/Ajax/Application.php
kronolith/lib/Api.php
kronolith/lib/Driver/Ical.php

index ca42a16..68885da 100644 (file)
@@ -826,14 +826,14 @@ class Kronolith_Ajax_Application extends Horde_Core_Ajax_Application
             $driver->open($this->_vars->url);
             $ical = $driver->getRemoteCalendar(false);
             $result->success = true;
-            $name = $ical->getAttribute('X-WR-CALNAME');
-            if (!($name instanceof PEAR_Error)) {
+            try {
+                $name = $ical->getAttribute('X-WR-CALNAME');
                 $result->name = $name;
-            }
-            $desc = $ical->getAttribute('X-WR-CALDESC');
-            if (!($desc instanceof PEAR_Error)) {
+            } catch (Horde_Icalendar_Exception $e) {}
+            try {
+                $desc = $ical->getAttribute('X-WR-CALDESC');
                 $result->desc = $desc;
-            }
+            } catch (Horde_Icalendar_Exception $e) {}
         } catch (Exception $e) {
             if ($e->getCode() == 401) {
                 $result->auth = true;
index 9e945a7..661e8c2 100644 (file)
@@ -648,10 +648,10 @@ class Kronolith_Api extends Horde_Registry_Api
                     // Need to ensure that the original recurring event is
                     // added before any of the instance exceptions. Easiest way
                     // to do that is just add all the recurrence-id entries last
-                    $recurrenceId = $content->getAttribute('RECURRENCE-ID');
-                    if (!($recurrenceId instanceof PEAR_Error)) {
+                    try {
+                        $recurrenceId = $content->getAttribute('RECURRENCE-ID');
                         $recurrences[] = $content;
-                    } else {
+                    } catch (Horde_Icalendar_Exception $e) {
                         $ids[] = $this->_addiCalEvent($content, $kronolith_driver);
                     }
                 }
index 28a4372..680f6bc 100644 (file)
@@ -127,12 +127,14 @@ class Kronolith_Driver_Ical extends Kronolith_Driver
 
                 /* Catch RECURRENCE-ID attributes which mark single recurrence
                  * instances. */
-                $recurrence_id = $component->getAttribute('RECURRENCE-ID');
-                if (is_int($recurrence_id) &&
-                    is_string($uid = $component->getAttribute('UID')) &&
-                    is_int($seq = $component->getAttribute('SEQUENCE'))) {
-                    $exceptions[$uid][$seq] = $recurrence_id;
-                }
+                try {
+                    $recurrence_id = $component->getAttribute('RECURRENCE-ID');
+                    if (is_int($recurrence_id) &&
+                        is_string($uid = $component->getAttribute('UID')) &&
+                        is_int($seq = $component->getAttribute('SEQUENCE'))) {
+                        $exceptions[$uid][$seq] = $recurrence_id;
+                    }
+                } catch (Horde_Icalendar_Exception $e) {}
 
                 /* Ignore events out of the period. */
                 if (
@@ -199,7 +201,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver
      *
      * @param boolean $cache  Whether to return data from the session cache.
      *
-     * @return Horde_Icalendar  The calendar data, or an error on failure.
+     * @return Horde_Icalendar  The calendar data.
      * @throws Kronolith_Exception
      */
     public function getRemoteCalendar($cache = true)
@@ -253,13 +255,18 @@ class Kronolith_Driver_Ical extends Kronolith_Driver
 
         $data = $response->getBody();
         $ical = new Horde_Icalendar();
-        $result = $ical->parsevCalendar($data);
+        try {
+            $result = $ical->parsevCalendar($data);
+        } catch (Horde_Icalendar_Exception $e) {
+            if ($cache) {
+                $cacheOb->set($signature, serialize($e->getMessage()));
+            }
+            throw new Kronolith_Exception($e);
+        }
+
         if ($cache) {
             $cacheOb->set($signature, serialize($ical));
         }
-        if ($result instanceof PEAR_Error) {
-            throw new Kronolith_Exception($result);
-        }
 
         return $ical;
     }