Replace is_a() calls.
authorJan Schneider <jan@horde.org>
Fri, 12 Feb 2010 12:21:37 +0000 (13:21 +0100)
committerJan Schneider <jan@horde.org>
Fri, 12 Feb 2010 12:21:37 +0000 (13:21 +0100)
Fade out PEAR_Error.

26 files changed:
kronolith/contacts.php
kronolith/data.php
kronolith/edit.php
kronolith/event.php
kronolith/lib/Ajax/Application.php
kronolith/lib/Api.php
kronolith/lib/Application.php
kronolith/lib/Driver.php
kronolith/lib/Driver/Holidays.php
kronolith/lib/Driver/Ical.php
kronolith/lib/Driver/Kolab.php
kronolith/lib/Driver/Resource.php
kronolith/lib/Driver/Sql.php
kronolith/lib/Event.php
kronolith/lib/FreeBusy.php
kronolith/lib/Kronolith.php
kronolith/lib/Storage/sql.php
kronolith/lib/Tagger.php
kronolith/lib/View/Event.php
kronolith/lib/tests/allday.phpt
kronolith/lib/tests/bug6031.phpt
kronolith/lib/tests/bug7068.phpt
kronolith/perms.php
kronolith/scripts/import_squirrelmail_calendar.php
kronolith/scripts/upgrades/convert_datatree_shares_to_sql.php
kronolith/templates/week/head.inc

index 011fdb4..7db6ce1 100644 (file)
@@ -45,7 +45,11 @@ if ($search_fields_pref = $prefs->getValue('search_fields')) {
 }
 
 if ($search || $prefs->getValue('display_contact')) {
-    $results = $registry->call('contacts/search', $apiargs);
+    try {
+        $results = $registry->call('contacts/search', $apiargs);
+    } catch (Exception $e) {
+        $results = array();
+    }
 } else {
     $results = array();
 }
@@ -53,10 +57,8 @@ if ($search || $prefs->getValue('display_contact')) {
 /* The results list returns an array for each source searched - at least
    that's how it looks to me. Make it all one array instead. */
 $addresses = array();
-if (!is_a($results, 'PEAR_Error')) {
-    foreach ($results as $r) {
-        $addresses = array_merge($addresses, $r);
-    }
+foreach ($results as $r) {
+    $addresses = array_merge($addresses, $r);
 }
 
 /* If self-submitted, preserve the currently selected users encoded by
index 8cf6578..006a428 100644 (file)
@@ -159,9 +159,6 @@ case 'export':
             foreach ($calevents as $dayevents) {
                 foreach ($dayevents as $event) {
                     $calIds[$event->calendar] = true;
-                    if (is_a($event, 'PEAR_Error')) {
-                        continue;
-                    }
                     $iCal->addComponent($event->toiCalendar($iCal));
                 }
             }
@@ -189,7 +186,7 @@ case Horde_Data::IMPORT_FILE:
 
 if (!$error) {
     $data = &Horde_Data::singleton($import_format);
-    if (is_a($data, 'PEAR_Error')) {
+    if ($data instanceof PEAR_Error) {
         $notification->push(_("This file format is not supported."), 'horde.error');
         $next_step = Horde_Data::IMPORT_FILE;
     } else {
@@ -201,7 +198,7 @@ if (!$error) {
                     $next_step = $data->cleanup();
                 } else {
                     $next_step = $data->nextStep($actionID, $param);
-                    if (is_a($next_step, 'PEAR_Error')) {
+                    if ($next_step instanceof PEAR_Error) {
                         $notification->push($next_step->getMessage(), 'horde.error');
                         $next_step = $data->cleanup();
                     }
@@ -212,7 +209,7 @@ if (!$error) {
             }
         } else {
             $next_step = $data->nextStep($actionID, $param);
-            if (is_a($next_step, 'PEAR_Error')) {
+            if ($next_step instanceof PEAR_Error) {
                 $notification->push($next_step->getMessage(), 'horde.error');
                 $next_step = $data->cleanup();
             }
@@ -265,9 +262,9 @@ if (is_array($next_step)) {
             $error = true;
             break;
         }
-        if (is_a($row, 'Horde_iCalendar_vevent')) {
+        if ($row instanceof Horde_iCalendar_vevent) {
             $event->fromiCalendar($row);
-        } elseif (is_a($row, 'Horde_iCalendar')) {
+        } elseif ($row instanceof Horde_iCalendar) {
             // Skip other iCalendar components for now.
             continue;
         } else {
index 4b8ac59..83c67bd 100644 (file)
@@ -52,7 +52,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) {
         $kronolith_driver->open($calendar);
         $event = $kronolith_driver->getEvent(Horde_Util::getFormData('eventID'));
         $result = sscanf($exception, '%04d%02d%02d', $year, $month, $day);
-        if ($result == 3 && !is_a($event, 'PEAR_Error') && $event->recurs()) {
+        if ($result == 3 && $event->recurs()) {
             $event->recurrence->deleteException($year, $month, $day);
             _save($event);
         }
@@ -136,7 +136,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) {
                 // has permissions to do so.
                 try {
                     $sourceShare = Kronolith::getInternalCalendar($source);
-                    if (!is_a($share, 'PEAR_Error') &&
+                    if (!($share instanceof PEAR_Error) &&
                         $sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE) &&
                         (($user == Horde_Auth::getAuth() &&
                           $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) ||
@@ -159,7 +159,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) {
         }
 
         if ($event) {
-            if (isset($sourceShare) && !is_a($sourceShare, 'PEAR_Error')
+            if (isset($sourceShare) && !($sourceShare instanceof PEAR_Error)
                 && !$sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
                 $notification->push(_("You do not have permission to move this event."), 'horde.warning');
             } elseif ($user != Horde_Auth::getAuth() &&
index 80c3767..0265648 100644 (file)
@@ -14,7 +14,7 @@ Horde_Registry::appInit('kronolith');
 
 $viewName = Horde_Util::getFormData('view', 'Event');
 $view = Kronolith::getView($viewName);
-if (is_a($view->event, 'PEAR_Error')) {
+if (is_string($view->event)) {
     $notification->push($view->event, 'horde.error');
     header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
     exit;
index 2c28e85..fc10f8a 100644 (file)
@@ -182,9 +182,6 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
         if (!$event) {
             $GLOBALS['notification']->push(_("The requested event was not found."), 'horde.error');
             return false;
-        } elseif ($event instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($event, 'horde.error');
-            return false;
         } elseif (!$event->hasPermission(Horde_Perms::DELETE)) {
             $GLOBALS['notification']->push(_("You do not have permission to delete this event."), 'horde.warning');
             return false;
@@ -250,9 +247,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $tasks = $GLOBALS['registry']->call('tasks/listTasks', array(null, null, null, $vars->list, $vars->type == 'incomplete' ? 'future_incomplete' : $vars->type, true));
-        if ($tasks instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($tasks, 'horde.error');
+        try {
+            $tasks = $GLOBALS['registry']->tasks->listTasks(null, null, null, $vars->list, $vars->type == 'incomplete' ? 'future_incomplete' : $vars->type, true);
+        } catch (Exception $e)
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
 
@@ -278,12 +276,14 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $task = $GLOBALS['registry']->tasks->getTask($vars->list, $vars->id);
-        if (!$task) {
-            $GLOBALS['notification']->push(_("The requested task was not found."), 'horde.error');
-            return false;
-        } elseif ($task instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($task, 'horde.error');
+        try {
+            $task = $GLOBALS['registry']->tasks->getTask($vars->list, $vars->id);
+            if (!$task) {
+                $GLOBALS['notification']->push(_("The requested task was not found."), 'horde.error');
+                return false;
+            }
+        } catch (Exception $e)
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
 
@@ -337,20 +337,22 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             ? $task['alarm']['value'] * $task['alarm']['unit']
             : 0;
 
-        $result = ($id && $list)
-            ? $GLOBALS['registry']->tasks->updateTask($list, $id, $task)
-            : $GLOBALS['registry']->tasks->addTask($task);
-        if ($result instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($result, 'horde.error');
+        try {
+            $result = ($id && $list)
+                ? $GLOBALS['registry']->tasks->updateTask($list, $id, $task)
+                : $GLOBALS['registry']->tasks->addTask($task);
+        } catch (Exception $e) {
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
 
         if (!$id) {
             $id = $result[0];
         }
-        $task = $GLOBALS['registry']->tasks->getTask($task['tasklist'], $id);
-        if ($task instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($task, 'horde.error');
+        try {
+            $task = $GLOBALS['registry']->tasks->getTask($task['tasklist'], $id);
+        } catch (Exception $e) {
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
 
@@ -374,9 +376,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $result = $GLOBALS['registry']->tasks->deleteTask($vars->list, $vars->id);
-        if ($result instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($result, 'horde.error');
+        try {
+            $GLOBALS['registry']->tasks->deleteTask($vars->list, $vars->id);
+        } catch (Exception $e) {
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
 
@@ -395,9 +398,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $saved = $GLOBALS['registry']->call('tasks/toggleCompletion', array($vars->id, $vars->list));
-        if ($saved instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($saved, 'horde.error');
+        try {
+            $GLOBALS['registry']->tasks->toggleCompletion($vars->id, $vars->list);
+        } catch (Exception $e)
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
 
@@ -514,9 +518,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
                     $GLOBALS['prefs']->isLocked('default_share')) {
                     return false;
                 }
-                $tasklist = $GLOBALS['registry']->tasks->addTasklist($calendar['name'], $calendar['description'], $calendar['color']);
-                if ($tasklist instanceof PEAR_Error) {
-                    $GLOBALS['notification']->push($tasklist, 'horde.error');
+                try {
+                    $tasklist = $GLOBALS['registry']->tasks->addTasklist($calendar['name'], $calendar['description'], $calendar['color']);
+                } catch (Exception $e) {
+                    $GLOBALS['notification']->push($e, 'horde.error');
                     return false;
                 }
                 $GLOBALS['notification']->push(sprintf(_("The task list \"%s\" has been created."), $calendar['name']), 'horde.success');
@@ -531,9 +536,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
                 $GLOBALS['notification']->push(_("You are not allowed to change this task list."), 'horde.error');
                 return false;
             }
-            $updated = $GLOBALS['registry']->tasks->updateTasklist($calendar_id, $calendar);
-            if ($updated instanceof PEAR_Error) {
-                $GLOBALS['notification']->push($updated, 'horde.error');
+            try {
+                $GLOBALS['registry']->tasks->updateTasklist($calendar_id, $calendar);
+            } catch (Exception $e) {
+                $GLOBALS['notification']->push($e, 'horde.error');
                 return false;
             }
             if ($tasklists[$calendar_id]->get('name') != $calendar['name']) {
@@ -599,9 +605,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
                 $GLOBALS['notification']->push(_("You are not allowed to delete this task list."), 'horde.error');
                 return false;
             }
-            $deleted = $GLOBALS['registry']->tasks->deleteTasklist($calendar_id);
-            if ($deleted instanceof PEAR_Error) {
-                $GLOBALS['notification']->push(sprintf(_("Unable to delete \"%s\": %s"), $tasklists[$calendar_id]->get('name'), $deleted->getMessage()), 'horde.error');
+            try {
+                $GLOBALS['registry']->tasks->deleteTasklist($calendar_id);
+            } catch (Exception $e) {
+                $GLOBALS['notification']->push(sprintf(_("Unable to delete \"%s\": %s"), $tasklists[$calendar_id]->get('name'), $e->getMessage()), 'horde.error');
                 return false;
             }
             $GLOBALS['notification']->push(sprintf(_("The task list \"%s\" has been deleted."), $tasklists[$calendar_id]->get('name')), 'horde.success');
@@ -695,9 +702,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             $GLOBALS['notification']->push(_("Permission Denied"), 'horde.error');
             return false;
         }
-        $kronolith_driver = Kronolith::getDriver($driver, $calendar);
-        if ($kronolith_driver instanceof PEAR_Error) {
-            $GLOBALS['notification']->push($kronolith_driver, 'horde.error');
+        try {
+            $kronolith_driver = Kronolith::getDriver($driver, $calendar);
+        } catch (Exception $e) {
+            $GLOBALS['notification']->push($e, 'horde.error');
             return false;
         }
         if ($driver == 'remote') {
index b3d28b4..473f1a1 100644 (file)
@@ -299,7 +299,7 @@ class Kronolith_Api extends Horde_Registry_Api
         case 'text/calendar':
         case 'text/x-vcalendar':
             $iCal = new Horde_iCalendar();
-            if (!is_a($content, 'Horde_iCalendar_vevent')) {
+            if (!($content instanceof Horde_iCalendar_vevent)) {
                 if (!$iCal->parsevCalendar($content)) {
                     throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
                 }
@@ -309,7 +309,7 @@ class Kronolith_Api extends Horde_Registry_Api
 
             $kronolith_driver = Kronolith::getDriver();
             foreach ($iCal->getComponents() as $content) {
-                if (is_a($content, 'Horde_iCalendar_vevent')) {
+                if ($content instanceof Horde_iCalendar_vevent) {
                     $event = $kronolith_driver->getEvent();
                     $event->fromiCalendar($content);
                     $uid = $event->uid;
@@ -324,20 +324,22 @@ class Kronolith_Api extends Horde_Registry_Api
                         // the event's history.
                         $history = Horde_History::singleton();
                         $created = $modified = null;
-                        $log = $history->getHistory('kronolith:' . $calendar . ':'
-                            . $uid);
-                        if ($log && !is_a($log, 'PEAR_Error')) {
-                            foreach ($log->getData() as $entry) {
-                                switch ($entry['action']) {
-                                case 'add':
-                                    $created = $entry['ts'];
-                                    break;
-
-                                case 'modify':
-                                    $modified = $entry['ts'];
-                                    break;
+                        $log = $history->getHistory('kronolith:' . $calendar . ':' . $uid);
+                        try {
+                            if ($log) {
+                                foreach ($log->getData() as $entry) {
+                                    switch ($entry['action']) {
+                                    case 'add':
+                                        $created = $entry['ts'];
+                                        break;
+
+                                    case 'modify':
+                                        $modified = $entry['ts'];
+                                        break;
+                                    }
                                 }
                             }
+                        } catch (Exception $e) {
                         }
                         if (empty($modified) && !empty($created)) {
                             $modified = $created;
@@ -410,8 +412,8 @@ class Kronolith_Api extends Horde_Registry_Api
                 // Remove share and all groups/permissions.
                 $share = $GLOBALS['kronolith_shares']->getShare($calendarId);
                 $result = $GLOBALS['kronolith_shares']->removeShare($share);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
+                if ($result instanceof PEAR_Error) {
+                    throw new Kronolith_Exception($result);
                 }
             } catch (Exception $e) {
                 throw new Kronolith_Exception(sprintf(_("Unable to delete calendar \"%s\": %s"), $calendarId, $e->getMessage()));
@@ -457,13 +459,8 @@ class Kronolith_Api extends Horde_Registry_Api
             throw new Horde_Exception_PermissionDenied();
         }
 
-        $driver = Kronolith::getDriver(null, $calendar);
-        if (is_a($driver, 'PEAR_Error')) {
-            return $driver;
-        }
-
-        $events = $driver->listEvents(new Horde_Date($startstamp),
-            new Horde_Date($endstamp));
+        $events = Kronolith::getDriver(null, $calendar)
+            ->listEvents(new Horde_Date($startstamp), new Horde_Date($endstamp));
         $uids = array();
         foreach ($events as $dayevents) {
             foreach ($dayevents as $event) {
@@ -498,9 +495,6 @@ class Kronolith_Api extends Horde_Registry_Api
 
         $history = Horde_History::singleton();
         $histories = $history->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'kronolith:' . $calendar);
-        if (is_a($histories, 'PEAR_Error')) {
-            return $histories;
-        }
 
         // Strip leading kronolith:username:.
         return preg_replace('/^([^:]*:){2}/', '', array_keys($histories));
@@ -560,7 +554,7 @@ class Kronolith_Api extends Horde_Registry_Api
         case 'text/calendar':
         case 'text/x-vcalendar':
             $iCal = new Horde_iCalendar();
-            if (!is_a($content, 'Horde_iCalendar_vevent')) {
+            if (!($content instanceof Horde_iCalendar_vevent)) {
                 if (!$iCal->parsevCalendar($content)) {
                     throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
                 }
@@ -576,7 +570,7 @@ class Kronolith_Api extends Horde_Registry_Api
             $kronolith_driver = Kronolith::getDriver(null, $calendar);
             $ids = array();
             foreach ($components as $content) {
-                if (is_a($content, 'Horde_iCalendar_vevent')) {
+                if ($content instanceof Horde_iCalendar_vevent) {
                     $event = $kronolith_driver->getEvent();
                     $event->fromiCalendar($content);
                     // Check if the entry already exists in the data source,
@@ -757,9 +751,6 @@ class Kronolith_Api extends Horde_Registry_Api
         if (is_array($uid)) {
             foreach ($uid as $g) {
                 $result = $this->delete($g);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
-                }
             }
             return;
         }
@@ -825,13 +816,13 @@ class Kronolith_Api extends Horde_Registry_Api
             throw new Horde_Exception_PermissionDenied();
         }
 
-        if (is_a($content, 'Horde_iCalendar_vevent')) {
+        if ($content instanceof Horde_iCalendar_vevent) {
             $component = $content;
         } else {
             switch ($contentType) {
             case 'text/calendar':
             case 'text/x-vcalendar':
-                if (!is_a($content, 'Horde_iCalendar_vevent')) {
+                if (!($content instanceof Horde_iCalendar_vevent)) {
                     $iCal = new Horde_iCalendar();
                     if (!$iCal->parsevCalendar($content)) {
                         throw new Kronolith_Exception(_("There was an error importing the iCalendar data."));
@@ -840,7 +831,7 @@ class Kronolith_Api extends Horde_Registry_Api
                     $components = $iCal->getComponents();
                     $component = null;
                     foreach ($components as $content) {
-                        if (is_a($content, 'Horde_iCalendar_vevent')) {
+                        if ($content instanceof Horde_iCalendar_vevent) {
                             if ($component !== null) {
                                 throw new Kronolith_Exception(_("Multiple iCalendar components found; only one vEvent is supported."));
                             }
@@ -930,8 +921,8 @@ class Kronolith_Api extends Horde_Registry_Api
     public function updateAttendee($response, $sender = null)
     {
         $uid = $response->getAttribute('UID');
-        if (is_a($uid, 'PEAR_Error')) {
-            return $uid;
+        if ($uid instanceof PEAR_Error) {
+            throw new Kronolith_Exception($uid);
         }
 
         $events = Kronolith::getDriver()->getByUID($uid, null, true);
@@ -1068,7 +1059,7 @@ class Kronolith_Api extends Horde_Registry_Api
                 $groups = $share->listGroups(Horde_Perms::READ);
                 foreach ($groups as $gid) {
                     $group_users = $group->listUsers($gid);
-                    if (!is_a($group_users, 'PEAR_Error')) {
+                    if (!($group_users instanceof PEAR_Error)) {
                         $users = array_merge($users, $group_users);
                     }
                 }
index ba4effc..8ea37b8 100644 (file)
@@ -318,15 +318,11 @@ class Kronolith_Application extends Horde_Registry_Application
         $history = Horde_History::singleton();
         $histories = $history->removeByParent('kronolith:' . $user);
 
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-
         /* Get the user's default share */
         try {
             $share = $GLOBALS['kronolith_shares']->getShare($user);
             $result = $GLOBALS['kronolith_shares']->removeShare($share);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 $hasError = true;
                 Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
             }
@@ -337,7 +333,7 @@ class Kronolith_Application extends Horde_Registry_Application
         /* Get a list of all shares this user has perms to and remove the
          * perms */
         $shares = $GLOBALS['kronolith_shares']->listShares($user);
-        if (is_a($shares, 'PEAR_Error')) {
+        if ($shares instanceof PEAR_Error) {
             Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
         }
         foreach ($shares as $share) {
index a1a7209..6b7d187 100644 (file)
@@ -209,7 +209,7 @@ class Kronolith_Driver
      *                        connection parameters a subclass might need.
      *
      * @return Kronolith_Driver  The newly created concrete Kronolith_Driver
-     *                           instance, or a PEAR_Error on error.
+     *                           instance.
      */
     public function factory($driver = null, $params = null)
     {
index 0b7c953..6d76557 100644 (file)
@@ -112,7 +112,7 @@ class Kronolith_Driver_Holidays extends Kronolith_Driver
         $dh->addTranslation($this->_params['language']);
 
         $event = $dh->getHoliday($id);
-        if (is_a($event, 'PEAR_Error')) {
+        if ($event instanceof PEAR_Error) {
             throw new Horde_Exception_NotFound($event);
         }
 
index dbaf368..5c1b4a0 100644 (file)
@@ -239,7 +239,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver
         $data = $response->getBody();
         $_SESSION['kronolith']['remote'][$signature] = new Horde_iCalendar();
         $result = $_SESSION['kronolith']['remote'][$signature]->parsevCalendar($data);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             throw new Kronolith_Exception($result);
         }
 
index f74ae8f..ecf93cc 100644 (file)
@@ -102,8 +102,8 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
 
         // Connect to the Kolab backend
         $result = $this->_kolab->open($this->calendar, 1);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+        if ($result instanceof PEAR_Error) {
+            throw new Kronolith_Exception($result);
         }
         $this->_store = $this->_kolab->_storage;
 
@@ -184,9 +184,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
         }
 
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         if ($this->_store->objectUidExists($uid)) {
             return $uid;
@@ -218,9 +215,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
                                $json = false, $coverDates = true)
     {
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         if (is_null($startDate)) {
             $startDate = new Horde_Date(array('mday' => 1,
@@ -278,9 +272,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
         }
 
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         if (array_key_exists($eventId, $this->_events_cache)) {
             return $this->_events_cache[$eventId];
@@ -342,9 +333,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
     public function saveEvent($event)
     {
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         $uid = $event->uid;
         if ($uid == null) {
@@ -364,9 +352,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
         }
 
         $result = $this->_store->save($attributes, $stored_uid);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         /* Deal with tags */
         $tagger = Kronolith::getTagger();
@@ -407,9 +392,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
     {
         $event = $this->getEvent($eventId);
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         global $kronolith_shares;
         $target = $kronolith_shares->getShare($newCalendar);
@@ -439,9 +421,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
     {
         $this->open($calendar);
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         $result = $this->_store->deleteAll($calendar);
         if (is_callable('Kolab', 'triggerFreeBusyUpdate')) {
@@ -461,9 +440,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver
     public function deleteEvent($eventId, $silent = false)
     {
         $result = $this->synchronize();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         if (!$this->_store->objectUidExists($eventId)) {
             throw new Kronolith_Exception(sprintf(_("Event not found: %s"), $eventId));
index 8d9e0e6..1efdd1e 100644 (file)
@@ -70,21 +70,14 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
             $query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ? , resource_description = ?, resource_response_type = ?, resource_type = ?, resource_members = ? WHERE resource_id = ?';
             $values = array($this->convertToDriver($resource->get('name')), $resource->get('calendar'), $this->convertToDriver($resource->get('description')), $resource->get('response_type'), $resource->get('type'), serialize($resource->get('members')), $resource->getId());
             $result = $this->_write_db->query($query, $values);
-            if ($result instanceof PEAR_Error) {
-                Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-                throw new Kronolith_Exception($result);
-            }
+            $this->handleError($result);
         } else {
             $query = 'INSERT INTO kronolith_resources (resource_id, resource_name, resource_calendar, resource_description, resource_response_type, resource_type, resource_members)';
             $cols_values = ' VALUES (?, ?, ?, ?, ?, ?, ?)';
             $id = $this->_db->nextId('kronolith_resources');
             $values = array($id, $this->convertToDriver($resource->get('name')), $resource->get('calendar'), $this->convertToDriver($resource->get('description')), $resource->get('response_type'), $resource->get('type'), serialize($resource->get('members')));
             $result = $this->_write_db->query($query . $cols_values, $values);
-            if ($result instanceof PEAR_Error) {
-                Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-                throw new Kronolith_Exception($result);
-            }
-
+            $this->handleError($result);
             $resource->setId($id);
         }
 
@@ -107,16 +100,10 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
 
         $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE calendar_id = ?';
         $result = $this->_write_db->query($query, array($resource->get('calendar')));
-        if ($result instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
         $query = 'DELETE FROM kronolith_resources WHERE resource_id = ?';
         $result = $this->_write_db->query($query, array($resource->getId()));
-        if ($result instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
     }
 
     /**
@@ -131,10 +118,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
     {
         $query = 'SELECT resource_id, resource_name, resource_calendar, resource_description, resource_response_type, resource_type, resource_members FROM kronolith_resources WHERE resource_id = ?';
         $results = $this->_db->getRow($query, array($id), DB_FETCHMODE_ASSOC);
-        if ($results instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($results);
-        }
+        $this->handleError($results);
         if (empty($results)) {
             throw new Kronolith_Exception('Resource not found');
         }
@@ -159,10 +143,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
     {
         $query = 'SELECT resource_id FROM kronolith_resources WHERE resource_calendar = ?';
         $result = $this->_db->getOne($query, array($calendar));
-        if ($result instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
         if (empty($result)) {
             throw new Kronolith_Exception('Resource not found');
         }
@@ -201,10 +182,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
         }
 
         $results = $this->_db->getAssoc($query, true, $filter, DB_FETCHMODE_ASSOC, false);
-        if ($results instanceof PEAR_Error) {
-            Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($results);
-        }
+        $this->handleError($results);
 
         $return = array();
         foreach ($results as $key => $result) {
index d2ec550..ca057e1 100644 (file)
@@ -232,16 +232,13 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                           __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $event = $this->_db->getRow($query, $values, DB_FETCHMODE_ASSOC);
-        if (is_a($event, 'PEAR_Error')) {
-            Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($event);
-        }
+        $this->handleError($event);
 
         if ($event) {
             return $event['event_id'];
-        } else {
-            return false;
         }
+
+        return false;
     }
 
     /**
@@ -342,14 +339,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
 
         /* Run the query. */
         $qr = $this->_db->query($q, $values);
-        if ($qr instanceof PEAR_Error) {
-            Horde::logMessage($qr, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($qr);
-        }
+        $this->handleError($qr);
 
         $events = array();
         $row = $qr->fetchRow(DB_FETCHMODE_ASSOC);
-        while ($row && !is_a($row, 'PEAR_Error')) {
+        while ($row && !($row instanceof PEAR_Error)) {
             /* If the event did not have a UID before, we need to give
              * it one. */
             if (empty($row['event_uid'])) {
@@ -365,7 +359,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                                   __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
                 $result = $this->_write_db->query($query, $values);
-                if (is_a($result, 'PEAR_Error')) {
+                if ($result instanceof PEAR_Error) {
                     Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
                 }
             }
@@ -407,10 +401,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
 
         /* Run the query. */
         $result = $this->_db->getOne($query, array($this->calendar));
-        if ($result instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
         return $result;
     }
 
@@ -444,10 +435,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                           __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $event = $this->_db->getRow($query, $values, DB_FETCHMODE_ASSOC);
-        if (is_a($event, 'PEAR_Error')) {
-            Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($event);
-        }
+        $this->handleError($event);
 
         if ($event) {
             $this->_cache[$this->calendar][$eventId] = new $this->_eventClass($this, $event);
@@ -496,10 +484,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                           __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $events = $this->_db->getAll($query, $values, DB_FETCHMODE_ASSOC);
-        if (is_a($events, 'PEAR_Error')) {
-            Horde::logMessage($events, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($events);
-        }
+        $this->handleError($events);
         if (!count($events)) {
             throw new Horde_Exception_NotFound($uid . ' not found');
         }
@@ -575,10 +560,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                               __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
             $result = $this->_write_db->query($query, $values);
-            if (is_a($result, 'PEAR_Error')) {
-                Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-                throw new Kronolith_Exception($result);
-            }
+            $this->handleError($result);
 
             /* Log the modification of this item in the history log. */
             if ($event->uid) {
@@ -638,10 +620,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                             __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $result = $this->_write_db->query($query, $values);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
 
         /* Log the creation of this item in the history log. */
         $history = Horde_History::singleton();
@@ -687,10 +666,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
 
         /* Attempt the move query. */
         $result = $this->_write_db->query($query, $values);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
 
         return $event;
     }
@@ -713,10 +689,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                           __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $result = $this->_write_db->query($query, $values);
-        if ($result instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
     }
 
     /**
@@ -744,10 +717,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                           __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $result = $this->_write_db->query($query, $values);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
 
         /* Log the deletion of this item in the history log. */
         if ($event->uid) {
@@ -810,10 +780,9 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                           __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
         $result = $this->_db->getCol($sql, 0, array_merge($calendar, $uids));
-        if ($result instanceof PEAR_Error) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Kronolith_Exception($result);
-        }
+        $this->handleError($result);
+
+        return $result;
     }
 
     /**
@@ -843,9 +812,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         $this->_write_db = DB::connect($this->_params,
                                        array('persistent' => !empty($this->_params['persistent']),
                                              'ssl' => !empty($this->_params['ssl'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Kronolith_Exception($this->_write_db);
-        }
+        $this->handleError($this->_write_db);
         $this->_initConn($this->_write_db);
 
         /* Check if we need to set up the read DB connection
@@ -855,9 +822,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
             $this->_db = DB::connect($params,
                                      array('persistent' => !empty($params['persistent']),
                                            'ssl' => !empty($params['ssl'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw new Kronolith_Exception($this->_db);
-            }
+            $this->handleError($this->_db);
             $this->_initConn($this->_db);
         } else {
             /* Default to the same DB handle for the writer too. */
@@ -951,15 +916,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         }
 
         $shares = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::EDIT);
-        if (is_a($shares, 'PEAR_Error')) {
-            return $shares;
-        }
+        $this->handleError($shares);
 
         foreach (array_keys($shares) as $calendar) {
             $ids = Kronolith::listEventIds(null, null, $calendar);
-            if (is_a($ids, 'PEAR_Error')) {
-                return $ids;
-            }
+            $this->handleError($ids);
             $uids = array();
             foreach ($ids as $cal) {
                 $uids = array_merge($uids, array_keys($cal));
@@ -974,4 +935,20 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         return true;
     }
 
+    /**
+     * Determines if the given result is a PEAR error. If it is, logs the event
+     * and throws an exception.
+     *
+     * @param mixed $result The result to check.
+     *
+     * @throws Horde_Exception
+     */
+    protected function handleError($result)
+    {
+        if ($result instanceof PEAR_Error) {
+            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Kronolith_Exception($result);
+        }
+    }
+
 }
index d067180..52ec5bc 100644 (file)
@@ -519,19 +519,22 @@ abstract class Kronolith_Event
         /* Get the event's history. */
         $history = &Horde_History::singleton();
         $created = $modified = null;
-        $log = $history->getHistory('kronolith:' . $this->calendar . ':' . $this->uid);
-        if ($log && !is_a($log, 'PEAR_Error')) {
-            foreach ($log->getData() as $entry) {
-                switch ($entry['action']) {
-                case 'add':
-                    $created = $entry['ts'];
-                    break;
+        try {
+            $log = $history->getHistory('kronolith:' . $this->calendar . ':' . $this->uid);
+            if ($log) {
+                foreach ($log->getData() as $entry) {
+                    switch ($entry['action']) {
+                    case 'add':
+                        $created = $entry['ts'];
+                        break;
 
-                case 'modify':
-                    $modified = $entry['ts'];
-                    break;
+                    case 'modify':
+                        $modified = $entry['ts'];
+                        break;
+                    }
                 }
             }
+        } catch (Exception $e) {
         }
         if (!empty($created)) {
             $vEvent->setAttribute($v1 ? 'DCREATED' : 'CREATED', $created);
@@ -749,7 +752,7 @@ abstract class Kronolith_Event
     {
         // Unique ID.
         $uid = $vEvent->getAttribute('UID');
-        if (!empty($uid) && !is_a($uid, 'PEAR_Error')) {
+        if (!empty($uid) && !($uid instanceof PEAR_Error)) {
             $this->uid = $uid;
         }
 
@@ -761,44 +764,44 @@ abstract class Kronolith_Event
 
         // Title, tags and description.
         $title = $vEvent->getAttribute('SUMMARY');
-        if (!is_array($title) && !is_a($title, 'PEAR_Error')) {
+        if (!is_array($title) && !($title instanceof PEAR_Error)) {
             $this->title = $title;
         }
 
         // Tags
         $categories = $vEvent->getAttributeValues('CATEGORIES');
-        if (!is_a($categories, 'PEAR_Error')) {
+        if (!($categories instanceof PEAR_Error)) {
             $this->tags = $categories;
         }
 
         // Description
         $desc = $vEvent->getAttribute('DESCRIPTION');
-        if (!is_array($desc) && !is_a($desc, 'PEAR_Error')) {
+        if (!is_array($desc) && !($desc instanceof PEAR_Error)) {
             $this->description = $desc;
         }
 
         // Remote Url
         $url = $vEvent->getAttribute('URL');
-        if (!is_array($url) && !is_a($url, 'PEAR_Error')) {
+        if (!is_array($url) && !($url instanceof PEAR_Error)) {
             $this->url = $url;
         }
 
         // Location
         $location = $vEvent->getAttribute('LOCATION');
-        if (!is_array($location) && !is_a($location, 'PEAR_Error')) {
+        if (!is_array($location) && !($location instanceof PEAR_Error)) {
             $this->location = $location;
         }
 
         // Class
         $class = $vEvent->getAttribute('CLASS');
-        if (!is_array($class) && !is_a($class, 'PEAR_Error')) {
+        if (!is_array($class) && !($class instanceof PEAR_Error)) {
             $class = Horde_String::upper($class);
             $this->private = $class == 'PRIVATE' || $class == 'CONFIDENTIAL';
         }
 
         // Status.
         $status = $vEvent->getAttribute('STATUS');
-        if (!is_array($status) && !is_a($status, 'PEAR_Error')) {
+        if (!is_array($status) && !($status instanceof PEAR_Error)) {
             $status = Horde_String::upper($status);
             if ($status == 'DECLINED') {
                 $status = 'CANCELLED';
@@ -810,7 +813,7 @@ abstract class Kronolith_Event
 
         // Start and end date.
         $start = $vEvent->getAttribute('DTSTART');
-        if (!is_a($start, 'PEAR_Error')) {
+        if (!($start instanceof PEAR_Error)) {
             if (!is_array($start)) {
                 // Date-Time field
                 $this->start = new Horde_Date($start);
@@ -823,7 +826,7 @@ abstract class Kronolith_Event
             }
         }
         $end = $vEvent->getAttribute('DTEND');
-        if (!is_a($end, 'PEAR_Error')) {
+        if (!($end instanceof PEAR_Error)) {
             if (!is_array($end)) {
                 // Date-Time field
                 $this->end = new Horde_Date($end);
@@ -838,7 +841,7 @@ abstract class Kronolith_Event
                               'month' => (int)$this->end->month,
                               'mday'  => (int)$this->end->mday + 1));
                 }
-            } elseif (is_array($end) && !is_a($end, 'PEAR_Error')) {
+            } elseif (is_array($end) && !($end instanceof PEAR_Error)) {
                 // Date field
                 $this->end = new Horde_Date(
                     array('year'  => (int)$end['year'],
@@ -847,7 +850,7 @@ abstract class Kronolith_Event
             }
         } else {
             $duration = $vEvent->getAttribute('DURATION');
-            if (!is_array($duration) && !is_a($duration, 'PEAR_Error')) {
+            if (!is_array($duration) && !($duration instanceof PEAR_Error)) {
                 $this->end = new Horde_Date($this->start);
                 $this->end->sec += $duration;
             } else {
@@ -863,7 +866,7 @@ abstract class Kronolith_Event
         // vCalendar 1.0 alarms
         $alarm = $vEvent->getAttribute('AALARM');
         if (!is_array($alarm) &&
-            !is_a($alarm, 'PEAR_Error') &&
+            !($alarm instanceof PEAR_Error) &&
             intval($alarm)) {
             $this->alarm = intval(($this->start->timestamp() - $alarm) / 60);
         }
@@ -878,7 +881,7 @@ abstract class Kronolith_Event
         // X-ATTENDEE attribute is used which has the same syntax as
         // ATTENDEE.
         $attendee = $vEvent->getAttribute('X-ATTENDEE');
-        if (!is_a($attendee, 'PEAR_Error')) {
+        if (!($attendee instanceof PEAR_Error)) {
 
             if (!is_array($attendee)) {
                 $attendee = array($attendee);
@@ -946,7 +949,7 @@ abstract class Kronolith_Event
 
         // Recurrence.
         $rrule = $vEvent->getAttribute('RRULE');
-        if (!is_array($rrule) && !is_a($rrule, 'PEAR_Error')) {
+        if (!is_array($rrule) && !($rrule instanceof PEAR_Error)) {
             $this->recurrence = new Horde_Date_Recurrence($this->start);
             if (strpos($rrule, '=') !== false) {
                 $this->recurrence->fromRRule20($rrule);
index 9fa0720..5746e94 100644 (file)
@@ -127,8 +127,7 @@ class Kronolith_FreeBusy
      * @param boolean $json  Whether to return the free/busy data as a simple
      *                       object suitable to be transferred as json.
      *
-     * @return Horde_iCalendar_vfreebusy  Free/busy component on success,
-     *                                    PEAR_Error on failure.
+     * @return Horde_iCalendar_vfreebusy  Free/busy component.
      * @throws Kronolith_Exception
      */
     public static function get($email, $json = false)
@@ -141,8 +140,8 @@ class Kronolith_FreeBusy
 
         $default_domain = empty($GLOBALS['conf']['storage']['default_domain']) ? null : $GLOBALS['conf']['storage']['default_domain'];
         $res = $rfc822->parseAddressList($email, $default_domain);
-        if (is_a($res, 'PEAR_Error')) {
-            return $res;
+        if ($res instanceof PEAR_Error) {
+            throw new Kronolith_Exception($res);
         }
         if (!count($res)) {
             throw new Kronolith_Exception(_("No valid email address found"));
@@ -164,7 +163,8 @@ class Kronolith_FreeBusy
             }
 
             $http = new HTTP_Request($url, $options);
-            if (is_a($response = @$http->sendRequest(), 'PEAR_Error')) {
+            $response = @$http->sendRequest();
+            if ($response instanceof PEAR_Error) {
                 throw new Kronolith_Exception(sprintf(_("The free/busy url for %s cannot be retrieved."), $email));
             }
             if ($http->getResponseCode() == 200 &&
@@ -187,7 +187,7 @@ class Kronolith_FreeBusy
                 $vFb->setAttribute('ORGANIZER', $email);
                 $found = false;
                 foreach ($components as $component) {
-                    if (is_a($component, 'Horde_iCalendar_vfreebusy')) {
+                    if ($component instanceof Horde_iCalendar_vfreebusy) {
                         $found = true;
                         $vFb->merge($component);
                     }
index be353e9..557405b 100644 (file)
@@ -1055,7 +1055,7 @@ class Kronolith
                 }
                 $groups = &Group::singleton();
                 $group_list = $groups->getGroupMemberships(Horde_Auth::getAuth());
-                if (!is_a($group_list, 'PEAR_Error') && count($group_list)) {
+                if (!($group_list instanceof PEAR_Error) && count($group_list)) {
                     $perm = $share->getPermission();
                     // Add the default perm, not added otherwise
                     $perm->addUserPermission(Horde_Auth::getAuth(), Horde_Perms::ALL, false);
@@ -1324,7 +1324,7 @@ class Kronolith
         }
 
         $calendars = $GLOBALS['kronolith_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name');
-        if (is_a($calendars, 'PEAR_Error')) {
+        if ($calendars instanceof PEAR_Error) {
             Horde::logMessage($calendars, __FILE__, __LINE__, PEAR_LOG_ERR);
             return array();
         }
@@ -1593,7 +1593,7 @@ class Kronolith
 
             // If we can't even get a mailbox out of the address, then it is
             // likely unuseable. Reject it entirely.
-            if (is_a($newAttendeeParsed, 'PEAR_Error') ||
+            if ($newAttendeeParsed instanceof PEAR_Error ||
                 !isset($newAttendeeParsed[0]) ||
                 !isset($newAttendeeParsed[0]->mailbox)) {
                 $notification->push(
@@ -2143,7 +2143,7 @@ class Kronolith
      *                          driver being used.
      *
      * @return Kronolith_Driver  The newly created concrete Kronolith_Driver
-     *                           instance, or a PEAR_Error on error.
+     *                           instance.
      * @throws Kronolith_Exception
      */
     public static function getDriver($driver = null, $calendar = null)
index fd6051c..94ca8d9 100644 (file)
@@ -69,9 +69,7 @@ class Kronolith_Storage_sql extends Kronolith_Storage
         $this->_write_db = &DB::connect($this->_params,
                                         array('persistent' => !empty($this->_params['persistent']),
                                               'ssl' => !empty($this->_params['ssl'])));
-        if ($this->_write_db instanceof PEAR_Error) {
-            throw new Kronolith_Exception($this->_write_db);
-        }
+        $this->handleError($this->_write_db);
         $this->_initConn($this->_write_db);
 
         /* Check if we need to set up the read DB connection seperately. */
@@ -80,9 +78,7 @@ class Kronolith_Storage_sql extends Kronolith_Storage
             $this->_db = &DB::connect($params,
                                       array('persistent' => !empty($params['persistent']),
                                             'ssl' => !empty($params['ssl'])));
-            if ($this->_db instanceof PEAR_Error) {
-                throw new Kronolith_Exception($this->_db);
-            }
+            $this->handleError($this->_db);
             $this->_initConn($this->_db);
         } else {
             /* Default to the same DB handle for the writer too. */
@@ -111,8 +107,7 @@ class Kronolith_Storage_sql extends Kronolith_Storage
      * @param boolean $private_only (optional) Only return free/busy
      *                              information owned by this used.
      *
-     * @return object               Horde_iCalendar_vFreebusy on success
-     *                              PEAR_Error on error or not found
+     * @return Horde_iCalendar_vFreebusy
      * @throws Kronolith_Exception
      */
     public function search($email, $private_only = false)
@@ -171,7 +166,21 @@ class Kronolith_Storage_sql extends Kronolith_Storage
 
         /* Execute the query. */
         $result = $this->_write_db->query($query, $values);
+        $this->handleError($result);
+    }
+
+    /**
+     * Determines if the given result is a PEAR error. If it is, logs the event
+     * and throws an exception.
+     *
+     * @param mixed $result The result to check.
+     *
+     * @throws Horde_Exception
+     */
+    protected function handleError($result)
+    {
         if ($result instanceof PEAR_Error) {
+            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
             throw new Kronolith_Exception($result);
         }
     }
index d8f4eb9..ef52ae2 100644 (file)
@@ -172,8 +172,8 @@ class Kronolith_Tagger
      *   (array)calendarId   - restrict to events contained in these calendars.
      *
      * @return A hash of 'calendars' and 'events' that each contain an array
-     *         of calendar_ids and event_uids respectively or PEAR_Error on
-     *         failure. Should this return the objects?
+     *         of calendar_ids and event_uids respectively. Should this return
+     *         the objects?
      */
     public function search($tags, $filter = array())
     {
index 6d4421b..8920ebe 100644 (file)
@@ -52,29 +52,32 @@ class Kronolith_View_Event {
         if ($this->event->uid) {
             /* Get the event's history. */
             $history = &Horde_History::singleton();
-            $log = $history->getHistory('kronolith:' . $this->event->calendar . ':' .
-                                        $this->event->uid);
-            if ($log && !is_a($log, 'PEAR_Error')) {
-                foreach ($log->getData() as $entry) {
-                    switch ($entry['action']) {
-                    case 'add':
-                        $created = new Horde_Date($entry['ts']);
-                        if ($userId != $entry['who']) {
-                            $createdby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
-                        } else {
-                            $createdby = _("by me");
+            try {
+                $log = $history->getHistory('kronolith:' . $this->event->calendar . ':' .
+                                            $this->event->uid);
+                if ($log) {
+                    foreach ($log->getData() as $entry) {
+                        switch ($entry['action']) {
+                        case 'add':
+                            $created = new Horde_Date($entry['ts']);
+                            if ($userId != $entry['who']) {
+                                $createdby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
+                            } else {
+                                $createdby = _("by me");
+                            }
+                            break;
+
+                        case 'modify':
+                            $modified = new Horde_Date($entry['ts']);
+                            if ($userId != $entry['who']) {
+                                $modifiedby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
+                            } else {
+                                $modifiedby = _("by me");
+                            }
+                            break;
                         }
-                        break;
-
-                    case 'modify':
-                        $modified = new Horde_Date($entry['ts']);
-                        if ($userId != $entry['who']) {
-                            $modifiedby = sprintf(_("by %s"), Kronolith::getUserName($entry['who']));
-                        } else {
-                            $modifiedby = _("by me");
-                        }
-                        break;
                     }
+                } catch (Exception $e) {
                 }
             }
         }
index 13eea2b..b10eeb2 100644 (file)
@@ -29,7 +29,7 @@ require KRONOLITH_BASE . '/lib/Driver.php';
 require KRONOLITH_BASE . '/lib/Event.php';
 require KRONOLITH_BASE . '/lib/Event/Sql.php';
 foreach ($components as $content) {
-    if (is_a($content, 'Horde_iCalendar_vevent')) {
+    if ($content instanceof Horde_iCalendar_vevent) {
         $event = new Kronolith_Event_Sql(new Driver);
         $event->fromiCalendar($content);
         echo (string)$event->start . "\n";
index 3e8369a..1808e8e 100644 (file)
@@ -72,12 +72,8 @@ $end   = new Horde_Date(345600);
 
 // List the events in three days (recurring event)
 $a = $kron->listEvents($start, $end);
-if (is_a($a, 'PEAR_Error')) {
-    var_dump($a->getMessage());
-} else {
-    $events = reset($a);
-    var_dump($events[0]->id);
-}
+$events = reset($a);
+var_dump($events[0]->id);
 --EXPECT--
 bool(true)
 array(0) {
index 5f4f9bf..cbc169c 100644 (file)
@@ -24,7 +24,7 @@ require KRONOLITH_BASE . '/lib/Event.php';
 require KRONOLITH_BASE . '/lib/Event/Sql.php';
 $event = new Kronolith_Event_Sql(new Driver);
 foreach ($components as $content) {
-    if (is_a($content, 'Horde_iCalendar_vevent')) {
+    if ($content instanceof Horde_iCalendar_vevent) {
         $event->fromiCalendar($content);
         var_export($event->recurrence->exceptions);
         echo "\n";
index 3212fea..868b54a 100644 (file)
@@ -28,7 +28,7 @@ $actionID = Horde_Util::getFormData('actionID', 'edit');
 switch ($actionID) {
 case 'edit':
     $share = $shares->getShareById(Horde_Util::getFormData('cid'));
-    if (!is_a($share, 'PEAR_Error')) {
+    if (!($share instanceof PEAR_Error)) {
         $perm = $share->getPermission();
     } elseif (($category = Horde_Util::getFormData('share')) !== null) {
         try {
@@ -48,7 +48,7 @@ case 'edit':
 
 case 'editform':
     $share = $shares->getShareById(Horde_Util::getFormData('cid'));
-    if (is_a($share, 'PEAR_Error')) {
+    if ($share instanceof PEAR_Error) {
         $notification->push(_("Attempt to edit a non-existent share."), 'horde.error');
     } else {
         if (!Horde_Auth::getAuth() ||
@@ -243,11 +243,11 @@ case 'editform':
         }
 
         $result = $share->setPermission($perm, false);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             $notification->push($result, 'horde.error');
         } else {
             $result = $share->save();
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 $notification->push($result, 'horde.error');
             } else {
                 if (Horde_Util::getFormData('save_and_finish')) {
@@ -261,16 +261,17 @@ case 'editform':
     break;
 }
 
-if (is_a($share, 'PEAR_Error')) {
+if ($share instanceof PEAR_Error) {
     $title = _("Edit Permissions");
 } else {
     $title = sprintf(_("Edit Permissions for %s"), $share->get('name'));
 }
 
 if ($auth->hasCapability('list')) {
-    $userList = $auth->listUsers();
-    if (is_a($userList, 'PEAR_Error')) {
-        Horde::logMessage($userList, __FILE__, __LINE__, PEAR_LOG_ERR);
+    try {
+        $userList = $auth->listUsers();
+    } catch (Exception $e) {
+        Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
         $userList = array();
     }
     sort($userList);
@@ -283,7 +284,7 @@ if (!empty($conf['share']['any_group'])) {
 } else {
     $groupList = $groups->getGroupMemberships(Horde_Auth::getAuth(), true);
 }
-if (is_a($groupList, 'PEAR_Error')) {
+if ($groupList instanceof PEAR_Error) {
     Horde::logMessage($groupList, __FILE__, __LINE__, PEAR_LOG_NOTICE);
     $groupList = array();
 }
index 1bd3f39..316c472 100755 (executable)
@@ -29,7 +29,7 @@ $default_tz = date_default_timezone_get();
 
 // Connect to database.
 $db = DB::connect($dsn);
-if (is_a($db, 'PEAR_Error')) {
+if ($db instanceof PEAR_Error) {
     $cli->fatal($db->toString());
 }
 
@@ -37,7 +37,7 @@ if (is_a($db, 'PEAR_Error')) {
 $read_stmt = $db->prepare('SELECT reader_name FROM calendar_readers WHERE calendar_id = ?');
 $write_stmt = $db->prepare('SELECT writer_name FROM calendar_writers WHERE calendar_id = ?');
 $handle = $db->query('SELECT id, name, owner_name FROM calendars, calendar_owners WHERE calendars.id = calendar_owners.calendar_id');
-if (is_a($handle, 'PEAR_Error')) {
+if ($handle instanceof PEAR_Error) {
     $cli->fatal($handle->toString());
 }
 while ($row = $handle->fetchRow(DB_FETCHMODE_ASSOC)) {
@@ -51,14 +51,14 @@ while ($row = $handle->fetchRow(DB_FETCHMODE_ASSOC)) {
     // Add permissions.
     $permissions = array();
     $result = $db->execute($read_stmt, array($row['id']));
-    if (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $cli->fatal($result->toString());
     }
     while ($perm_row = $result->fetchRow()) {
         $permissions[$perm_row[0]] = Horde_Perms::READ | Horde_Perms::SHOW;
     }
     $result = $db->execute($write_stmt, array($row['id']));
-    if (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $cli->fatal($result->toString());
     }
     while ($perm_row = $result->fetchRow()) {
@@ -80,7 +80,7 @@ while ($row = $handle->fetchRow(DB_FETCHMODE_ASSOC)) {
 }
 
 $handle = $db->query('SELECT event_id, calendar_id, ical_raw, owner_name, prefval FROM events, event_owners LEFT JOIN userprefs ON event_owners.owner_name = userprefs.user AND userprefs.prefkey = \'timezone\' WHERE events.id = event_owners.event_key ORDER BY calendar_id, userprefs.prefval, event_owners.owner_name');
-if (is_a($handle, 'PEAR_Error')) {
+if ($handle instanceof PEAR_Error) {
     $cli->fatal($handle->toString());
 }
 $ical = new Horde_iCalendar();
@@ -108,7 +108,7 @@ while ($row = $handle->fetchRow(DB_FETCHMODE_ASSOC)) {
     }
     // Parse event.
     $parsed = $ical->parsevCalendar($row['ical_raw']);
-    if (is_a($parsed, 'PEAR_Error')) {
+    if ($parsed instanceof PEAR_Error) {
         $cli->message('  ' . $parsed->getMessage(), 'cli.warning');
         continue;
     }
index 01df788..fd44eba 100755 (executable)
@@ -28,7 +28,7 @@ if ($answer != 'y') {
 
 /* Get the share entries */
 $shares_result = $db->query('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = \'horde.shares.kronolith\'');
-if (is_a($shares_result, 'PEAR_Error')) {
+if ($shares_result instanceof PEAR_Error) {
     die($shares_result->toString());
 }
 
@@ -39,7 +39,7 @@ while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
 
     /* Build an array to hold the new row data */
     $nextId = $db->nextId('kronolith_shares');
-    if (is_a($nextId, 'PEAR_Error')) {
+    if ($nextId instanceof PEAR_Error) {
         $cli->message($nextId->toString(), 'cli.error');
         $error_cnt++;
         continue;
@@ -103,14 +103,14 @@ while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
     $error = false;
     $db->beginTransaction();
     $result = insertData('kronolith_shares', $data);
-    if (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $cli->message($result->toString(), 'cli.error');
         $error=true;
     }
     if (count($groups)) {
         foreach ($groups as $group) {
             $result = insertData('kronolith_shares_groups', $group);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 $cli->message($result->toString(), 'cli.error');
                 $error = true;
             }
@@ -119,7 +119,7 @@ while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
     if (count($users)) {
         foreach ($users as $user) {
             $result = insertData('kronolith_shares_users', $user);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 $cli->message($result->toString(), 'cli.error');
                 $error = true;
             }
@@ -130,12 +130,12 @@ while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
     if ($delete_dt_data && !$error) {
         $cli->message('DELETING datatree data for share_id: ' . $share_id, 'cli.message');
         $delete = $db->prepare('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?', null, MDB2_PREPARE_MANIP);
-        if (is_a($delete, 'PEAR_Error')) {
+        if ($delete instanceof PEAR_Error) {
             $cli->message($delete->toString(), 'cli.error');
             $error = true;
         } else {
             $delete_result = $delete->execute(array($share_id));
-            if (is_a($delete_result, 'PEAR_Error')) {
+            if ($delete_result instanceof PEAR_Error) {
                 $cli->message($delete_result->toString(), 'cli.error');
                 $error = true;
             }
@@ -144,12 +144,12 @@ while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
         $delete->free();
 
         $delete = $db->prepare('DELETE FROM horde_datatree WHERE datatree_id = ?', null, MDB2_PREPARE_MANIP);
-        if (is_a($delete, 'PEAR_Error')) {
+        if ($delete instanceof PEAR_Error) {
             $cli->message($delete->toString(), 'cli.error');
             $error = true;
         } else {
             $delete_result = $delete->execute(array($share_id));
-            if (is_a($delete_result, 'PEAR_Error')) {
+            if ($delete_result instanceof PEAR_Error) {
                 $cli->message($delete_result->toString(), 'cli.error');
                 $error = true;
             }
@@ -185,7 +185,7 @@ function insertData($table, $data)
 
     $insert = $GLOBALS['db']->prepare('INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . str_repeat('?, ', count($values) - 1) . '?)',
                                       null, MDB2_PREPARE_MANIP);
-    if (is_a($insert,'PEAR_Error')) {
+    if ($insert instanceof PEAR_Error) {
         return $insert;
     }
     $insert_result = $insert->execute($values);
index d91516f..95eaf06 100644 (file)
@@ -1,6 +1,6 @@
 <h1 class="header" style="text-align:center">
 <?php
-$currentView = is_a($this, 'Kronolith_View_WorkWeek') ? 'WorkWeek' : 'Week';
+$currentView = $this instanceof Kronolith_View_WorkWeek ? 'WorkWeek' : 'Week';
 $prev = $this->getWeek(-1);
 $next = $this->getWeek(1);
 echo $this->link(-1)->link(array('title' => _("Last week"), 'class' => 'iconNav', 'onclick' => 'return ShowView(\'' . $currentView . '\', \'' . $prev->dateString() . '\');')) . Horde::img('nav/left.png', '<', '', $GLOBALS['registry']->getImageDir('horde')) . '</a>';