From: Jan Schneider Date: Wed, 10 Feb 2010 18:28:36 +0000 (+0100) Subject: Use exceptions and a bit other H4 stuff along the way. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a700826d0e39e7c64a82f4fcf82e11e3ac0e7e07;p=horde.git Use exceptions and a bit other H4 stuff along the way. --- diff --git a/kronolith/add.php b/kronolith/add.php index cbbac3aaf..eec54d6fb 100644 --- a/kronolith/add.php +++ b/kronolith/add.php @@ -17,39 +17,42 @@ if (!Horde_Util::getFormData('cancel')) { $calendar_id = $targetcalendar; $user = Horde_Auth::getAuth(); } - $share = Kronolith::getInternalCalendar($calendar_id); - if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error'); - } elseif ($user != Horde_Auth::getAuth() && - !$share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE, Horde_Auth::getAuth())) { - $notification->push(sprintf(_("You do not have permission to delegate events to %s."), Kronolith::getUserName($user)), 'horde.warning'); - } elseif ($user == Horde_Auth::getAuth() && - !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT, Horde_Auth::getAuth())) { - $notification->push(sprintf(_("You do not have permission to add events to %s."), $share->get('name')), 'horde.warning'); - } elseif ($GLOBALS['perms']->hasAppPermission('max_events') === true || - $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()) { - $event = Kronolith::getDriver(null, $calendar_id)->getEvent(); - $event->readForm(); - $result = $event->save(); - if (is_a($result, 'PEAR_Error')) { - $userinfo = $result->getUserInfo(); - if (is_array($userinfo)) { - $userinfo = implode(', ', $userinfo); - } - $message = $result->getMessage() . ($userinfo ? ' : ' . $userinfo : ''); - - $notification->push(sprintf(_("There was an error adding the event: %s"), $message), 'horde.error'); - } else { - Kronolith::notifyOfResourceRejection($event); - if (Horde_Util::getFormData('sendupdates', false)) { - $event = Kronolith::getDriver()->getEvent($result); - if (is_a($event, 'PEAR_Error')) { - $notification->push($event, 'horde.error'); - } else { - Kronolith::sendITipNotifications($event, $notification, Kronolith::ITIP_REQUEST); + try { + $share = Kronolith::getInternalCalendar($calendar_id); + if ($user != Horde_Auth::getAuth() && + !$share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE, Horde_Auth::getAuth())) { + $notification->push(sprintf(_("You do not have permission to delegate events to %s."), Kronolith::getUserName($user)), 'horde.warning'); + } elseif ($user == Horde_Auth::getAuth() && + !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT, Horde_Auth::getAuth())) { + $notification->push(sprintf(_("You do not have permission to add events to %s."), $share->get('name')), 'horde.warning'); + } elseif ($GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()) { + $event = Kronolith::getDriver(null, $calendar_id)->getEvent(); + $event->readForm(); + try { + $event->save(); + Kronolith::notifyOfResourceRejection($event); + if (Horde_Util::getFormData('sendupdates', false)) { + try { + $event = Kronolith::getDriver()->getEvent($result); + Kronolith::sendITipNotifications($event, $notification, Kronolith::ITIP_REQUEST); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); + } } + } catch (Exception $e) { + // @todo: there is no getUserInfo() in Horde_Exception + $userinfo = $e->getUserInfo(); + if (is_array($userinfo)) { + $userinfo = implode(', ', $userinfo); + } + $message = $e->getMessage() . ($userinfo ? ' : ' . $userinfo : ''); + + $notification->push(sprintf(_("There was an error adding the event: %s"), $message), 'horde.error'); } } + } catch (Exception $e) { + $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $e->getMessage()), 'horde.error'); } } diff --git a/kronolith/attend.php b/kronolith/attend.php index 18bf4dc30..699c85c0a 100644 --- a/kronolith/attend.php +++ b/kronolith/attend.php @@ -43,26 +43,30 @@ if (((empty($cal) || empty($id)) && empty($uid)) || empty($user)) { $notification->push(_("The request was incomplete. Some parameters that are necessary to accept or decline an event are missing."), 'horde.error'); $title = ''; } else { - if (empty($uid)) { - $event = Kronolith::getDriver(null, $cal)->getEvent($id); - } else { - $event = Kronolith::getDriver()->getByUID($uid); - } - if (is_a($event, 'PEAR_Error')) { - $notification->push($event, 'horde.error'); - $title = ''; - } elseif (!$event->hasAttendee($user)) { - $notification->push(_("You are not an attendee of the specified event."), 'horde.error'); - $title = $event->getTitle(); - } else { - $event->addAttendee($user, Kronolith::PART_IGNORE, $action); - $result = $event->save(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } elseif (!empty($msg)) { - $notification->push($msg, 'horde.success'); + try { + if (empty($uid)) { + $event = Kronolith::getDriver(null, $cal)->getEvent($id); + } else { + $event = Kronolith::getDriver()->getByUID($uid); } - $title = $event->getTitle(); + if (!$event->hasAttendee($user)) { + $notification->push(_("You are not an attendee of the specified event."), 'horde.error'); + $title = $event->getTitle(); + } else { + $event->addAttendee($user, Kronolith::PART_IGNORE, $action); + try { + $event->save(); + if (!empty($msg)) { + $notification->push($msg, 'horde.success'); + } + } catch (Exception $e) { + $notification->push($e, 'horde.error'); + } + $title = $event->getTitle(); + } + } catch (Exception $e) { + $notification->push($e, 'horde.error'); + $title = ''; } } diff --git a/kronolith/attendees.php b/kronolith/attendees.php index 78a41c74d..4fdab08fb 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -206,13 +206,11 @@ if (!$cal) { } $cal = array($cal); } -$vfb = Kronolith_FreeBusy::generate($cal, null, null, true, Horde_Auth::getAuth()); -if (!is_a($vfb, 'PEAR_Error')) { +try { + $vfb = Kronolith_FreeBusy::generate($cal, null, null, true, Horde_Auth::getAuth()); $attendee_view->addRequiredMember($vfb); -} else { - $notification->push( - sprintf(_("Error retrieving your free/busy information: %s"), - $vfb->getMessage())); +} catch (Exception $e) { + $notification->push(sprintf(_("Error retrieving your free/busy information: %s"), $e->getMessage())); } // Add the Free/Busy information for each attendee. @@ -220,8 +218,8 @@ foreach ($attendees as $email => $status) { if (strpos($email, '@') !== false && ($status['attendance'] == Kronolith::PART_REQUIRED || $status['attendance'] == Kronolith::PART_OPTIONAL)) { - $vfb = Kronolith_Freebusy::get($email); - if (!is_a($vfb, 'PEAR_Error')) { + try { + $vfb = Kronolith_Freebusy::get($email); $organizer = $vfb->getAttribute('ORGANIZER'); if (empty($organizer)) { $vfb->setAttribute('ORGANIZER', 'mailto:' . $email, array(), @@ -232,10 +230,10 @@ foreach ($attendees as $email => $status) { } else { $attendee_view->addOptionalMember($vfb); } - } else { + } catch (Exception $e) { $notification->push( sprintf(_("Error retrieving free/busy information for %s: %s"), - $email, $vfb->getMessage())); + $email, $e->getMessage())); } } } @@ -244,8 +242,8 @@ foreach ($attendees as $email => $status) { if (count($resources)) { $driver = Kronolith::getDriver('Resource'); foreach ($resources as $r_id => $resource) { + $r = $driver->getResource($r_id); try { - $r = $driver->getResource($r_id); $vfb = $r->getFreeBusy(null, null, true); if ($resource['attendance'] == Kronolith::PART_REQUIRED) { $attendee_view->addRequiredResourceMember($vfb); diff --git a/kronolith/calendars/create.php b/kronolith/calendars/create.php index 00812c4a3..b9819dce3 100644 --- a/kronolith/calendars/create.php +++ b/kronolith/calendars/create.php @@ -25,13 +25,12 @@ $form = new Kronolith_CreateCalendarForm($vars); // Execute if the form is valid. if ($form->validate($vars)) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } else { + try { + $form->execute(); $notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } - header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } diff --git a/kronolith/calendars/delete.php b/kronolith/calendars/delete.php index 070c79f09..e69b7a36e 100644 --- a/kronolith/calendars/delete.php +++ b/kronolith/calendars/delete.php @@ -26,13 +26,15 @@ if ($calendar_id == Horde_Auth::getAuth()) { header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } -$calendar = $kronolith_shares->getShare($calendar_id); -if (is_a($calendar, 'PEAR_Error')) { - $notification->push($calendar, 'horde.error'); +try { + $calendar = $kronolith_shares->getShare($calendar_id); +} catch (Exception $e) { + $notification->push($e, 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; -} elseif ($calendar->get('owner') != Horde_Auth::getAuth() && - (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) { +} +if ($calendar->get('owner') != Horde_Auth::getAuth() && + (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) { $notification->push(_("You are not allowed to delete this calendar."), 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; @@ -41,13 +43,12 @@ $form = new Kronolith_DeleteCalendarForm($vars, $calendar); // Execute if the form is valid (must pass with POST variables only). if ($form->validate(new Horde_Variables($_POST))) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } elseif ($result) { + try { + $form->execute(); $notification->push(sprintf(_("The calendar \"%s\" has been deleted."), $calendar->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } - header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } diff --git a/kronolith/calendars/edit.php b/kronolith/calendars/edit.php index 189eb7e45..b165eb57c 100644 --- a/kronolith/calendars/edit.php +++ b/kronolith/calendars/edit.php @@ -20,13 +20,15 @@ if (!Horde_Auth::getAuth()) { } $vars = Horde_Variables::getDefaultVariables(); -$calendar = $kronolith_shares->getShare($vars->get('c')); -if (is_a($calendar, 'PEAR_Error')) { - $notification->push($calendar, 'horde.error'); +try { + $calendar = $kronolith_shares->getShare($vars->get('c')); +} catch (Exception $e) { + $notification->push($e, 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; -} elseif ($calendar->get('owner') != Horde_Auth::getAuth() && - (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) { +} +if ($calendar->get('owner') != Horde_Auth::getAuth() && + (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin())) { $notification->push(_("You are not allowed to change this calendar."), 'horde.error'); header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; @@ -36,17 +38,16 @@ $form = new Kronolith_EditCalendarForm($vars, $calendar); // Execute if the form is valid. if ($form->validate($vars)) { $original_name = $calendar->get('name'); - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } else { + try { + $form->execute(); if ($calendar->get('name') != $original_name) { $notification->push(sprintf(_("The calendar \"%s\" has been renamed to \"%s\"."), $original_name, $calendar->get('name')), 'horde.success'); } else { $notification->push(sprintf(_("The calendar \"%s\" has been saved."), $original_name), 'horde.success'); } + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } - header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } diff --git a/kronolith/calendars/remote_edit.php b/kronolith/calendars/remote_edit.php index 29062c6e7..3ed24f98a 100644 --- a/kronolith/calendars/remote_edit.php +++ b/kronolith/calendars/remote_edit.php @@ -41,13 +41,12 @@ $form = new Kronolith_EditRemoteCalendarForm($vars, $remote_calendar); // Execute if the form is valid. if ($form->validate($vars)) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } else { + try { + $form->execute(); $notification->push(sprintf(_("The calendar \"%s\" has been saved."), $vars->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } - header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } diff --git a/kronolith/calendars/remote_subscribe.php b/kronolith/calendars/remote_subscribe.php index 9af9a757e..ae964005b 100644 --- a/kronolith/calendars/remote_subscribe.php +++ b/kronolith/calendars/remote_subscribe.php @@ -25,13 +25,12 @@ $form = new Kronolith_SubscribeRemoteCalendarForm($vars); // Execute if the form is valid. if ($form->validate($vars)) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } else { + try { + $form->execute(); $notification->push(sprintf(_("You have been subscribed to \"%s\" (%s)."), $vars->get('name'), $vars->get('url')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } - header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } diff --git a/kronolith/calendars/remote_unsubscribe.php b/kronolith/calendars/remote_unsubscribe.php index fb2db1303..1e486796e 100644 --- a/kronolith/calendars/remote_unsubscribe.php +++ b/kronolith/calendars/remote_unsubscribe.php @@ -25,13 +25,12 @@ $form = new Kronolith_UnsubscribeRemoteCalendarForm($vars, $remote_calendar); // Execute if the form is valid (must pass with POST variables only). if ($form->validate(new Horde_Variables($_POST))) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } elseif ($result) { + try { + $calendar = $form->execute(); $notification->push(sprintf(_("You have been unsubscribed from \"%s\" (%s)."), $calendar['name'], $calendar['url']), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } - header('Location: ' . Horde::applicationUrl('calendars/', true)); exit; } diff --git a/kronolith/data.php b/kronolith/data.php index eb8132982..319855204 100644 --- a/kronolith/data.php +++ b/kronolith/data.php @@ -192,19 +192,21 @@ if (!$error) { $next_step = Horde_Data::IMPORT_FILE; } else { if ($actionID == Horde_Data::IMPORT_FILE) { - $share = &$kronolith_shares->getShare($_SESSION['import_data']['import_cal']); - if (is_a($share, 'PEAR_Error')) { - $notification->push(_("You have specified an invalid calendar."), 'horde.error'); - $next_step = $data->cleanup(); - } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { - $notification->push(_("You do not have permission to add events to the selected calendar."), 'horde.error'); - $next_step = $data->cleanup(); - } else { - $next_step = $data->nextStep($actionID, $param); - if (is_a($next_step, 'PEAR_Error')) { - $notification->push($next_step->getMessage(), 'horde.error'); + try { + $share = $kronolith_shares->getShare($_SESSION['import_data']['import_cal']); + if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + $notification->push(_("You do not have permission to add events to the selected calendar."), 'horde.error'); $next_step = $data->cleanup(); + } else { + $next_step = $data->nextStep($actionID, $param); + if (is_a($next_step, 'PEAR_Error')) { + $notification->push($next_step->getMessage(), 'horde.error'); + $next_step = $data->cleanup(); + } } + } catch (Exception $e) { + $notification->push(_("You have specified an invalid calendar."), 'horde.error'); + $next_step = $data->cleanup(); } } else { $next_step = $data->nextStep($actionID, $param); @@ -233,11 +235,11 @@ if (is_array($next_step)) { } else { /* Purge old calendar if requested. */ if ($_SESSION['import_data']['purge']) { - $result = $kronolith_driver->delete($_SESSION['import_data']['import_cal']); - if (is_a($result, 'PEAR_Error')) { - $notification->push(sprintf(_("The calendar could not be purged: %s"), $result->getMessage()), 'horde.error'); - } else { + try { + $kronolith_driver->delete($_SESSION['import_data']['import_cal']); $notification->push(_("Calendar successfully purged."), 'horde.success'); + } catch (Exception $e) { + $notification->push(sprintf(_("The calendar could not be purged: %s"), $e->getMessage()), 'horde.error'); } } } @@ -252,12 +254,11 @@ if (is_array($next_step)) { $notification->push($message, 'horde.error', array('content.raw')); break; } - $event = &$kronolith_driver->getEvent(); - if (!$event || is_a($event, 'PEAR_Error')) { - $msg = _("Can't create a new event."); - if (is_a($event, 'PEAR_Error')) { - $msg .= ' ' . sprintf(_("This is what the server said: %s"), $event->getMessage()); - } + try { + $event = $kronolith_driver->getEvent(); + } catch (Exception $e) { + $msg = _("Can't create a new event.") + . ' ' . sprintf(_("This is what the server said: %s"), $e->getMessage()); $notification->push($msg, 'horde.error'); $error = true; break; @@ -268,17 +269,19 @@ if (is_array($next_step)) { // Skip other iCalendar components for now. continue; } else { - $valid = $event->fromHash($row); - if (is_a($valid, 'PEAR_Error')) { - $notification->push($valid, 'horde.error'); + try { + $event->fromHash($row); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); $error = true; break; } } - $success = $event->save(); - if (is_a($success, 'PEAR_Error')) { - $notification->push($success, 'horde.error'); + try { + $event->save(); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); $error = true; break; } diff --git a/kronolith/delete.php b/kronolith/delete.php index 6069b1719..0202aa412 100644 --- a/kronolith/delete.php +++ b/kronolith/delete.php @@ -20,8 +20,9 @@ if (Kronolith_Resource::isResourceCalendar($c = Horde_Util::getFormData('calenda $kronolith_driver = Kronolith::getDriver($driver, $c); if ($eventID = Horde_Util::getFormData('eventID')) { - $event = $kronolith_driver->getEvent($eventID); - if (is_a($event, 'PEAR_Error')) { + try { + $event = $kronolith_driver->getEvent($eventID); + } catch(Exception $e) { if (($url = Horde_Util::getFormData('url')) === null) { $url = Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true); } @@ -29,7 +30,7 @@ if ($eventID = Horde_Util::getFormData('eventID')) { exit; } if ($driver != 'Resource') { - $share = &$kronolith_shares->getShare($event->calendar); + $share = $kronolith_shares->getShare($event->calendar); if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE, $event->creator)) { $notification->push(_("You do not have permission to delete this event."), 'horde.warning'); } else { @@ -52,9 +53,10 @@ if ($eventID = Horde_Util::getFormData('eventID')) { 'mday' => Horde_Util::getFormData('mday', date('j')) - 1, 'year' => Horde_Util::getFormData('year', date('Y')))); if ($event->end->compareDate($recurEnd) > 0) { - $result = $kronolith_driver->deleteEvent($event->id); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); + try { + $kronolith_driver->deleteEvent($event->id); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } } else { $event->recurrence->setRecurEnd($recurEnd); @@ -74,9 +76,10 @@ if ($eventID = Horde_Util::getFormData('eventID')) { if (!$event->recurs() || Horde_Util::getFormData('all') || !$event->recurrence->hasActiveRecurrence()) { - $result = $kronolith_driver->deleteEvent($event->id); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); + try { + $kronolith_driver->deleteEvent($event->id); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } } diff --git a/kronolith/edit.php b/kronolith/edit.php index 5c26d1bd7..5d784da2b 100644 --- a/kronolith/edit.php +++ b/kronolith/edit.php @@ -11,14 +11,16 @@ function _save(&$event) { - $res = $event->save(); + try { + $event->save(); + if (Horde_Util::getFormData('sendupdates', false)) { + Kronolith::sendITipNotifications($event, $GLOBALS['notification'], Kronolith::ITIP_REQUEST); + } + } catch (Exception $e) { + $GLOBALS['notification']->push(sprintf(_("There was an error editing the event: %s"), $e->getMessage()), 'horde.error'); + } $tagger = Kronolith::getTagger(); $tagger->replaceTags($event->uid, Horde_Util::getFormData('tags')); - if (is_a($res, 'PEAR_Error')) { - $GLOBALS['notification']->push(sprintf(_("There was an error editing the event: %s"), $res->getMessage()), 'horde.error'); - } elseif (Horde_Util::getFormData('sendupdates', false)) { - Kronolith::sendITipNotifications($event, $GLOBALS['notification'], Kronolith::ITIP_REQUEST); - } Kronolith::notifyOfResourceRejection($event); } @@ -44,17 +46,17 @@ $kronolith_driver = Kronolith::getDriver(); if ($exception = Horde_Util::getFormData('del_exception')) { $calendar = Horde_Util::getFormData('calendar'); - $share = Kronolith::getInternalCalendar($calendar); - if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error'); - } else { + try { + $share = Kronolith::getInternalCalendar($calendar); $kronolith_driver->open($calendar); - $event = &$kronolith_driver->getEvent(Horde_Util::getFormData('eventID')); + $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()) { $event->recurrence->deleteException($year, $month, $day); _save($event); } + } catch (Exception $e) { + $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $e->getMessage()), 'horde.error'); } } elseif (!Horde_Util::getFormData('cancel')) { $source = Horde_Util::getFormData('existingcalendar'); @@ -65,19 +67,16 @@ if ($exception = Horde_Util::getFormData('del_exception')) { $target = $targetcalendar; $user = Horde_Auth::getAuth(); } - $share = Kronolith::getInternalCalendar($target); - if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error'); - } else { + try { + $share = Kronolith::getInternalCalendar($target); $event = false; - if (($edit_recur = Horde_Util::getFormData('edit_recur')) && $edit_recur != 'all' && $edit_recur != 'copy' && _check_max()) { /* Get event details. */ $kronolith_driver->open($source); - $event = &$kronolith_driver->getEvent(Horde_Util::getFormData('eventID')); + $event = $kronolith_driver->getEvent(Horde_Util::getFormData('eventID')); $recur_ex = Horde_Util::getFormData('recur_ex'); $exception = new Horde_Date($recur_ex); @@ -91,7 +90,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) { /* Create one-time event. */ $kronolith_driver->open($target); - $event = &$kronolith_driver->getEvent(); + $event = $kronolith_driver->getEvent(); $event->readForm(); $event->recurrence->setRecurType(Horde_Date_Recurrence::RECUR_NONE); @@ -101,9 +100,10 @@ if ($exception = Horde_Util::getFormData('del_exception')) { /* Set recurrence end. */ $exception->mday--; if ($event->end->compareDate($exception) > 0) { - $result = $kronolith_driver->deleteEvent($event->id); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); + try { + $kronolith_driver->deleteEvent($event->id); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } } else { $event->recurrence->setRecurEnd($exception); @@ -112,7 +112,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) { /* Create new event. */ $kronolith_driver->open($target); - $event = &$kronolith_driver->getEvent(); + $event = $kronolith_driver->getEvent(); $event->readForm(); break; @@ -125,7 +125,7 @@ if ($exception = Horde_Util::getFormData('del_exception')) { $edit_recur == 'copy') { if (_check_max()) { $kronolith_driver->open($target); - $event = &$kronolith_driver->getEvent(); + $event = $kronolith_driver->getEvent(); } } else { $event_load_from = $source; @@ -133,29 +133,31 @@ if ($exception = Horde_Util::getFormData('del_exception')) { if ($target != $source) { // Only delete the event from the source calendar if this user // has permissions to do so. - $sourceShare = Kronolith::getInternalCalendar($source); - if (!is_a($share, 'PEAR_Error') && - !is_a($sourceShare, 'PEAR_Error') && - $sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE) && - (($user == Horde_Auth::getAuth() && - $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) || - ($user != Horde_Auth::getAuth() && - $share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE)))) { - $kronolith_driver->open($source); - $res = $kronolith_driver->move(Horde_Util::getFormData('eventID'), $target); - if (is_a($res, 'PEAR_Error')) { - $notification->push(sprintf(_("There was an error moving the event: %s"), $res->getMessage()), 'horde.error'); - } else { - $event_load_from = $target; + try { + $sourceShare = Kronolith::getInternalCalendar($source); + if (!is_a($share, 'PEAR_Error') && + $sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE) && + (($user == Horde_Auth::getAuth() && + $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) || + ($user != Horde_Auth::getAuth() && + $share->hasPermission(Horde_Auth::getAuth(), Kronolith::PERMS_DELEGATE)))) { + $kronolith_driver->open($source); + try { + $res = $kronolith_driver->move(Horde_Util::getFormData('eventID'), $target); + $event_load_from = $target; + } catch (Exception $e) { + $notification->push(sprintf(_("There was an error moving the event: %s"), $e->getMessage()), 'horde.error'); + } } + } catch (Exception $e) { } } $kronolith_driver->open($event_load_from); - $event = &$kronolith_driver->getEvent(Horde_Util::getFormData('eventID')); + $event = $kronolith_driver->getEvent(Horde_Util::getFormData('eventID')); } - if ($event && !is_a($event, 'PEAR_Error')) { + if ($event) { if (isset($sourceShare) && !is_a($sourceShare, 'PEAR_Error') && !$sourceShare->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { $notification->push(_("You do not have permission to move this event."), 'horde.warning'); @@ -170,6 +172,8 @@ if ($exception = Horde_Util::getFormData('del_exception')) { _save($event); } } + } catch (Exception $e) { + $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $e->getMessage()), 'horde.error'); } } diff --git a/kronolith/fb.php b/kronolith/fb.php index fd26bf8f1..02ba217a9 100644 --- a/kronolith/fb.php +++ b/kronolith/fb.php @@ -50,9 +50,10 @@ if (!$fb) { } } - $fb = Kronolith_FreeBusy::generate(explode('|', $cal), null, null, false, $user); - if (is_a($fb, 'PEAR_Error')) { - Horde::logMessage($fb, __FILE__, __LINE__, PEAR_LOG_ERR); + try { + $fb = Kronolith_FreeBusy::generate(explode('|', $cal), null, null, false, $user); + } catch (Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); exit; } $cache->set($key, $fb); diff --git a/kronolith/feed/index.php b/kronolith/feed/index.php index 1cf54fbb5..46e73f880 100644 --- a/kronolith/feed/index.php +++ b/kronolith/feed/index.php @@ -25,8 +25,9 @@ require_once dirname(__FILE__) . '/../lib/Application.php'; Horde_Registry::appInit('kronolith', array('authentication' => 'none', 'session_control' => 'readonly')); $calendar = Horde_Util::getFormData('c'); -$share = $kronolith_shares->getShare($calendar); -if (is_a($share, 'PEAR_Error')) { +try { + $share = $kronolith_shares->getShare($calendar); +} catch (Exception $e) { _no_access(404, 'Not Found', sprintf(_("The requested feed (%s) was not found on this server."), htmlspecialchars($calendar))); @@ -68,11 +69,12 @@ if (empty($feed_type)) { $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j'))); -$events = Kronolith::listEvents($startDate, - new Horde_Date($startDate), - array($calendar)); -if (is_a($events, 'PEAR_Error')) { - Horde::logMessage($events, __FILE__, __LINE__, PEAR_LOG_ERR); +try { + $events = Kronolith::listEvents($startDate, + new Horde_Date($startDate), + array($calendar)); +} catch (Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); $events = array(); } diff --git a/kronolith/lib/Ajax/Application.php b/kronolith/lib/Ajax/Application.php index 5cefe84e8..bd4e4424f 100644 --- a/kronolith/lib/Ajax/Application.php +++ b/kronolith/lib/Ajax/Application.php @@ -32,7 +32,6 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base { $start = new Horde_Date($vars->start); $end = new Horde_Date($vars->end); - $result = new stdClass; $result->cal = $vars->cal; $result->view = $vars->view; @@ -41,16 +40,9 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base return $result; } $events = $kronolith_driver->listEvents($start, $end, true, false, true); - if ($events instanceof PEAR_Error) { - $GLOBALS['notification']->push($events, 'horde.error'); - return $result; - break; - } - if (count($events)) { $result->events = $events; } - return $result; } @@ -114,13 +106,8 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base */ public function QuickSaveEvent($vars) { - $kronolith_driver = Kronolith::getDriver(); try { $event = Kronolith::quickAdd($vars->text, Kronolith::getDefaultCalendar(Horde_Perms::EDIT)); - if ($event instanceof PEAR_Error) { - $GLOBALS['notification']->push($event, 'horde.error'); - return false; - } return $this->_saveEvent($event); } catch (Horde_Exception $e) { $GLOBALS['notification']->push($e); @@ -213,10 +200,6 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base } $deleted = $kronolith_driver->deleteEvent($event->id); - if ($deleted instanceof PEAR_Error) { - $GLOBALS['notification']->push($deleted, 'horde.error'); - return false; - } if ($vars->sendupdates) { Kronolith::sendITipNotifications($event, $GLOBALS['notification'], Kronolith::ITIP_CANCEL); @@ -245,15 +228,15 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base $events = array(); foreach ($cals as $cal) { if (!($kronolith_driver = $this->_getDriver($cal))) { - break; - } - $result = $kronolith_driver->search($query, true); - if ($result instanceof PEAR_Error) { - $GLOBALS['notification']->push($result, 'horde.error'); - break; + continue; } - if ($result) { - $events[$cal] = $result; + try { + $result = $kronolith_driver->search($query, true); + if ($result) { + $events[$cal] = $result; + } + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); } } @@ -444,7 +427,6 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base foreach ($tags as $tag) { $result->tags[] = $tag['tag_name']; } - return $result; } @@ -453,14 +435,14 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base */ public function GetFreeBusy($vars) { - $fb = Kronolith_FreeBusy::get($vars->email, true); - if ($fb instanceof PEAR_Error) { - $GLOBALS['notification']->push($fb->getMessage(), 'horde.warning'); + try { + $fb = Kronolith_FreeBusy::get($vars->email, true); + } catch (Exception $e) { + $GLOBALS['notification']->push($e->getMessage(), 'horde.warning'); return false; } $result = new stdClass; $result->fb = $fb; - return $result; } @@ -495,9 +477,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base $GLOBALS['prefs']->isLocked('default_share')) { return false; } - $calendar = Kronolith::addShare($info); - if ($calendar instanceof PEAR_Error) { - $GLOBALS['notification']->push($calendar, 'horde.error'); + try { + $calendar = Kronolith::addShare($info); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return false; } $GLOBALS['notification']->push(sprintf(_("The calendar \"%s\" has been created."), $info['name']), 'horde.success'); @@ -506,15 +489,17 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base } // Update a calendar. - $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id); - if ($calendar instanceof PEAR_Error) { - $GLOBALS['notification']->push($calendar, 'horde.error'); + try { + $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return false; } $original_name = $calendar->get('name'); - $updated = Kronolith::updateShare($calendar, $info); - if ($updated instanceof PEAR_Error) { - $GLOBALS['notification']->push($updated, 'horde.error'); + try { + Kronolith::updateShare($calendar, $info); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return false; } @@ -571,9 +556,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base foreach (array('name', 'description', 'url', 'color', 'username', 'password') as $key) { $calendar[$key] = $vars->$key; } - $subscribed = Kronolith::subscribeRemoteCalendar($calendar); - if ($subscribed instanceof PEAR_Error) { - $GLOBALS['notification']->push($subscribed, 'horde.error'); + try { + Kronolith::subscribeRemoteCalendar($calendar); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return false; } if ($calendar_id) { @@ -599,14 +585,16 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base switch ($vars->type) { case 'internal': - $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id); - if ($calendar instanceof PEAR_Error) { - $GLOBALS['notification']->push($calendar, 'horde.error'); + try { + $calendar = $GLOBALS['kronolith_shares']->getShare($calendar_id); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return false; } - $deleted = Kronolith::deleteShare($calendar); - if ($deleted instanceof PEAR_Error) { - $GLOBALS['notification']->push(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $deleted->getMessage()), 'horde.error'); + try { + Kronolith::deleteShare($calendar); + } catch (Exception $e) { + $GLOBALS['notification']->push(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $e->getMessage()), 'horde.error'); return false; } $GLOBALS['notification']->push(sprintf(_("The calendar \"%s\" has been deleted."), $calendar->get('name')), 'horde.success'); @@ -628,9 +616,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base break; case 'remote': - $deleted = Kronolith::unsubscribeRemoteCalendar($calendar_id); - if ($deleted instanceof PEAR_Error) { - $GLOBALS['notification']->push($deleted, 'horde.error'); + try { + $deleted = Kronolith::unsubscribeRemoteCalendar($calendar_id); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return false; } $GLOBALS['notification']->push(sprintf(_("You have been unsubscribed from \"%s\" (%s)."), $deleted['name'], $deleted['url']), 'horde.success'); @@ -730,9 +719,10 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base */ protected function _saveEvent($event) { - $result = $event->save(); - if ($result instanceof PEAR_Error) { - $GLOBALS['notification']->push($result, 'horde.error'); + try { + $result = $event->save(); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); return true; } $start = new Horde_Date(Horde_Util::getFormData('view_start')); diff --git a/kronolith/lib/Ajax/Imple/TagActions.php b/kronolith/lib/Ajax/Imple/TagActions.php index 2a2b98dfa..d36d28f72 100644 --- a/kronolith/lib/Ajax/Imple/TagActions.php +++ b/kronolith/lib/Ajax/Imple/TagActions.php @@ -34,9 +34,12 @@ class Kronolith_Ajax_Imple_TagActions extends Horde_Ajax_Imple_Base * Handle the tag related action. * * If removing a tag, needs a 'resource' which is the local identifier of - * the kronolith object, a 'type' which should be the string reprentation of - * the type of object (event/calendar) and 'tags' should be the integer + * the kronolith object, a 'type' which should be the string reprentation + * of the type of object (event/calendar) and 'tags' should be the integer * tag_id of the tag to remove. + * + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function handle($args, $post) { @@ -81,6 +84,9 @@ class Kronolith_Ajax_Imple_TagActions extends Horde_Ajax_Imple_Base * @param string $type The type of resource (calendar/event) * * @return string The HTML + * + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ private function _getTagHtml($tagger, $id, $type) { diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index 8dfacf9e6..d3e8216be 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -52,6 +52,7 @@ class Kronolith_Api extends Horde_Registry_Api * 'icon', and 'browseable'. * * @return array The contents of $path + * @throws Kronolith_Exception */ public function browse($path = '', $properties = array()) { @@ -176,10 +177,6 @@ class Kronolith_Api extends Horde_Registry_Api // directory. $kronolith_driver = Kronolith::getDriver(null, $parts[1]); $events = $kronolith_driver->listEvents(); - if (is_a($events, 'PEAR_Error')) { - return $events; - } - $icon = $registry->getImageDir('horde') . '/mime/icalendar.png'; $results = array(); foreach ($events as $dayevents) { @@ -223,9 +220,6 @@ class Kronolith_Api extends Horde_Registry_Api array_key_exists($parts[1], Kronolith::listCalendars(false, Horde_Perms::READ))) { // This request is for a specific item within a given calendar. $event = Kronolith::getDriver(null, $parts[1])->getEvent($parts[2]); - if (is_a($event, 'PEAR_Error')) { - return $event; - } $result = array( 'data' => $this->export($event->uid, 'text/calendar'), @@ -260,7 +254,8 @@ class Kronolith_Api extends Horde_Registry_Api * @param string $content The file content. * @param string $content_type The file's content type. * - * @return array The event UIDs, or a PEAR_Error on failure. + * @return array The event UIDs. + * @throws Kronolith_Exception */ public function put($path, $content, $content_type) { @@ -285,14 +280,14 @@ class Kronolith_Api extends Horde_Registry_Api $content_type = 'text/calendar'; } } else { - return PEAR::raiseError("Invalid calendar data supplied."); + throw new Kronolith_Exception("Invalid calendar data supplied."); } if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::EDIT))) { // FIXME: Should we attempt to create a calendar based on the // filename in the case that the requested calendar does not // exist? - return PEAR::raiseError("Calendar does not exist or no permission to edit"); + throw new Kronolith_Exception("Calendar does not exist or no permission to edit"); } // Store all currently existings UIDs. Use this info to delete UIDs not @@ -306,7 +301,7 @@ class Kronolith_Api extends Horde_Registry_Api $iCal = new Horde_iCalendar(); if (!is_a($content, 'Horde_iCalendar_vevent')) { if (!$iCal->parsevCalendar($content)) { - return PEAR::raiseError(_("There was an error importing the iCalendar data.")); + throw new Kronolith_Exception(_("There was an error importing the iCalendar data.")); } } else { $iCal->addComponent($content); @@ -323,8 +318,8 @@ class Kronolith_Api extends Horde_Registry_Api if (isset($uids_remove[$uid])) { unset($uids_remove[$uid]); } - $existing_event = $kronolith_driver->getByUID($uid, array($calendar)); - if (!is_a($existing_event, 'PEAR_Error')) { + try { + $existing_event = $kronolith_driver->getByUID($uid, array($calendar)); // Check if our event is newer then the existing - get // the event's history. $history = Horde_History::singleton(); @@ -356,20 +351,18 @@ class Kronolith_Api extends Horde_Registry_Api // Don't change creator/owner. $event->creator = $existing_event->creator; + } catch (Kronolith_Exception $e) { } // Save entry. $saved = $event->save(); - if (is_a($saved, 'PEAR_Error')) { - return $saved; - } $ids[] = $event->uid; } } break; default: - return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $content_type)); + throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $content_type)); } if (array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::DELETE))) { @@ -386,7 +379,7 @@ class Kronolith_Api extends Horde_Registry_Api * * @param string $path The path to the file. * - * @return mixed The event's UID, or a PEAR_Error on failure. + * @throws Kronolith_Exception */ public function path_delete($path) { @@ -404,7 +397,7 @@ class Kronolith_Api extends Horde_Registry_Api if (!(count($parts) == 2 || count($parts) == 3) || !array_key_exists($calendarId, Kronolith::listCalendars(false, Horde_Perms::DELETE))) { - return PEAR::raiseError("Calendar does not exist or no permission to delete"); + throw new Kronolith_Exception("Calendar does not exist or no permission to delete"); } if (count($parts) == 3) { @@ -412,16 +405,16 @@ class Kronolith_Api extends Horde_Registry_Api return Kronolith::getDriver(null, $calendarId)->deleteEvent($parts[2]); } else { // Delete the entire calendar - $result = Kronolith::getDriver()->delete($calendarId); - if (is_a($result, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Unable to delete calendar \"%s\": %s"), $calendarId, $result->getMessage())); - } else { + try { + Kronolith::getDriver()->delete($calendarId); // 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; } + } catch (Exception $e) { + throw new Kronolith_Exception(sprintf(_("Unable to delete calendar \"%s\": %s"), $calendarId, $e->getMessage())); } } } @@ -452,6 +445,7 @@ class Kronolith_Api extends Horde_Registry_Api * @param object $endstamp The end of the time range. * * @return array The event ids happening in this time period. + * @throws Kronolith_Exception */ public function listUids($calendar = null, $startstamp = 0, $endstamp = 0) { @@ -460,19 +454,16 @@ class Kronolith_Api extends Horde_Registry_Api } if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::READ))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $driver = Kronolith::getDriver(null, $calendar); if (is_a($driver, 'PEAR_Error')) { return $driver; } + $events = $driver->listEvents(new Horde_Date($startstamp), new Horde_Date($endstamp)); - if (is_a($events, 'PEAR_Error')) { - return $events; - } - $uids = array(); foreach ($events as $dayevents) { foreach ($dayevents as $event) { @@ -492,6 +483,7 @@ class Kronolith_Api extends Horde_Registry_Api * @param string $calendar The calendar to search in. * * @return array An array of UIDs matching the action and time criteria. + * @throws Kronolith_Exception */ public function listBy($action, $timestamp, $calendar = null) { @@ -501,7 +493,7 @@ class Kronolith_Api extends Horde_Registry_Api if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::READ))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $history = Horde_History::singleton(); @@ -522,6 +514,7 @@ class Kronolith_Api extends Horde_Registry_Api * @param string $calendar The calendar to search in. * * @return integer The timestamp for this action. + * @throws Kronolith_Exception */ public function getActionTimestamp($uid, $action, $calendar = null) { @@ -531,7 +524,7 @@ class Kronolith_Api extends Horde_Registry_Api if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::READ))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $history = Horde_History::singleton(); @@ -550,7 +543,8 @@ class Kronolith_Api extends Horde_Registry_Api * * @param string $calendar What calendar should the event be added to? * - * @return mixed The event's UID, or a PEAR_Error on failure. + * @return array The event's UID. + * @throws Kronolith_Exception */ public function import($content, $contentType, $calendar = null) { @@ -559,7 +553,7 @@ class Kronolith_Api extends Horde_Registry_Api } if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::EDIT))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } switch ($contentType) { @@ -568,7 +562,7 @@ class Kronolith_Api extends Horde_Registry_Api $iCal = new Horde_iCalendar(); if (!is_a($content, 'Horde_iCalendar_vevent')) { if (!$iCal->parsevCalendar($content)) { - return PEAR::raiseError(_("There was an error importing the iCalendar data.")); + throw new Kronolith_Exception(_("There was an error importing the iCalendar data.")); } } else { $iCal->addComponent($content); @@ -576,7 +570,7 @@ class Kronolith_Api extends Horde_Registry_Api $components = $iCal->getComponents(); if (count($components) == 0) { - return PEAR::raiseError(_("No iCalendar data was found.")); + throw new Kronolith_Exception(_("No iCalendar data was found.")); } $kronolith_driver = Kronolith::getDriver(null, $calendar); @@ -588,10 +582,11 @@ class Kronolith_Api extends Horde_Registry_Api // Check if the entry already exists in the data source, // first by UID. $uid = $event->uid; - $existing_event = $kronolith_driver->getByUID($uid, array($calendar)); - if (!is_a($existing_event, 'PEAR_Error')) { - return PEAR::raiseError(_("Already Exists"), - 'horde.message', null, null, $uid); + try { + $existing_event = $kronolith_driver->getByUID($uid, array($calendar)); + throw new Kronolith_Exception(_("Already Exists"), + 'horde.message', null, null, $uid); + } catch (Kronolith_Exception $e) { } $result = $kronolith_driver->search($event); // Check if the match really is an exact match: @@ -602,27 +597,24 @@ class Kronolith_Api extends Horde_Registry_Api $match->title == $event->title && $match->location == $event->location && $match->hasPermission(Horde_Perms::EDIT)) { - return PEAR::raiseError(_("Already Exists"), 'horde.message', null, null, $match->uid); + throw new Kronolith_Exception(_("Already Exists"), 'horde.message', null, null, $match->uid); } } } $eventId = $event->save(); - if (is_a($eventId, 'PEAR_Error')) { - return $eventId; - } $ids[] = $event->uid; } } if (count($ids) == 0) { - return PEAR::raiseError(_("No iCalendar data was found.")); + throw new Kronolith_Exception(_("No iCalendar data was found.")); } else if (count($ids) == 1) { return $ids[0]; } return $ids; } - return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType)); + throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType)); } /** @@ -634,24 +626,18 @@ class Kronolith_Api extends Horde_Registry_Api * calendar will be used. * * @return array The UID of all events that were added. + * @throws Kronolith_Exception */ public function quickAdd($text, $calendar = null) { - global $kronolith_shares; - if (!isset($calendar)) { $calendar = Kronolith::getDefaultCalendar(Horde_Perms::EDIT); } if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::EDIT))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } - $event = Kronolith::quickAdd($text, $calendar); - if (is_a($event, 'PEAR_Error')) { - return $event; - } - return $event->uid; } @@ -669,17 +655,16 @@ class Kronolith_Api extends Horde_Registry_Api * * * @return string The requested data. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function export($uid, $contentType) { global $kronolith_shares; $event = Kronolith::getDriver()->getByUID($uid); - if (is_a($event, 'PEAR_Error')) { - return $event; - } if (!$event->hasPermission(Horde_Perms::READ)) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $version = '2.0'; @@ -700,7 +685,7 @@ class Kronolith_Api extends Horde_Registry_Api } - return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType)); + throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType)); } /** @@ -717,6 +702,7 @@ class Kronolith_Api extends Horde_Registry_Api * * * @return string The iCalendar representation of the calendar. + * @throws Kronolith_Exception */ public function exportCalendar($calendar, $contentType) { @@ -724,7 +710,7 @@ class Kronolith_Api extends Horde_Registry_Api if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::READ))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $kronolith_driver = Kronolith::getDriver(null, $calendar); @@ -753,21 +739,21 @@ class Kronolith_Api extends Horde_Registry_Api return $iCal->exportvCalendar(); } - return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType)); + throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType)); } /** * Deletes an event identified by UID. * - * @param string|array $uid A single UID or an array identifying the event(s) - * to delete. + * @param string|array $uid A single UID or an array identifying the + * event(s) to delete. * - * @return boolean Success or failure. + * @throws Kronolith_Exception */ public function delete($uid) { - // Handle an array of UIDs for convenience of deleting multiple events at - // once. + // Handle an array of UIDs for convenience of deleting multiple events + // at once. if (is_array($uid)) { foreach ($uid as $g) { $result = $this->delete($g); @@ -775,15 +761,11 @@ class Kronolith_Api extends Horde_Registry_Api return $result; } } - - return true; + return; } $kronolith_driver = Kronolith::getDriver(); $events = $kronolith_driver->getByUID($uid, null, true); - if (is_a($events, 'PEAR_Error')) { - return $events; - } $event = null; if (Horde_Auth::isAdmin()) { @@ -814,10 +796,10 @@ class Kronolith_Api extends Horde_Registry_Api } if (empty($event)) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } - return $kronolith_driver->deleteEvent($event->id); + $kronolith_driver->deleteEvent($event->id); } /** @@ -832,18 +814,15 @@ class Kronolith_Api extends Horde_Registry_Api * text/x-vcalendar * (Ignored if content is Horde_iCalendar_vevent) * - * @return mixed True on success, PEAR_Error otherwise. + * @throws Kronolith_Exception */ public function replace($uid, $content, $contentType) { $event = Kronolith::getDriver()->getByUID($uid); - if (is_a($event, 'PEAR_Error')) { - return $event; - } if (!$event->hasPermission(Horde_Perms::EDIT) || ($event->private && $event->creator != Horde_Auth::getAuth())) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } if (is_a($content, 'Horde_iCalendar_vevent')) { @@ -855,7 +834,7 @@ class Kronolith_Api extends Horde_Registry_Api if (!is_a($content, 'Horde_iCalendar_vevent')) { $iCal = new Horde_iCalendar(); if (!$iCal->parsevCalendar($content)) { - return PEAR::raiseError(_("There was an error importing the iCalendar data.")); + throw new Kronolith_Exception(_("There was an error importing the iCalendar data.")); } $components = $iCal->getComponents(); @@ -863,20 +842,20 @@ class Kronolith_Api extends Horde_Registry_Api foreach ($components as $content) { if (is_a($content, 'Horde_iCalendar_vevent')) { if ($component !== null) { - return PEAR::raiseError(_("Multiple iCalendar components found; only one vEvent is supported.")); + throw new Kronolith_Exception(_("Multiple iCalendar components found; only one vEvent is supported.")); } $component = $content; } } if ($component === null) { - return PEAR::raiseError(_("No iCalendar data was found.")); + throw new Kronolith_Exception(_("No iCalendar data was found.")); } } break; default: - return PEAR::raiseError(sprintf(_("Unsupported Content-Type: %s"), $contentType)); + throw new Kronolith_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType)); } } @@ -884,9 +863,7 @@ class Kronolith_Api extends Horde_Registry_Api // Ensure we keep the original UID, even when content does not // contain one and fromiCalendar creates a new one. $event->uid = $uid; - $eventId = $event->save(); - - return is_a($eventId, 'PEAR_Error') ? $eventId : true; + $event->save(); } /** @@ -899,6 +876,7 @@ class Kronolith_Api extends Horde_Registry_Api * * @return Horde_iCalendar_vfreebusy A freebusy object that covers the * specified time period. + * @throws Kronolith_Exception */ public function getFreeBusy($startstamp = null, $endstamp = null, $calendar = null) @@ -908,7 +886,6 @@ class Kronolith_Api extends Horde_Registry_Api } // Free/Busy information is globally available; no permission // check is needed. - return Kronolith_FreeBusy::generate($calendar, $startstamp, $endstamp, true); } @@ -917,17 +894,14 @@ class Kronolith_Api extends Horde_Registry_Api * * @param string $uid The event's UID. * - * @return Kronolith_Event A valid Kronolith_Event on success, or a PEAR_Error - * on failure. + * @return Kronolith_Event A valid Kronolith_Event. + * @throws Kronolith_Exception */ public function eventFromUID($uid) { $event = Kronolith::getDriver()->getByUID($uid); - if (is_a($event, 'PEAR_Error')) { - return $event; - } if (!$event->hasPermission(Horde_Perms::SHOW)) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } return $event; @@ -936,19 +910,22 @@ class Kronolith_Api extends Horde_Registry_Api /** * Updates an attendee's response status for a specified event. * - * @param Horde_iCalender_vevent $response A Horde_iCalender_vevent object, - * with a valid UID attribute that - * points to an existing event. - * This is typically the vEvent - * portion of an iTip meeting-request + * @param Horde_iCalender_vevent $response A Horde_iCalender_vevent + * object, with a valid UID + * attribute that points to an + * existing event. This is + * typically the vEvent portion + * of an iTip meeting-request * response, with the attendee's - * response in an ATTENDEE parameter. - * @param string $sender The email address of the person - * initiating the update. Attendees - * are only updated if this address + * response in an ATTENDEE + * parameter. + * @param string $sender The email address of the + * person initiating the + * update. Attendees are only + * updated if this address * matches. * - * @return mixed True on success, PEAR_Error on failure. + * @throws Kronolith_Exception */ public function updateAttendee($response, $sender = null) { @@ -958,9 +935,6 @@ class Kronolith_Api extends Horde_Registry_Api } $events = Kronolith::getDriver()->getByUID($uid, null, true); - if (is_a($events, 'PEAR_Error')) { - return $events; - } /* First try the user's own calendars. */ $ownerCalendars = Kronolith::listCalendars(true, Horde_Perms::EDIT); @@ -985,7 +959,7 @@ class Kronolith_Api extends Horde_Registry_Api if (empty($event) || ($event->private && $event->creator != Horde_Auth::getAuth())) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $atnames = $response->getAttribute('ATTENDEE'); @@ -1009,35 +983,32 @@ class Kronolith_Api extends Horde_Registry_Api } } } - - $result = $event->save(); - if (is_a($result, 'PEAR_Error')) { - return $result; - } + $event->save(); if (!$found) { - return PEAR::raiseError($error); + throw new Kronolith_Exception($error); } - - return true; } /** * Lists events for a given time period. * - * @param integer $startstamp The start of the time period to retrieve. + * @param integer $startstamp The start of the time period to + * retrieve. * @param integer $endstamp The end of the time period to retrieve. * @param array $calendars The calendars to view events from. * Defaults to the user's default calendar. - * @param boolean $showRecurrence Return every instance of a recurring event? - * If false, will only return recurring events - * once inside the $startDate - $endDate range. + * @param boolean $showRecurrence Return every instance of a recurring + * event? If false, will only return + * recurring events once inside the + * $startDate - $endDate range. * @param boolean $alarmsOnly Filter results for events with alarms. * Defaults to false. * @param boolean $showRemote Return events from remote calendars and * listTimeObject API as well? * * @return array A list of event hashes. + * @throws Kronolith_Exception */ public function listEvents($startstamp = null, $endstamp = null, $calendars = null, $showRecurrence = true, @@ -1051,7 +1022,7 @@ class Kronolith_Api extends Horde_Registry_Api $allowed_calendars = Kronolith::listCalendars(false, Horde_Perms::READ); foreach ($calendars as $calendar) { if (!array_key_exists($calendar, $allowed_calendars)) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } } @@ -1067,6 +1038,7 @@ class Kronolith_Api extends Horde_Registry_Api * @param string $user The user to retrieve alarms for. All users if null. * * @return array An array of UIDs + * @throws Kronolith_Exception */ public function listAlarms($time, $user = null) { @@ -1074,7 +1046,7 @@ class Kronolith_Api extends Horde_Registry_Api $current_user = Horde_Auth::getAuth(); if ((empty($user) || $user != $current_user) && !Horde_Auth::isAdmin()) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $group = Group::singleton(); @@ -1082,15 +1054,13 @@ class Kronolith_Api extends Horde_Registry_Api $time = new Horde_Date($time); $calendars = is_null($user) ? array_keys($GLOBALS['kronolith_shares']->listAllShares()) : $GLOBALS['display_calendars']; $alarms = Kronolith::listAlarms($time, $calendars, true); - if (is_a($alarms, 'PEAR_Error')) { - return $alarms; - } foreach ($alarms as $calendar => $cal_alarms) { if (!$cal_alarms) { continue; } - $share = $GLOBALS['kronolith_shares']->getShare($calendar); - if (is_a($share, 'PEAR_Error')) { + try { + $share = $GLOBALS['kronolith_shares']->getShare($calendar); + } catch (Exception $e) { continue; } if (empty($user)) { @@ -1138,13 +1108,14 @@ class Kronolith_Api extends Horde_Registry_Api * Subscribe to a calendar. * * @param array $calendar Calendar description hash, with required 'type' - * parameter. Currently supports 'http' and 'webcal' - * for remote calendars. + * parameter. Currently supports 'http' and + * 'webcal' for remote calendars. @throws + * Kronolith_Exception */ public function subscribe($calendar) { if (!isset($calendar['type'])) { - return PEAR::raiseError(_("Unknown calendar protocol")); + throw new Kronolith_Exception(_("Unknown calendar protocol")); } switch ($calendar['type']) { @@ -1180,7 +1151,7 @@ class Kronolith_Api extends Horde_Registry_Api } default: - return PEAR::raiseError(_("Unknown calendar protocol")); + throw new Kronolith_Exception(_("Unknown calendar protocol")); } } @@ -1188,13 +1159,14 @@ class Kronolith_Api extends Horde_Registry_Api * Unsubscribe from a calendar. * * @param array $calendar Calendar description array, with required 'type' - * parameter. Currently supports 'http' and 'webcal' - * for remote calendars. + * parameter. Currently supports 'http' and + * 'webcal' for remote calendars. @throws + * Kronolith_Exception */ public function unsubscribe($calendar) { if (!isset($calendar['type'])) { - return PEAR::raiseError('Unknown calendar specification'); + throw new Kronolith_Exception('Unknown calendar specification'); } switch ($calendar['type']) { @@ -1219,7 +1191,7 @@ class Kronolith_Api extends Horde_Registry_Api } default: - return PEAR::raiseError('Unknown calendar specification'); + throw new Kronolith_Exception('Unknown calendar specification'); } } @@ -1230,21 +1202,20 @@ class Kronolith_Api extends Horde_Registry_Api * @param array $calendar The calendar to lock * @param array $event The event to lock * - * @return mixed A lock ID on success, PEAR_Error on failure, false if: + * @return mixed A lock ID on success, false if: * - The calendar is already locked * - The event is already locked - * - A calendar lock was requested and an event is already - * locked in the calendar + * - A calendar lock was requested and an event is + * already locked in the calendar + * @throws Kronolith_Exception */ public function lock($calendar, $event = null) { if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::EDIT))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } - - $share = $GLOBALS['kronolith_shares']->getShare($calendar); - return $share->lock($calendar, $event); + return $GLOBALS['kronolith_shares']->getShare($calendar)->lock($calendar, $event); } /** @@ -1252,16 +1223,16 @@ class Kronolith_Api extends Horde_Registry_Api * * @param array $calendar The event to lock. * @param array $lockid The lock id to unlock. + * + * @throws Kronolith_Exception */ public function unlock($calendar, $lockid) { if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::EDIT))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } - - $share = $GLOBALS['kronolith_shares']->getShare($calendar); - return $share->unlock($lockid); + return $GLOBALS['kronolith_shares']->getShare($calendar)->unlock($lockid); } /** @@ -1269,16 +1240,16 @@ class Kronolith_Api extends Horde_Registry_Api * * @param array $calendar The calendar to check locks for. * @param array $event The event to check locks for. + * + * @throws Kronolith_Exception */ public function checkLocks($calendar, $event = null) { if (!array_key_exists($calendar, Kronolith::listCalendars(false, Horde_Perms::READ))) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } - - $share = $GLOBALS['kronolith_shares']->getShare($calendar); - return $share->checkLocks($event); + return $GLOBALS['kronolith_shares']->getShare($calendar)->checkLocks($event); } /** diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index 53ca8c9d2..89690fe07 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -164,14 +164,17 @@ class Kronolith_Application extends Horde_Registry_Application public function prefsCallback() { if ($GLOBALS['prefs']->isDirty('event_alarms')) { - $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME'])); - if (!is_a($alarms, 'PEAR_Error') && !empty($alarms)) { - $horde_alarm = Horde_Alarm::factory(); - foreach ($alarms as $alarm) { - $alarm['start'] = new Horde_Date($alarm['start']); - $alarm['end'] = new Horde_Date($alarm['end']); - $horde_alarm->set($alarm); + try { + $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME'])); + if (!empty($alarms)) { + $horde_alarm = Horde_Alarm::factory(); + foreach ($alarms as $alarm) { + $alarm['start'] = new Horde_Date($alarm['start']); + $alarm['end'] = new Horde_Date($alarm['end']); + $horde_alarm->set($alarm); + } } + } catch (Exception $e) { } } } @@ -303,12 +306,12 @@ class Kronolith_Application extends Horde_Registry_Application * * @param string $user Name of user to remove data for. * - * @return mixed true on success | PEAR_Error on failure + * @throws Kronolith_Exception */ public function removeUserData($user) { if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) { - return PEAR::raiseError(_("You are not allowed to remove user data.")); + throw new Kronolith_Exception(_("You are not allowed to remove user data.")); } /* Remove all events owned by the user in all calendars. */ @@ -323,18 +326,19 @@ class Kronolith_Application extends Horde_Registry_Application } /* Get the user's default share */ - $share = $GLOBALS['kronolith_shares']->getShare($user); - if (is_a($share, 'PEAR_Error')) { - Horde::logMessage($share, __FILE__, __LINE__, PEAR_LOG_ERR); - } else { + try { + $share = $GLOBALS['kronolith_shares']->getShare($user); $result = $GLOBALS['kronolith_shares']->removeShare($share); if (is_a($result, 'PEAR_Error')) { $hasError = true; Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); } + } catch (Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); } - /* Get a list of all shares this user has perms to and remove the perms */ + /* 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')) { Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR); @@ -342,8 +346,6 @@ class Kronolith_Application extends Horde_Registry_Application foreach ($shares as $share) { $share->removeUser($user); } - - return true; } } diff --git a/kronolith/lib/Block/month.php b/kronolith/lib/Block/month.php index 6fa2157e7..ba8420d8d 100644 --- a/kronolith/lib/Block/month.php +++ b/kronolith/lib/Block/month.php @@ -37,10 +37,11 @@ class Horde_Block_Kronolith_month extends Horde_Block { $url = Horde::url($GLOBALS['registry']->getInitialPage(), true); if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { - $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); - if (!is_a($this->_share, 'PEAR_Error')) { + try { + $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); $url->add('display_cal', $this->_params['calendar']); $title = htmlspecialchars($this->_share->get('name')); + } catch (Exception $e) { } } $date = new Horde_Date(time()); @@ -59,13 +60,11 @@ class Horde_Block_Kronolith_month extends Horde_Block { if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { if (empty($this->_share)) { - $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); - } - if (is_a($this->_share, 'PEAR_Error')) { - return _(sprintf("There was an error accessing the calendar: %s", $this->_share->getMessage())); - } - if (is_a($this->_share, 'PEAR_Error')) { - return $this->_share; + try { + $this->_share = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); + } catch (Exception $e) { + return _(sprintf("There was an error accessing the calendar: %s", $e->getMessage())); + } } if (!$this->_share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { return _("Permission Denied"); @@ -122,18 +121,15 @@ class Horde_Block_Kronolith_month extends Horde_Block { $html .= '' . $weekday . ''; } - if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { - $all_events = Kronolith::listEvents( - $startDate, - $endDate, - array($this->_params['calendar']), true, false, false); - } else { - $all_events = Kronolith::listEvents($startDate, - $endDate, - $GLOBALS['display_calendars']); - } - if (is_a($all_events, 'PEAR_Error')) { - return '' . $all_events->getMessage() . ''; + try { + if (isset($this->_params['calendar']) && + $this->_params['calendar'] != '__all') { + $all_events = Kronolith::listEvents($startDate,$endDate, array($this->_params['calendar']), true, false, false); + } else { + $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); + } + } catch (Exception $e) { + return '' . $e->getMessage() . ''; } $weeks = array(); diff --git a/kronolith/lib/Block/monthlist.php b/kronolith/lib/Block/monthlist.php index 711966950..639cb9c28 100644 --- a/kronolith/lib/Block/monthlist.php +++ b/kronolith/lib/Block/monthlist.php @@ -67,17 +67,22 @@ class Horde_Block_Kronolith_monthlist extends Horde_Block { $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j'))); $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1)); - if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { - $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); - if (!is_a($calendar, 'PEAR_Error') && !$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { - return _("Permission Denied"); + try { + if (isset($this->_params['calendar']) && + $this->_params['calendar'] != '__all') { + try { + $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); + if (!$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { + return _("Permission Denied"); + } + } catch (Exception $e) { + } + $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false); + } else { + $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); } - $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false); - } else { - $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); - } - if (is_a($all_events, 'PEAR_Error')) { - return '' . $all_events->getMessage() . ''; + } catch (Exception $e) { + return '' . $e->getMessage() . ''; } /* How many days do we need to check. */ diff --git a/kronolith/lib/Block/prevmonthlist.php b/kronolith/lib/Block/prevmonthlist.php index 0ff256037..31f27ccac 100644 --- a/kronolith/lib/Block/prevmonthlist.php +++ b/kronolith/lib/Block/prevmonthlist.php @@ -64,17 +64,22 @@ class Horde_Block_Kronolith_prevmonthlist extends Horde_Block { $current_month = ''; - if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') { - $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); - if (!is_a($calendar, 'PEAR_Error') && !$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { - return _("Permission Denied"); + try { + if (isset($this->_params['calendar']) && + $this->_params['calendar'] != '__all') { + try { + $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); + if (!$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { + return _("Permission Denied"); + } + } catch (Exception $e) { + } + $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false); + } else { + $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); } - $all_events = Kronolith::listEvents($startDate, $endDate, array($this->_params['calendar']), true, false, false); - } else { - $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); - } - if (is_a($all_events, 'PEAR_Error')) { - return '' . $all_events->getMessage() . ''; + } catch (Exception $e) { + return '' . $e->getMessage() . ''; } $html = ''; diff --git a/kronolith/lib/Block/summary.php b/kronolith/lib/Block/summary.php index 68b9df277..9de246882 100644 --- a/kronolith/lib/Block/summary.php +++ b/kronolith/lib/Block/summary.php @@ -83,25 +83,27 @@ class Horde_Block_Kronolith_summary extends Horde_Block { $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j'))); $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j') + $this->_params['days'])); - if (isset($this->_params['calendar']) && - $this->_params['calendar'] != '__all') { - - $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); - if (!is_a($calendar, 'PEAR_Error') && !$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { - return _("Permission Denied"); + try { + if (isset($this->_params['calendar']) && + $this->_params['calendar'] != '__all') { + try { + $calendar = $GLOBALS['kronolith_shares']->getShare($this->_params['calendar']); + if (!$calendar->hasPermission(Horde_Auth::getAuth(), Horde_Perms::SHOW)) { + return _("Permission Denied"); + } + } catch (Exception $e) { + } + $all_events = Kronolith::listEvents($startDate, + $endDate, + array($this->_params['calendar']), + true, false, false); + } else { + $all_events = Kronolith::listEvents($startDate, + $endDate, + $GLOBALS['display_calendars']); } - - $all_events = Kronolith::listEvents($startDate, - $endDate, - array($this->_params['calendar']), - true, false, false); - } else { - $all_events = Kronolith::listEvents($startDate, - $endDate, - $GLOBALS['display_calendars']); - } - if (is_a($all_events, 'PEAR_Error')) { - return '' . $all_events->getMessage() . ''; + } catch (Exception $e) { + return '' . $e->getMessage() . ''; } $html = ''; diff --git a/kronolith/lib/Block/tree_alarms.php b/kronolith/lib/Block/tree_alarms.php index 52b63c16e..6b6a92345 100644 --- a/kronolith/lib/Block/tree_alarms.php +++ b/kronolith/lib/Block/tree_alarms.php @@ -18,11 +18,12 @@ class Horde_Block_kronolith_tree_alarms extends Horde_Block { } $alarmCount = 0; - $alarms = Kronolith::listAlarms(new Horde_Date($_SERVER['REQUEST_TIME']), - $GLOBALS['display_calendars'], - true); - if (is_a($alarms, 'PEAR_Error')) { - return $alarms; + try { + $alarms = Kronolith::listAlarms(new Horde_Date($_SERVER['REQUEST_TIME']), + $GLOBALS['display_calendars'], + true); + } catch (Exception $e) { + return; } foreach ($alarms as $calId => $calAlarms) { foreach ($calAlarms as $event) { diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index c96242648..a1a72098d 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -127,7 +127,8 @@ class Kronolith_Driver * @param object $query An object with the criteria to search for. * @param boolean $json Store the results of the events' toJson() method? * - * @return mixed An array of Kronolith_Events or a PEAR_Error. + * @return mixed An array of Kronolith_Events. + * @throws Kronolith_Exception */ public function search($query, $json = false) { @@ -138,10 +139,6 @@ class Kronolith_Driver $results = array(); $events = $this->listEvents($query->start, $query->end); - if (is_a($events, 'PEAR_Error')) { - return $events; - } - foreach ($events as $day => $day_events) { foreach ($day_events as $event) { if ((((!isset($query->start) || @@ -177,14 +174,12 @@ class Kronolith_Driver * * @return Horde_Date|boolean The date of the next recurrence or false if * the event does not recur after $afterDate. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function nextRecurrence($eventId, $afterDate) { $event = $this->getEvent($eventId); - if (is_a($event, 'PEAR_Error')) { - return $event; - } - return $event->recurs() ? $event->recurrence->nextRecurrence($afterDate) : false; } @@ -192,6 +187,7 @@ class Kronolith_Driver * Returns the number of events in the current calendar. * * @return integer The number of events. + * @throws Kronolith_Exception */ public function countEvents() { @@ -222,9 +218,10 @@ class Kronolith_Driver if (class_exists($class)) { $driver = new $class($params); - $result = $driver->initialize(); - if (is_a($result, 'PEAR_Error')) { - $driver = new Kronolith_Driver($params, sprintf(_("The Calendar backend is not currently available: %s"), $result->getMessage())); + try { + $driver->initialize(); + } catch (Exception $e) { + $driver = new Kronolith_Driver($params, sprintf(_("The Calendar backend is not currently available: %s"), $e->getMessage())); } } else { $driver = new Kronolith_Driver($params, sprintf(_("Unable to load the definition of %s."), $class)); @@ -235,6 +232,8 @@ class Kronolith_Driver /** * Stub to initiate a driver. + * + * @throws Kronolith_Exception */ public function initialize() { @@ -243,50 +242,64 @@ class Kronolith_Driver /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function getEvent() { - return PEAR::raiseError($this->_errormsg); + throw new Kronolith_Exception($this->_errormsg); } /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function getByUID($uid, $calendars = null, $getAll = false) { - return PEAR::raiseError($this->_errormsg); + throw new Kronolith_Exception($this->_errormsg); } /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception */ public function listAlarms($date, $fullevent = false) { - return PEAR::raiseError($this->_errormsg); + throw new Kronolith_Exception($this->_errormsg); } /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception */ public function listEvents() { - return PEAR::raiseError($this->_errormsg); + throw new Kronolith_Exception($this->_errormsg); } /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception */ public function saveEvent() { - return PEAR::raiseError($this->_errormsg); + throw new Kronolith_Exception($this->_errormsg); } /** * Stub for child class to override if it can implement. + * + * @throws Kronolith_Exception */ public function exists() { - return PEAR::raiseError('Not supported'); + throw new Kronolith_Exception('Not supported'); } /** @@ -294,6 +307,9 @@ class Kronolith_Driver * * @param string $eventId The event to move. * @param string $newCalendar The new calendar. + * + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function move($eventId, $newCalendar) { @@ -310,18 +326,22 @@ class Kronolith_Driver /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception */ protected function _move($eventId, $newCalendar) { - return PEAR::raiseError('Not supported'); + throw new Kronolith_Exception('Not supported'); } /** * Stub to be overridden in the child class. + * + * @throws Kronolith_Exception */ public function delete($calendar) { - return PEAR::raiseError('Not supported'); + throw new Kronolith_Exception('Not supported'); } /** @@ -329,22 +349,25 @@ class Kronolith_Driver */ public function deleteEvent($eventId) { - } /** - * Stub for child class to override if it can implement. + * Stub to be overridden in the child class if it can implement. + * + * @throws Kronolith_Exception */ - public function removeUserData($user) + public function filterEventsByCalendar($uids, $calendar) { - return PEAR::raiseError(_("Removing user data is not supported with the current calendar storage backend.")); + throw new Kronolith_Exception('Not supported'); } /** - * Stub to be overridden in the child class if it can implement. + * Stub for child class to override if it can implement. + * + * @throws Kronolith_Exception */ - public function filterEventsByCalendar($uids, $calendar) + public function removeUserData($user) { - return PEAR::raiseError('Not supported'); + throw new Kronolith_Exception(_("Removing user data is not supported with the current calendar storage backend.")); } } diff --git a/kronolith/lib/Driver/Holidays.php b/kronolith/lib/Driver/Holidays.php index 16b87396a..0b7c95380 100644 --- a/kronolith/lib/Driver/Holidays.php +++ b/kronolith/lib/Driver/Holidays.php @@ -14,7 +14,6 @@ */ class Kronolith_Driver_Holidays extends Kronolith_Driver { - public function listAlarms($date, $fullevent = false) { return array(); @@ -89,6 +88,10 @@ class Kronolith_Driver_Holidays extends Kronolith_Driver return $results; } + /** + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound + */ public function getEvent($eventId = null) { if (!$eventId) { @@ -110,7 +113,7 @@ class Kronolith_Driver_Holidays extends Kronolith_Driver $event = $dh->getHoliday($id); if (is_a($event, 'PEAR_Error')) { - return $event; + throw new Horde_Exception_NotFound($event); } return new Kronolith_Event_Holidays($this, $event); diff --git a/kronolith/lib/Driver/Horde.php b/kronolith/lib/Driver/Horde.php index 1c455bb47..ac75d66b5 100644 --- a/kronolith/lib/Driver/Horde.php +++ b/kronolith/lib/Driver/Horde.php @@ -50,7 +50,7 @@ class Kronolith_Driver_Horde extends Kronolith_Driver * that they cover. * * @return array Events in the given time range. - * @throws Horde_Exception + * @throws Kronolith_Exception */ public function listEvents($startDate = null, $endDate = null, $showRecurrence = false, $hasAlarm = false, @@ -108,6 +108,8 @@ class Kronolith_Driver_Horde extends Kronolith_Driver /** * @todo: implement getTimeObject in timeobjects API. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function getEvent($eventId = null, $start = null) { @@ -125,7 +127,7 @@ class Kronolith_Driver_Horde extends Kronolith_Driver } } - return PEAR::raiseError(_("Event not found")); + throw new Horde_Exception_NotFound(_("Event not found")); } } diff --git a/kronolith/lib/Driver/Ical.php b/kronolith/lib/Driver/Ical.php index 27ce822c7..dbaf36834 100644 --- a/kronolith/lib/Driver/Ical.php +++ b/kronolith/lib/Driver/Ical.php @@ -69,15 +69,13 @@ class Kronolith_Driver_Ical extends Kronolith_Driver * that they cover. * * @return array Events in the given time range. + * @throws Kronolith_Exception */ public function listEvents($startDate = null, $endDate = null, $showRecurrence = false, $hasAlarm = false, $json = false, $coverDates = true) { $iCal = $this->getRemoteCalendar(); - if (is_a($iCal, 'PEAR_Error')) { - return $iCal; - } if (is_null($startDate)) { $startDate = new Horde_Date(array('mday' => 1, @@ -153,6 +151,10 @@ class Kronolith_Driver_Ical extends Kronolith_Driver return $results; } + /** + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound + */ public function getEvent($eventId = null) { if (!$eventId) { @@ -160,9 +162,6 @@ class Kronolith_Driver_Ical extends Kronolith_Driver } $eventId = str_replace('ical', '', $eventId); $iCal = $this->getRemoteCalendar(); - if (is_a($iCal, 'PEAR_Error')) { - return $iCal; - } $components = $iCal->getComponents(); if (isset($components[$eventId]) && @@ -171,11 +170,10 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $event->status = Kronolith::STATUS_FREE; $event->fromiCalendar($components[$eventId]); $event->id = 'ical' . $eventId; - return $event; } - return false; + throw new Horde_Exception_NotFound(_("Event not found")); } /** @@ -183,8 +181,8 @@ class Kronolith_Driver_Ical extends Kronolith_Driver * * @param boolean $cache Whether to return data from the session cache. * - * @throws Kronolith_Exception * @return Horde_iCalendar The calendar data, or an error on failure. + * @throws Kronolith_Exception */ public function getRemoteCalendar($cache = true) { @@ -242,7 +240,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $_SESSION['kronolith']['remote'][$signature] = new Horde_iCalendar(); $result = $_SESSION['kronolith']['remote'][$signature]->parsevCalendar($data); if (is_a($result, 'PEAR_Error')) { - $_SESSION['kronolith']['remote'][$signature] = $result; + throw new Kronolith_Exception($result); } return $_SESSION['kronolith']['remote'][$signature]; diff --git a/kronolith/lib/Driver/Kolab.php b/kronolith/lib/Driver/Kolab.php index 011a6e445..f74ae8fd9 100644 --- a/kronolith/lib/Driver/Kolab.php +++ b/kronolith/lib/Driver/Kolab.php @@ -1,7 +1,4 @@ _kolab = new Kolab(); $this->reset(); - return true; } /** @@ -123,6 +117,9 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver $this->_synchronized = true; } + /** + * @throws Kronolith_Exception + */ public function listAlarms($date, $fullevent = false) { $allevents = $this->listEvents($date, null, false, true); @@ -130,10 +127,6 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver foreach ($allevents as $eventId) { $event = $this->getEvent($eventId); - if (is_a($event, 'PEAR_Error')) { - return $event; - } - if (!$event->recurs()) { $start = new Horde_Date($event->start); $start->min -= $event->alarm; @@ -180,13 +173,14 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * * @return string|boolean Returns a string with event_id or false if * not found. + * @throws Kronolith_Exception */ public function exists($uid, $calendar_id = null) { // Log error if someone uses this function in an unsupported way if ($calendar_id != $this->calendar) { Horde::logMessage(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar), __FILE__, __LINE__, PEAR_LOG_ERR); - return PEAR::raiseError(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar)); + throw new Kronolith_Exception(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar)); } $result = $this->synchronize(); @@ -273,6 +267,10 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver return $events; } + /** + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound + */ public function getEvent($eventId = null) { if (!strlen($eventId)) { @@ -288,7 +286,7 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver return $this->_events_cache[$eventId]; } - return PEAR::raiseError(sprintf(_("Event not found: %s"), $eventId)); + throw new Horde_Exception_NotFound(sprintf(_("Event not found: %s"), $eventId)); } /** @@ -300,6 +298,8 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * an error will be returned if more than one event is found. * * @return Kronolith_Event + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function getByUID($uid, $calendars = null, $getAll = false) { @@ -327,7 +327,7 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver } } - return PEAR::raiseError(sprintf(_("Event not found: %s"), $uid)); + throw new Horde_Exception_NotFound(sprintf(_("Event not found: %s"), $uid)); } /** @@ -336,9 +336,10 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * * @param Kronolith_Event $event The event to save. * - * @return mixed UID on success, a PEAR error otherwise + * @return integer The event id. + * @throws Horde_Mime_Exception */ - public function saveEvent(&$event) + public function saveEvent($event) { $result = $this->synchronize(); if (is_a($result, 'PEAR_Error')) { @@ -376,10 +377,7 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver } /* Notify about the changed event. */ - $result = Kronolith::sendNotification($event, $edit ? 'edit' : 'add'); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - } + Kronolith::sendNotification($event, $edit ? 'edit' : 'add'); /* Log the creation/modification of this item in the history log. */ $history = Horde_History::singleton(); @@ -402,11 +400,12 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * @param string $newCalendar The new calendar. * * @return Kronolith_Event The old event. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ protected function _move($eventId, $newCalendar) { $event = $this->getEvent($eventId); - $result = $this->synchronize(); if (is_a($result, 'PEAR_Error')) { return $result; @@ -434,7 +433,7 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * * @param string $calendar The name of the calendar to delete. * - * @return mixed True or a PEAR_Error on failure. + * @throws Kronolith_Exception */ public function delete($calendar) { @@ -455,7 +454,9 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * * @param string $eventId The ID of the event to delete. * - * @return mixed True or a PEAR_Error on failure. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound + * @throws Horde_Mime_Exception */ public function deleteEvent($eventId, $silent = false) { @@ -465,18 +466,14 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver } if (!$this->_store->objectUidExists($eventId)) { - return PEAR::raiseError(sprintf(_("Event not found: %s"), $eventId)); + throw new Kronolith_Exception(sprintf(_("Event not found: %s"), $eventId)); } $event = $this->getEvent($eventId); - if ($this->_store->delete($eventId)) { // Notify about the deleted event. if (!$silent) { - $result = Kronolith::sendNotification($event, 'delete'); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - } + Kronolith::sendNotification($event, 'delete'); } /* Log the deletion of this item in the history log. */ @@ -489,10 +486,8 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver unset($this->_events_cache[$eventId]); } else { - return PEAR::raiseError(sprintf(_("Cannot delete event: %s"), $eventId)); + throw new Kronolith_Exception(sprintf(_("Cannot delete event: %s"), $eventId)); } - - return true; } } diff --git a/kronolith/lib/Driver/Resource.php b/kronolith/lib/Driver/Resource.php index 2433b2db1..8d9e0e681 100644 --- a/kronolith/lib/Driver/Resource.php +++ b/kronolith/lib/Driver/Resource.php @@ -30,13 +30,15 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * it is attached to. Not sure if there is a better way to do this... * * @see lib/Driver/Kronolith_Driver_Sql#deleteEvent($eventId, $silent) + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function deleteEvent($event, $silent = false) { /* Since this is the Kronolith_Resource's version of the event, if we * delete it, we must also make sure to remove it from the event that - * it is attached to. Not sure if there is a better way to do this... - */ + * it is attached to. Not sure if there is a better way to do + * this... */ $delete_event = $this->getEvent($event); $uid = $delete_event->uid; $driver = Kronolith::getDriver(); @@ -60,7 +62,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * @param Kronolith_Resource $resource * * @return Kronolith_Resource object - * @throws Horde_Exception + * @throws Kronolith_Exception */ public function save($resource) { @@ -70,7 +72,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql $result = $this->_write_db->query($query, $values); if ($result instanceof PEAR_Error) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - throw new Horde_Exception($result); + throw new Kronolith_Exception($result); } } else { $query = 'INSERT INTO kronolith_resources (resource_id, resource_name, resource_calendar, resource_description, resource_response_type, resource_type, resource_members)'; @@ -80,7 +82,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql $result = $this->_write_db->query($query . $cols_values, $values); if ($result instanceof PEAR_Error) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - throw new Horde_Exception($result); + throw new Kronolith_Exception($result); } $resource->setId($id); @@ -95,29 +97,26 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * * @param Kronolith_Resource $resource The kronolith resource to remove * - * @return boolean - * @throws Horde_Exception + * @throws Kronolith_Exception */ public function delete($resource) { if (!($resource instanceof Kronolith_Resource_Base) || !$resource->getId()) { - throw new Horde_Exception(_("Resource not valid.")); + throw new Kronolith_Exception(_("Resource not valid.")); } $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 Horde_Exception($result); + throw new Kronolith_Exception($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 Horde_Exception($result); + throw new Kronolith_Exception($result); } - - return true; } /** @@ -125,8 +124,8 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * * @param int $id The key for the Kronolith_Resource * - * @return Kronolith_Resource_Single || Kronolith_Resource_Group - * @throws Horde_Exception + * @return Kronolith_Resource_Single|Kronolith_Resource_Group + * @throws Kronolith_Exception */ public function getResource($id) { @@ -134,15 +133,15 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql $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 Horde_Exception($results); + throw new Kronolith_Exception($results); } if (empty($results)) { - throw new Horde_Exception('Resource not found'); + throw new Kronolith_Exception('Resource not found'); } $class = 'Kronolith_Resource_' . $results['resource_type']; if (!class_exists($class)) { - throw new Horde_Exception('Could not load the class definition for ' . $class); + throw new Kronolith_Exception('Could not load the class definition for ' . $class); } return new $class($this->_fromDriver($results)); @@ -151,24 +150,24 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql /** * Obtain the resource id associated with the given calendar uid. * - * @param string $calendar The calendar's uid + * @param string $calendar The calendar's uid. * - * @return int The Kronolith_Resource id - * @throws Horde_Exception + * @return integer The Kronolith_Resource id. + * @throws Kronolith_Exception */ public function getResourceIdByCalendar($calendar) { $query = 'SELECT resource_id FROM kronolith_resources WHERE resource_calendar = ?'; - $results = $this->_db->getOne($query, array($calendar)); - if ($results instanceof PEAR_Error) { + $result = $this->_db->getOne($query, array($calendar)); + if ($result instanceof PEAR_Error) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - throw new Horde_Exception($results); + throw new Kronolith_Exception($result); } - if (empty($results)) { - throw new Horde_Exception('Resource not found'); + if (empty($result)) { + throw new Kronolith_Exception('Resource not found'); } - return $results; + return $result; } /** @@ -177,14 +176,16 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * Right now, all users have Horde_Perms::READ, but only system admins have * Horde_Perms::EDIT | Horde_Perms::DELETE * - * @param int $perms A Horde_Perms::* constant. - * @param array $filter A hash of field/values to filter on. + * @param integer $perms A Horde_Perms::* constant. + * @param array $filter A hash of field/values to filter on. * * @return an array of Kronolith_Resource objects. + * @throws Kronolith_Exception */ public function listResources($perms = Horde_Perms::READ, $filter = array()) { - if (($perms & (Horde_Perms::EDIT | Horde_Perms::DELETE)) && !Horde_Auth::isAdmin()) { + if (($perms & (Horde_Perms::EDIT | Horde_Perms::DELETE)) && + !Horde_Auth::isAdmin()) { return array(); } @@ -202,7 +203,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 Horde_Exception($results); + throw new Kronolith_Exception($results); } $return = array(); @@ -220,6 +221,7 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql * @param integer $resource_id The resource id to check for. * * @return array of group ids. + * @throws Kronolith_Exception */ public function getGroupMemberships($resource_id) { @@ -257,19 +259,4 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql return $return; } - - /** - * Remove all events owned by the specified user in all calendars. - * - * @todo Refactor: move to Kronolith:: - * - * @param string $user The user name to delete events for. - * - * @param mixed True | PEAR_Error - */ - public function removeUserData($user) - { - return PEAR::raiseError(_("Removing user data is not supported with the current calendar storage backend.")); - } - } diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index ecfe97020..6d8966038 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -64,13 +64,12 @@ class Kronolith_Driver_Sql extends Kronolith_Driver return '#dddddd'; } + /** + * @throws Kronolith_Exception + */ public function listAlarms($date, $fullevent = false) { $allevents = $this->listEvents($date, null, false, true); - if (is_a($allevents, 'PEAR_Error')) { - return $allevents; - } - $events = array(); foreach ($allevents as $dayevents) { foreach ($dayevents as $event) { @@ -127,7 +126,8 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * @param object $query An object with the criteria to search for. * @param boolean $json Store the results of the events' toJson() method? * - * @return mixed An array of Kronolith_Events or a PEAR_Error. + * @return mixed An array of Kronolith_Events. + * @throws Kronolith_Exception */ public function search($query, $json = false) { @@ -175,17 +175,10 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $query->end, $cond, $values); - if (is_a($eventIds, 'PEAR_Error')) { - return $eventIds; - } - $now = new Horde_Date($_SERVER['REQUEST_TIME']); $events = array(); foreach ($eventIds as $eventId) { $event = $this->getEvent($eventId); - if (is_a($event, 'PEAR_Error')) { - return $event; - } $showRecurrence = true; if ($event->recurs()) { if (empty($query->end)) { @@ -221,6 +214,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * * @return string|boolean Returns a string with event_id or false if * not found. + * @throws Kronolith_Exception */ public function exists($uid, $calendar_id = null) { @@ -240,7 +234,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $event = $this->_db->getRow($query, $values, DB_FETCHMODE_ASSOC); if (is_a($event, 'PEAR_Error')) { Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_ERR); - return $event; + throw new Kronolith_Exception($event); } if ($event) { @@ -267,6 +261,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * that they cover. * * @return array Events in the given time range. + * @throws Kronolith_Exception */ public function listEvents($startDate = null, $endDate = null, $showRecurrence = false, $hasAlarm = false, @@ -285,9 +280,6 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $events = $this->_listEventsConditional($startDate, $endDate, $hasAlarm ? 'event_alarm > ?' : '', $hasAlarm ? array(0) : array()); - if (is_a($events, 'PEAR_Error')) { - return $events; - } $results = array(); foreach ($events as $id) { Kronolith::addEvents($results, $this->getEvent($id), $startDate, @@ -350,9 +342,9 @@ class Kronolith_Driver_Sql extends Kronolith_Driver /* Run the query. */ $qr = $this->_db->query($q, $values); - if (is_a($qr, 'PEAR_Error')) { + if ($qr instanceof PEAR_Error) { Horde::logMessage($qr, __FILE__, __LINE__, PEAR_LOG_ERR); - return $qr; + throw new Kronolith_Exception($qr); } $events = array(); @@ -402,6 +394,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * Returns the number of events in the current calendar. * * @return integer The number of events. + * @throws Kronolith_Exception */ public function countEvents() { @@ -413,9 +406,18 @@ class Kronolith_Driver_Sql extends Kronolith_Driver __FILE__, __LINE__, PEAR_LOG_DEBUG); /* Run the query. */ - return $this->_db->getOne($query, array($this->calendar)); + $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); + } + return $result; } + /** + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound + */ public function getEvent($eventId = null) { if (!strlen($eventId)) { @@ -444,15 +446,15 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $event = $this->_db->getRow($query, $values, DB_FETCHMODE_ASSOC); if (is_a($event, 'PEAR_Error')) { Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_ERR); - return $event; + throw new Kronolith_Exception($event); } if ($event) { $this->_cache[$this->calendar][$eventId] = new $this->_eventClass($this, $event); return $this->_cache[$this->calendar][$eventId]; - } else { - return PEAR::raiseError(_("Event not found")); } + + throw new Horde_Exception_NotFound(_("Event not found")); } /** @@ -464,6 +466,8 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * an error will be returned if more than one event is found. * * @return Kronolith_Event + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function getByUID($uid, $calendars = null, $getAll = false) { @@ -480,7 +484,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver /* Optionally filter by calendar */ if (!is_null($calendars)) { if (!count($calendars)) { - return PEAR::raiseError(_("No calendars to search")); + throw new Kronolith_Exception(_("No calendars to search")); } $query .= ' AND calendar_id IN (?' . str_repeat(', ?', count($calendars) - 1) . ')'; $values = array_merge($values, $calendars); @@ -494,10 +498,10 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $events = $this->_db->getAll($query, $values, DB_FETCHMODE_ASSOC); if (is_a($events, 'PEAR_Error')) { Horde::logMessage($events, __FILE__, __LINE__, PEAR_LOG_ERR); - return $events; + throw new Kronolith_Exception($events); } if (!count($events)) { - return PEAR::raiseError($uid . ' not found'); + throw new Horde_Exception_NotFound($uid . ' not found'); } $eventArray = array(); @@ -541,9 +545,14 @@ class Kronolith_Driver_Sql extends Kronolith_Driver /** * Saves an event in the backend. + * * If it is a new event, it is added, otherwise the event is updated. * * @param Kronolith_Event $event The event to save. + * + * @return integer The event id. + * @throws Horde_Mime_Exception + * @throws Kronolith_Exception */ public function saveEvent($event) { @@ -568,7 +577,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $result = $this->_write_db->query($query, $values); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - return $result; + throw new Kronolith_Exception($result); } /* Log the modification of this item in the history log. */ @@ -583,90 +592,74 @@ class Kronolith_Driver_Sql extends Kronolith_Driver /* Update Geolocation */ if ($gDriver = Kronolith::getGeoDriver()) { - try { - $gDriver->setLocation($event->id, $event->geoLocation); - } catch (Horde_Exception $e) { - Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); - return new PEAR_Error($e->getMessage()); - } + $gDriver->setLocation($event->id, $event->geoLocation); } /* Notify users about the changed event. */ - $result = Kronolith::sendNotification($event, 'edit'); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - } + Kronolith::sendNotification($event, 'edit'); return $event->id; + } + + if ($event->id) { + $id = $event->id; } else { - if ($event->id) { - $id = $event->id; - } else { - $id = hash('md5', uniqid(mt_rand(), true)); - $event->id = $id; - } + $id = hash('md5', uniqid(mt_rand(), true)); + $event->id = $id; + } - if ($event->uid) { - $uid = $event->uid; - } else { - $uid = (string)new Horde_Support_Guid; - $event->uid = $uid; - } + if ($event->uid) { + $uid = $event->uid; + } else { + $uid = (string)new Horde_Support_Guid; + $event->uid = $uid; + } - $query = 'INSERT INTO ' . $this->_params['table']; - $cols_name = ' (event_id, event_uid,'; - $cols_values = ' VALUES (?, ?,'; - $values = array($id, $uid); + $query = 'INSERT INTO ' . $this->_params['table']; + $cols_name = ' (event_id, event_uid,'; + $cols_values = ' VALUES (?, ?,'; + $values = array($id, $uid); - foreach ($event->getProperties() as $key => $val) { - $cols_name .= " $key,"; - $cols_values .= ' ?,'; - $values[] = $val; - } + foreach ($event->getProperties() as $key => $val) { + $cols_name .= " $key,"; + $cols_values .= ' ?,'; + $values[] = $val; + } - $cols_name .= ' calendar_id)'; - $cols_values .= ' ?)'; - $values[] = $this->calendar; + $cols_name .= ' calendar_id)'; + $cols_values .= ' ?)'; + $values[] = $this->calendar; - $query .= $cols_name . $cols_values; + $query .= $cols_name . $cols_values; - /* Log the query at a DEBUG log level. */ - Horde::logMessage(sprintf('Kronolith_Driver_Sql::saveEvent(): user = "%s"; query = "%s"; values = "%s"', - Horde_Auth::getAuth(), $query, implode(',', $values)), - __FILE__, __LINE__, PEAR_LOG_DEBUG); + /* Log the query at a DEBUG log level. */ + Horde::logMessage(sprintf('Kronolith_Driver_Sql::saveEvent(): user = "%s"; query = "%s"; values = "%s"', + Horde_Auth::getAuth(), $query, implode(',', $values)), + __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); - return $result; - } + $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); + } - /* Log the creation of this item in the history log. */ - $history = Horde_History::singleton(); - $history->log('kronolith:' . $this->calendar . ':' . $uid, array('action' => 'add'), true); + /* Log the creation of this item in the history log. */ + $history = Horde_History::singleton(); + $history->log('kronolith:' . $this->calendar . ':' . $uid, array('action' => 'add'), true); - /* Deal with any tags */ - $tagger = Kronolith::getTagger(); - $tagger->tag($event->uid, $event->tags, 'event'); + /* Deal with any tags */ + $tagger = Kronolith::getTagger(); + $tagger->tag($event->uid, $event->tags, 'event'); - /* Update Geolocation */ - if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) { - try { - $gDriver->setLocation($event->id, $event->geoLocation); - } catch (Horde_Exception $e) { - Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); - return new PEAR_Error($e->getMessage()); - } - } + /* Update Geolocation */ + if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) { + $gDriver->setLocation($event->id, $event->geoLocation); + } - /* Notify users about the new event. */ - $result = Kronolith::sendNotification($event, 'add'); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - } + /* Notify users about the new event. */ + Kronolith::sendNotification($event, 'add'); - return $id; - } + return $id; } /** @@ -676,14 +669,13 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * @param string $newCalendar The new calendar. * * @return Kronolith_Event The old event. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ protected function _move($eventId, $newCalendar) { /* Fetch the event for later use. */ $event = $this->getEvent($eventId); - if (is_a($event, 'PEAR_Error')) { - return $event; - } $query = 'UPDATE ' . $this->_params['table'] . ' SET calendar_id = ? WHERE calendar_id = ? AND event_id = ?'; $values = array($newCalendar, $this->calendar, $eventId); @@ -697,7 +689,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $result = $this->_write_db->query($query, $values); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - return $result; + throw new Kronolith_Exception($result); } return $event; @@ -708,7 +700,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * * @param string $calendar The name of the calendar to delete. * - * @return mixed True or a PEAR_Error on failure. + * @throws Kronolith_Exception */ public function delete($calendar) { @@ -720,7 +712,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver Horde_Auth::getAuth(), $query, implode(',', $values)), __FILE__, __LINE__, PEAR_LOG_DEBUG); - return $this->_write_db->query($query, $values); + $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); + } } /** @@ -730,15 +726,14 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * @param boolean $silent Don't send notifications, used when deleting * events in bulk from maintenance tasks. * - * @return mixed True or a PEAR_Error on failure. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound + * @throws Horde_Mime_Exception */ public function deleteEvent($eventId, $silent = false) { /* Fetch the event for later use. */ $event = $this->getEvent($eventId); - if (is_a($event, 'PEAR_Error')) { - return $event; - } $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE event_id = ? AND calendar_id = ?'; $values = array($eventId, $this->calendar); @@ -751,7 +746,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $result = $this->_write_db->query($query, $values); if (is_a($result, 'PEAR_Error')) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - return $result; + throw new Kronolith_Exception($result); } /* Log the deletion of this item in the history log. */ @@ -791,18 +786,40 @@ class Kronolith_Driver_Sql extends Kronolith_Driver /* Notify about the deleted event. */ if (!$silent) { - $result = Kronolith::sendNotification($event, 'delete'); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - } + Kronolith::sendNotification($event, 'delete'); + } + } + + /** + * Filters a list of events to return only those that belong to certain + * calendars. + * + * @param array $uids A list of event UIDs. + * @param array $calendar A list of calendar IDs. + * + * @return array Event UIDs filtered by calendar IDs. + * @throws Kronolith_Exception + */ + public function filterEventsByCalendar($uids, $calendar) + { + $sql = 'SELECT event_uid FROM kronolith_events WHERE calendar_id IN (' . str_repeat('?, ', count($calendar) - 1) . '?) ' + . 'AND event_uid IN (' . str_repeat('?,', count($uids) - 1) . '?)'; + + /* Log the query at a DEBUG log level. */ + Horde::logMessage(sprintf('Kronolith_Driver_Sql::filterEventsByCalendar(): %s', $sql), + __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); } - return true; } /** * Attempts to open a connection to the SQL server. * - * @return boolean True. + * @throws Kronolith_Exception */ public function initialize() { @@ -826,8 +843,8 @@ 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 (is_a($this->_write_db, 'PEAR_Error')) { - return $this->_write_db; + if ($this->_write_db instanceof PEAR_Error) { + throw new Kronolith_Exception($this->_write_db); } $this->_initConn($this->_write_db); @@ -838,16 +855,14 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $this->_db = DB::connect($params, array('persistent' => !empty($params['persistent']), 'ssl' => !empty($params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; + if ($this->_db instanceof PEAR_Error) { + throw new Kronolith_Exception($this->_db); } $this->_initConn($this->_db); } else { /* Default to the same DB handle for the writer too. */ $this->_db = $this->_write_db; } - - return true; } /** @@ -918,18 +933,20 @@ class Kronolith_Driver_Sql extends Kronolith_Driver /** * Remove all events owned by the specified user in all calendars. * - * @todo Refactor: move to Kronolith:: + * @todo Refactor: move to Kronolith:: and catch exceptions instead of relying on boolean return value. * * @param string $user The user name to delete events for. * - * @param mixed True | PEAR_Error + * @return boolean + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function removeUserData($user) { - return PEAR::raiseError('to be refactored'); + throw new Kronolith_Exception('to be refactored'); if (!Horde_Auth::isAdmin()) { - return PEAR::raiseError(_("Permission Denied")); + throw new Kronolith_Exception(_("Permission Denied")); } $shares = $GLOBALS['kronolith_shares']->listShares($user, Horde_Perms::EDIT); @@ -949,10 +966,6 @@ class Kronolith_Driver_Sql extends Kronolith_Driver foreach ($uids as $uid) { $event = $this->getByUID($uid); - if (is_a($event, 'PEAR_Error')) { - return $event; - } - $this->deleteEvent($event->id); } } @@ -960,25 +973,4 @@ class Kronolith_Driver_Sql extends Kronolith_Driver return true; } - /** - * Filter an array of event_uids to return only the events that belong to - * one of the $calendars. - * - * @param array $uids An array of event_uid values. - * @param array $calendar An array of calendar_ids. - * - * @return An array of event_uid values filtered by calendar_ids || PEAR_Error - */ - public function filterEventsByCalendar($uids, $calendar) - { - $sql = 'SELECT event_uid FROM kronolith_events WHERE calendar_id IN (' . str_repeat('?, ', count($calendar) - 1) . '?) ' - . 'AND event_uid IN (' . str_repeat('?,', count($uids) - 1) . '?)'; - - /* Log the query at a DEBUG log level. */ - Horde::logMessage(sprintf('Kronolith_Driver_Sql::filterEventsByCalendar(): %s', $sql), - __FILE__, __LINE__, PEAR_LOG_DEBUG); - - return $this->_db->getCol($sql, 0, array_merge($calendar, $uids)); - } - } diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 76fbea3e4..d0671803d 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -290,7 +290,10 @@ abstract class Kronolith_Event /* Get geolocation data */ if ($gDriver = Kronolith::getGeoDriver()) { - $this->geoLocation = $gDriver->getLocation($this->id); + try { + $this->geoLocation = $gDriver->getLocation($this->id); + } catch (Exception $e) { + } } } } @@ -373,15 +376,14 @@ abstract class Kronolith_Event * Returns the share this event belongs to. * * @return Horde_Share This event's share. + * @throws Kronolith_Exception */ public function getShare() { if (isset($GLOBALS['all_calendars'][$this->calendar])) { - $share = $GLOBALS['all_calendars'][$this->calendar]; - } else { - $share = PEAR::raiseError('Share not found'); + return $GLOBALS['all_calendars'][$this->calendar]; } - return $share; + throw new Kronolith_Exception('Share not found'); } /** @@ -397,30 +399,32 @@ abstract class Kronolith_Event if ($user === null) { $user = Horde_Auth::getAuth(); } - - return (!is_a($share = &$this->getShare(), 'PEAR_Error') && - $share->hasPermission($user, $permission, $this->creator)); + try { + $share = $this->getShare(); + } catch (Exception $e) { + return false; + } + return $share->hasPermission($user, $permission, $this->creator); } /** * Saves changes to this event. * - * @return mixed True or a PEAR_Error on failure. + * @return integer The event id. + * @throws Kronolith_Exception */ public function save() { if (!$this->initialized) { - return PEAR::raiseError('Event not yet initialized'); + throw new Kronolith_Exception('Event not yet initialized'); } - /* Check for acceptance/denial of this event's resources. - */ + /* Check for acceptance/denial of this event's resources. */ $add_events = array(); $locks = Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']); $lock = array(); $failed_resources = array(); foreach ($this->getResources() as $id => $resourceData) { - /* Get the resource and protect against infinite recursion in case * someone is silly enough to add a resource to it's own event.*/ $resource = Kronolith::getDriver('Resource')->getResource($id); @@ -441,7 +445,7 @@ abstract class Kronolith_Event // Already locked // For now, just fail. Not sure how else to capture the locked // resources and notify the user. - return PEAR::raiseError(sprintf(_("The resource \"%s\" was locked. Please try again."), $resource->get('name'))); + throw new Kronolith_Exception(sprintf(_("The resource \"%s\" was locked. Please try again."), $resource->get('name'))); } else { $response = $resource->getResponse($this); } @@ -461,17 +465,13 @@ abstract class Kronolith_Event /* Save */ $this->toDriver(); $result = $this->getDriver()->saveEvent($this); - if (is_a($result, 'PEAR_Error')) { - return $result; - } - /* Now that the event is definitely commited to storage, we can add the - * event to each resource that has accepted. Not very efficient, but - * this also solves the problem of not having a GUID for the event until - * after it's saved. If we add the event to the resources calendar - * before it is saved, they will have different GUIDs, and hence no - * longer refer to the same event. - */ + /* Now that the event is definitely commited to storage, we can add + * the event to each resource that has accepted. Not very efficient, + * but this also solves the problem of not having a GUID for the event + * until after it's saved. If we add the event to the resources + * calendar before it is saved, they will have different GUIDs, and + * hence no longer refer to the same event. */ foreach ($add_events as $resource) { $resource->addEvent($this); if ($resource->get('response_type') == Kronolith_Resource::RESPONSETYPE_AUTO) { @@ -974,6 +974,8 @@ abstract class Kronolith_Event * Imports the values for this event from an array of values. * * @param array $hash Array containing all the values. + * + * @throws Kronolith_Exception */ public function fromHash($hash) { @@ -984,7 +986,7 @@ abstract class Kronolith_Event if (!empty($hash['title'])) { $this->title = $hash['title']; } else { - return PEAR::raiseError(_("Events must have a title.")); + throw new Kronolith_Exception(_("Events must have a title.")); } if (!empty($hash['description'])) { $this->description = $hash['description']; @@ -1011,7 +1013,7 @@ abstract class Kronolith_Event 'sec' => $time[2])); } } else { - return PEAR::raiseError(_("Events must have a start date.")); + throw new Kronolith_Exception(_("Events must have a start date.")); } if (empty($hash['duration'])) { if (empty($hash['end_date'])) { @@ -1282,14 +1284,16 @@ abstract class Kronolith_Event if (!isset($this->uid) || !isset($this->calendar)) { return false; } - - $eventID = $this->getDriver()->exists($this->uid, $this->calendar); - if (is_a($eventID, 'PEAR_Error') || !$eventID) { - return false; - } else { - $this->id = $eventID; - return true; + try { + $eventID = $this->getDriver()->exists($this->uid, $this->calendar); + if (!$eventID) { + return false; + } + } catch (Exception $e) { + return $false; } + $this->id = $eventID; + return true; } public function getDuration() @@ -1446,8 +1450,7 @@ abstract class Kronolith_Event */ public function hasAttendee($email) { - $email = Horde_String::lower($email); - return isset($this->attendees[$email]); + return isset($this->attendees[Horde_String::lower($email)]); } /** @@ -1484,13 +1487,12 @@ abstract class Kronolith_Event } /** - * Adds a single Kronolith_Resource to this event. - * No validation or acceptence/denial is done here...it should be done - * when saving the Event. + * Adds a single resource to this event. * - * @param Kronolith_Resource $resource The resource to add + * No validation or acceptence/denial is done here...it should be done + * when saving the event. * - * @return void + * @param Kronolith_Resource $resource The resource to add. */ public function addResource($resource, $response) { @@ -1502,11 +1504,9 @@ abstract class Kronolith_Event } /** - * Remove a Kronolith_Resource from this event - * - * @param Kronolith_Resource $resource The resource to remove + * Removes a resource from this event. * - * @return void + * @param Kronolith_Resource $resource The resource to remove. */ public function removeResource($resource) { @@ -1516,9 +1516,9 @@ abstract class Kronolith_Event } /** - * Returns the entire resources array. + * Returns all resources. * - * @return array A copy of the attendees array. + * @return array A copy of the resources array. */ public function getResources() { diff --git a/kronolith/lib/Forms/CreateCalendar.php b/kronolith/lib/Forms/CreateCalendar.php index 5bf4f352b..b95e7fd2a 100755 --- a/kronolith/lib/Forms/CreateCalendar.php +++ b/kronolith/lib/Forms/CreateCalendar.php @@ -8,22 +8,16 @@ * @package Kronolith */ -/** Horde_Form */ -require_once 'Horde/Form.php'; - -/** Horde_Form_Renderer */ -require_once 'Horde/Form/Renderer.php'; - /** - * The Kronolith_CreateCalendarForm class provides the form for - * creating a calendar. + * The Kronolith_CreateCalendarForm class provides the form for creating a + * calendar. * * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_CreateCalendarForm extends Horde_Form { - - function Kronolith_CreateCalendarForm(&$vars) +class Kronolith_CreateCalendarForm extends Horde_Form +{ + public function __construct($vars) { parent::Horde_Form($vars, _("Create Calendar")); @@ -38,7 +32,10 @@ class Kronolith_CreateCalendarForm extends Horde_Form { $this->setButtons(array(_("Create"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $info = array(); foreach (array('name', 'color', 'description', 'tags', 'system') as $key) { diff --git a/kronolith/lib/Forms/CreateResource.php b/kronolith/lib/Forms/CreateResource.php index 9f8c3d34e..fd9ef25d0 100644 --- a/kronolith/lib/Forms/CreateResource.php +++ b/kronolith/lib/Forms/CreateResource.php @@ -1,6 +1,6 @@ * @author Michael J. Rubinsky * @package Kronolith */ -class Kronolith_CreateResourceForm extends Horde_Form { - - function Kronolith_CreateResourceForm(&$vars) +class Kronolith_CreateResourceForm extends Horde_Form +{ + /** + * @throws Kronolith_Exception + */ + public function __construct($vars) { parent::Horde_Form($vars, _("Create Resource")); + $responses = array(Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT => _("Always Accept"), Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE => _("Always Decline"), Kronolith_Resource::RESPONSETYPE_AUTO => _("Automatically"), @@ -34,8 +32,9 @@ class Kronolith_CreateResourceForm extends Horde_Form { Kronolith_Resource::RESPONSETYPE_NONE => _("None")); /* Get a list of available resource groups */ - $driver = Kronolith::getDriver('Resource'); - $groups = $driver->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_GROUP)); + $groups = Kronolith::getDriver('Resource') + ->listResources(Horde_Perms::READ, + array('type' => Kronolith_Resource::TYPE_GROUP)); $enum = array(); foreach ($groups as $id => $group) { $enum[$id] = $group->get('name'); @@ -49,14 +48,15 @@ class Kronolith_CreateResourceForm extends Horde_Form { $this->setButtons(array(_("Create"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $new = array('name' => $this->_vars->get('name'), 'description' => $this->_vars->get('description'), 'response_type' => $this->_vars->get('responsetype')); - - $resource = new Kronolith_Resource_Single($new); - $resource = Kronolith_Resource::addResource($resource); + $resource = Kronolith_Resource::addResource(new Kronolith_Resource_Single($new)); /* Do we need to add this to any groups? */ $groups = $this->_vars->get('category'); diff --git a/kronolith/lib/Forms/CreateResourceGroup.php b/kronolith/lib/Forms/CreateResourceGroup.php index 6bc71d24d..5ca78eb03 100644 --- a/kronolith/lib/Forms/CreateResourceGroup.php +++ b/kronolith/lib/Forms/CreateResourceGroup.php @@ -1,6 +1,6 @@ * @author Michael J. Rubinsky * @package Kronolith */ -class Kronolith_CreateResourceGroupForm extends Horde_Form { - - function Kronolith_CreateResourceGroupForm(&$vars) +class Kronolith_CreateResourceGroupForm extends Horde_Form +{ + /** + * @throws Kronolith_Exception + */ + public function __construct($vars) { parent::Horde_Form($vars, _("Create Resource")); @@ -39,15 +36,12 @@ class Kronolith_CreateResourceGroupForm extends Horde_Form { $this->setButtons(array(_("Create"))); } - function execute() + public function execute() { $new = array('name' => $this->_vars->get('name'), 'description' => $this->_vars->get('description'), 'members' => $this->_vars->get('members')); - - $resource = new Kronolith_Resource_Group($new); - - return $results = Kronolith_Resource::addResource($resource); + return Kronolith_Resource::addResource(new Kronolith_Resource_Group($new)); } } diff --git a/kronolith/lib/Forms/DeleteCalendar.php b/kronolith/lib/Forms/DeleteCalendar.php index 0791b027a..c8ffce14f 100644 --- a/kronolith/lib/Forms/DeleteCalendar.php +++ b/kronolith/lib/Forms/DeleteCalendar.php @@ -8,29 +8,23 @@ * @package Kronolith */ -/** Horde_Form */ -require_once 'Horde/Form.php'; - -/** Horde_Form_Renderer */ -require_once 'Horde/Form/Renderer.php'; - /** - * The Kronolith_DeleteCalendarForm class provides the form for - * deleting a calendar. + * The Kronolith_DeleteCalendarForm class provides the form for deleting a + * calendar. * * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_DeleteCalendarForm extends Horde_Form { - +class Kronolith_DeleteCalendarForm extends Horde_Form +{ /** - * Calendar being deleted + * Calendar being deleted. */ - var $_calendar; + protected $_calendar; - function Kronolith_DeleteCalendarForm(&$vars, &$calendar) + public function __construct($vars, $calendar) { - $this->_calendar = &$calendar; + $this->_calendar = $calendar; parent::Horde_Form($vars, sprintf(_("Delete %s"), $calendar->get('name'))); $this->addHidden('', 'c', 'text', true); @@ -39,7 +33,10 @@ class Kronolith_DeleteCalendarForm extends Horde_Form { $this->setButtons(array(_("Delete"), _("Cancel"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { // If cancel was clicked, return false. if ($this->_vars->get('submitbutton') == _("Cancel")) { diff --git a/kronolith/lib/Forms/DeleteResource.php b/kronolith/lib/Forms/DeleteResource.php index 46f9d54b4..3adf6e060 100644 --- a/kronolith/lib/Forms/DeleteResource.php +++ b/kronolith/lib/Forms/DeleteResource.php @@ -1,6 +1,6 @@ + * @author Michael J. Rubinsky * @package Kronolith */ -class Kronolith_DeleteResourceForm extends Horde_Form { - +class Kronolith_DeleteResourceForm extends Horde_Form +{ /** - * Calendar being deleted + * Resource being deleted. + * + * @var Kronolith_Resource_Single */ - var $_calendar; + protected $_resource; - function Kronolith_DeleteResourceForm(&$vars, &$resource) + public function __construct($vars, $resource) { - $this->_resource = &$resource; + $this->_resource = $resource; parent::Horde_Form($vars, sprintf(_("Delete %s"), $resource->get('name'))); $this->addHidden('', 'c', 'text', true); @@ -39,24 +36,26 @@ class Kronolith_DeleteResourceForm extends Horde_Form { $this->setButtons(array(_("Delete"), _("Cancel"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { // If cancel was clicked, return false. if ($this->_vars->get('submitbutton') == _("Cancel")) { - return false; + return; } if (!($this->_resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE))) { - return PEAR::raiseError(_("Permission denied")); + throw new Kronolith_Exception(_("Permission denied")); } // Delete the resource. - $result = Kronolith::getDriver('Resource')->delete($this->_resource); - if ($result instanceof PEAR_Error) { - return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $result->getMessage())); + try { + Kronolith::getDriver('Resource')->delete($this->_resource); + } catch (Exception $e) { + throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $e->getMessage())); } - - return true; } } diff --git a/kronolith/lib/Forms/DeleteResourceGroup.php b/kronolith/lib/Forms/DeleteResourceGroup.php index 01a8e1ae3..65d45e1fb 100644 --- a/kronolith/lib/Forms/DeleteResourceGroup.php +++ b/kronolith/lib/Forms/DeleteResourceGroup.php @@ -1,6 +1,6 @@ + * @author Michael J. Rubinsky * @package Kronolith */ -class Kronolith_DeleteResourceGroupForm extends Horde_Form { - +class Kronolith_DeleteResourceGroupForm extends Horde_Form +{ /** - * Calendar being deleted + * Resource group being deleted. + * + * @var Kronolith_Resource_Group */ - var $_calendar; + protected $_resource; - function Kronolith_DeleteResourceGroupForm(&$vars, &$resource) + public function __construct($vars, $resource) { - $this->_resource = &$resource; + $this->_resource = $resource; parent::Horde_Form($vars, sprintf(_("Delete %s"), $resource->get('name'))); $this->addHidden('', 'c', 'text', true); @@ -39,24 +36,26 @@ class Kronolith_DeleteResourceGroupForm extends Horde_Form { $this->setButtons(array(_("Delete"), _("Cancel"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { // If cancel was clicked, return false. if ($this->_vars->get('submitbutton') == _("Cancel")) { - return false; + return; } if (!($this->_resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE))) { - return PEAR::raiseError(_("Permission denied")); + throw new Kronolith_Exception(_("Permission denied")); } // Delete the resource. - $result = Kronolith::getDriver('Resource')->delete($this->_resource); - if ($result instanceof PEAR_Error) { - return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $result->getMessage())); + try { + Kronolith::getDriver('Resource')->delete($this->_resource); + } catch (Exception $e) { + throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $e->getMessage())); } - - return true; } } diff --git a/kronolith/lib/Forms/EditCalendar.php b/kronolith/lib/Forms/EditCalendar.php index 37526799c..8c525a4d8 100644 --- a/kronolith/lib/Forms/EditCalendar.php +++ b/kronolith/lib/Forms/EditCalendar.php @@ -8,29 +8,23 @@ * @package Kronolith */ -/** Horde_Form */ -require_once 'Horde/Form.php'; - -/** Horde_Form_Renderer */ -require_once 'Horde/Form/Renderer.php'; - /** - * The Kronolith_EditCalendarForm class provides the form for - * editing a calendar. + * The Kronolith_EditCalendarForm class provides the form for editing a + * calendar. * * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_EditCalendarForm extends Horde_Form { - +class Kronolith_EditCalendarForm extends Horde_Form +{ /** - * Calendar being edited + * Calendar being edited. */ - var $_calendar; + protected $_calendar; - function Kronolith_EditCalendarForm(&$vars, &$calendar) + public function __construct($vars, $calendar) { - $this->_calendar = &$calendar; + $this->_calendar = $calendar; parent::Horde_Form($vars, sprintf(_("Edit %s"), $calendar->get('name'))); $this->addHidden('', 'c', 'text', true); @@ -45,7 +39,10 @@ class Kronolith_EditCalendarForm extends Horde_Form { $this->setButtons(array(_("Save"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $info = array(); foreach (array('name', 'color', 'description', 'tags', 'system') as $key) { diff --git a/kronolith/lib/Forms/EditRemoteCalendar.php b/kronolith/lib/Forms/EditRemoteCalendar.php index 33fdfbb4f..f0c2d84b9 100644 --- a/kronolith/lib/Forms/EditRemoteCalendar.php +++ b/kronolith/lib/Forms/EditRemoteCalendar.php @@ -8,22 +8,16 @@ * @package Kronolith */ -/** Horde_Form */ -require_once 'Horde/Form.php'; - -/** Horde_Form_Renderer */ -require_once 'Horde/Form/Renderer.php'; - /** - * The Kronolith_EditRemoteCalendarForm class provides the form for - * editing a remote calendar. + * The Kronolith_EditRemoteCalendarForm class provides the form for editing a + * remote calendar. * * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_EditRemoteCalendarForm extends Horde_Form { - - function Kronolith_EditRemoteCalendarForm(&$vars, $remote_calendar) +class Kronolith_EditRemoteCalendarForm extends Horde_Form +{ + public function __construct($vars, $remote_calendar) { parent::Horde_Form($vars, sprintf(_("Edit %s"), $remote_calendar['name'])); @@ -39,7 +33,10 @@ class Kronolith_EditRemoteCalendarForm extends Horde_Form { $this->setButtons(array(_("Save"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $info = array(); foreach (array('name', 'new_url', 'user', 'password', 'color', 'desc') as $key) { diff --git a/kronolith/lib/Forms/EditResource.php b/kronolith/lib/Forms/EditResource.php index d46b93a80..c73841595 100644 --- a/kronolith/lib/Forms/EditResource.php +++ b/kronolith/lib/Forms/EditResource.php @@ -1,6 +1,6 @@ + * @author Michael J. Rubinsky * @package Kronolith */ -class Kronolith_EditResourceForm extends Horde_Form { - +class Kronolith_EditResourceForm extends Horde_Form +{ /** - * Calendar being edited + * Resource being edited. + * + * @var Kronolith_Resource_Single */ - var $_resource; + protected $_resource; - function Kronolith_EditResourceForm(&$vars, &$resource) + /** + * @throws Kronolith_Exception + */ + public function __construct($vars, $resource) { - $this->_resource = &$resource; + $this->_resource = $resource; parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name'))); + $responses = array(Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT => _("Always Accept"), Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE => _("Always Decline"), Kronolith_Resource::RESPONSETYPE_AUTO => _("Automatically"), @@ -39,8 +40,9 @@ class Kronolith_EditResourceForm extends Horde_Form { Kronolith_Resource::RESPONSETYPE_NONE => _("None")); /* Get a list of available resource groups */ - $driver = Kronolith::getDriver('Resource'); - $groups = $driver->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_GROUP)); + $groups = Kronolith::getDriver('Resource') + ->listResources(Horde_Perms::READ, + array('type' => Kronolith_Resource::TYPE_GROUP)); $enum = array(); foreach ($groups as $id => $group) { $enum[$id] = $group->get('name'); @@ -54,7 +56,10 @@ class Kronolith_EditResourceForm extends Horde_Form { $this->setButtons(array(_("Save"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $original_name = $this->_resource->get('name'); $new_name = $this->_vars->get('name'); @@ -96,14 +101,13 @@ class Kronolith_EditResourceForm extends Horde_Form { $group->save(); } - - $result = $this->_resource->save(); - if (is_a($result, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $result->getMessage())); + try { + $result = $this->_resource->save(); + } catch (Exception $e) { + throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage())); } return $this->_resource; - } } diff --git a/kronolith/lib/Forms/EditResourceGroup.php b/kronolith/lib/Forms/EditResourceGroup.php index 92402dc1c..2feb6c083 100644 --- a/kronolith/lib/Forms/EditResourceGroup.php +++ b/kronolith/lib/Forms/EditResourceGroup.php @@ -1,6 +1,6 @@ + * @author Michael J. Rubinsky * @package Kronolith */ -class Kronolith_EditResourceGroupForm extends Horde_Form { - +class Kronolith_EditResourceGroupForm extends Horde_Form +{ /** - * Calendar being edited + * Resource group being edited. + * + * @var Kronolith_Resource_Single */ - var $_resource; + protected $_resource; - function Kronolith_EditResourceGroupForm(&$vars, &$resource) + /** + * @throws Kronolith_Exception + */ + public function __construct($vars, $resource) { - $this->_resource = &$resource; + $this->_resource = $resource; parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name'))); + $resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_SINGLE)); $enum = array(); foreach ($resources as $r) { @@ -42,11 +43,13 @@ class Kronolith_EditResourceGroupForm extends Horde_Form { $this->addVariable(_("Name"), 'name', 'text', true); $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60)); $this->addVariable(_("Resources"), 'members', 'multienum', false, false, null, array('enum' => $enum)); - $this->setButtons(array(_("Save"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $original_name = $this->_resource->get('name'); $new_name = $this->_vars->get('name'); @@ -54,13 +57,13 @@ class Kronolith_EditResourceGroupForm extends Horde_Form { $this->_resource->set('description', $this->_vars->get('description')); $this->_resource->set('members', $this->_vars->get('members')); - $result = $this->_resource->save(); - if (is_a($result, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $result->getMessage())); + try { + $this->_resource->save(); + } catch (Exception $e) { + throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage())); } return $this->_resource; - } } diff --git a/kronolith/lib/Forms/SubscribeRemoteCalendar.php b/kronolith/lib/Forms/SubscribeRemoteCalendar.php index e04c5655d..49aab5d58 100644 --- a/kronolith/lib/Forms/SubscribeRemoteCalendar.php +++ b/kronolith/lib/Forms/SubscribeRemoteCalendar.php @@ -8,22 +8,16 @@ * @package Kronolith */ -/** Horde_Form */ -require_once 'Horde/Form.php'; - -/** Horde_Form_Renderer */ -require_once 'Horde/Form/Renderer.php'; - /** - * The Kronolith_SubscribeRemoteCalendarForm class provides the form - * for subscribing to remote calendars + * The Kronolith_SubscribeRemoteCalendarForm class provides the form for + * subscribing to remote calendars. * * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form { - - function Kronolith_SubscribeRemoteCalendarForm(&$vars) +class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form +{ + public function __construct($vars) { parent::Horde_Form($vars, _("Subscribe to a Remote Calendar")); @@ -37,13 +31,16 @@ class Kronolith_SubscribeRemoteCalendarForm extends Horde_Form { $this->setButtons(array(_("Subscribe"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { $info = array(); foreach (array('name', 'url', 'color', 'username', 'password') as $key) { $info[$key] = $this->_vars->get($key); } - return Kronolith::subscribeRemoteCalendar($info); + Kronolith::subscribeRemoteCalendar($info); } } diff --git a/kronolith/lib/Forms/UnsubscribeRemoteCalendar.php b/kronolith/lib/Forms/UnsubscribeRemoteCalendar.php index 8dc48785e..773e115c8 100644 --- a/kronolith/lib/Forms/UnsubscribeRemoteCalendar.php +++ b/kronolith/lib/Forms/UnsubscribeRemoteCalendar.php @@ -8,22 +8,16 @@ * @package Kronolith */ -/** Horde_Form */ -require_once 'Horde/Form.php'; - -/** Horde_Form_Renderer */ -require_once 'Horde/Form/Renderer.php'; - /** * The Kronolith_UnsubscribeRemoteCalendarForm class provides the form for - * deleting a calendar. + * unsubscribing from remote calendars. * * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_UnsubscribeRemoteCalendarForm extends Horde_Form { - - function Kronolith_UnsubscribeRemoteCalendarForm(&$vars, $calendar) +class Kronolith_UnsubscribeRemoteCalendarForm extends Horde_Form +{ + public function __construct($vars, $calendar) { parent::Horde_Form($vars, sprintf(_("Unsubscribe from %s"), $calendar['name'])); @@ -33,14 +27,16 @@ class Kronolith_UnsubscribeRemoteCalendarForm extends Horde_Form { $this->setButtons(array(_("Unsubscribe"), _("Cancel"))); } - function execute() + /** + * @throws Kronolith_Exception + */ + public function execute() { // If cancel was clicked, return false. if ($this->_vars->get('submitbutton') == _("Cancel")) { return false; } - - return Kronolit::unsubscribeRemoteCalendar($this->_vars->get('url')); + return Kronolith::unsubscribeRemoteCalendar($this->_vars->get('url')); } } diff --git a/kronolith/lib/FreeBusy.php b/kronolith/lib/FreeBusy.php index 027f937fa..bfd4db5ff 100644 --- a/kronolith/lib/FreeBusy.php +++ b/kronolith/lib/FreeBusy.php @@ -5,7 +5,8 @@ * @author Chuck Hagenbuch * @package Kronolith */ -class Kronolith_FreeBusy { +class Kronolith_FreeBusy +{ /** * Generates the free/busy text for $calendar. Cache it for at least an * hour, as well. @@ -18,9 +19,11 @@ class Kronolith_FreeBusy { * @param string $user Set organizer to this user. * * @return string The free/busy text. + * @throws Kronolith_Exception */ - function generate($calendar, $startstamp = null, $endstamp = null, - $returnObj = false, $user = null) + public static function generate($calendar, $startstamp = null, + $endstamp = null, $returnObj = false, + $user = null) { global $kronolith_shares; @@ -29,8 +32,10 @@ class Kronolith_FreeBusy { } /* Fetch the appropriate share and check permissions. */ - $share = &$kronolith_shares->getShare($calendar[0]); - if (is_a($share, 'PEAR_Error')) { + try { + $share = $kronolith_shares->getShare($calendar[0]); + $owner = $share->get('owner'); + } catch (Exception $e) { // Might be a Kronolith_Resource try { $resource = Kronolith_Resource::isResourceCalendar($calendar[0]); @@ -38,8 +43,6 @@ class Kronolith_FreeBusy { } catch (Horde_Exception $e) { return $returnObj ? $share : ''; } - } else { - $owner = $share->get('owner'); } /* Default the start date to today. */ @@ -63,9 +66,6 @@ class Kronolith_FreeBusy { /* Fetch events. */ $busy = Kronolith::listEvents(new Horde_Date($startstamp), $enddate, $calendar); - if (is_a($busy, 'PEAR_Error')) { - return $busy; - } /* Create the new iCalendar. */ $vCal = new Horde_iCalendar(); @@ -73,7 +73,7 @@ class Kronolith_FreeBusy { $vCal->setAttribute('METHOD', 'PUBLISH'); /* Create new vFreebusy. */ - $vFb = &Horde_iCalendar::newComponent('vfreebusy', $vCal); + $vFb = Horde_iCalendar::newComponent('vfreebusy', $vCal); $params = array(); if (!empty($cn)) { $params['CN'] = $cn; @@ -129,8 +129,9 @@ class Kronolith_FreeBusy { * * @return Horde_iCalendar_vfreebusy Free/busy component on success, * PEAR_Error on failure. + * @throws Kronolith_Exception */ - function get($email, $json = false) + public static function get($email, $json = false) { /* Properly handle RFC822-compliant email addresses. */ static $rfc822; @@ -144,14 +145,14 @@ class Kronolith_FreeBusy { return $res; } if (!count($res)) { - return PEAR::raiseError(_("No valid email address found")); + throw new Kronolith_Exception(_("No valid email address found")); } $email = Horde_Mime_Address::writeAddress($res[0]->mailbox, $res[0]->host); /* Check if we can retrieve a VFB from the Free/Busy URL, if one is * set. */ - $url = Kronolith_FreeBusy::getUrl($email); + $url = self::getUrl($email); if ($url) { $url = trim($url); $options['method'] = 'GET'; @@ -164,7 +165,7 @@ class Kronolith_FreeBusy { $http = new HTTP_Request($url, $options); if (is_a($response = @$http->sendRequest(), 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("The free/busy url for %s cannot be retrieved."), $email)); + throw new Kronolith_Exception(sprintf(_("The free/busy url for %s cannot be retrieved."), $email)); } if ($http->getResponseCode() == 200 && $data = $http->getResponseBody()) { @@ -193,21 +194,28 @@ class Kronolith_FreeBusy { } if ($found) { - return $json ? Kronolith_FreeBusy::toJson($vFb) : $vFb; + // @todo: actually store the results in the storage, so + // that they can be retrieved later. We should store the + // plain iCalendar data though, to avoid versioning + // problems with serialize iCalendar objects. + return $json ? self::toJson($vFb) : $vFb; } } } /* Check storage driver. */ - $storage = Kronolith_Storage::singleton(); - - $fb = $storage->search($email); - if (!is_a($fb, 'PEAR_Error')) { - return $json ? Kronolith_FreeBusy::toJson($fb) : $fb; - } elseif ($fb->getCode() == Kronolith::ERROR_FB_NOT_FOUND) { - return $url ? - PEAR::raiseError(sprintf(_("No free/busy information found at the free/busy url of %s."), $email)) : - PEAR::raiseError(sprintf(_("No free/busy url found for %s."), $email)); + $storage = Kronolith_Storage::factory(); + + try { + $fb = $storage->search($email); + return $json ? self::toJson($fb) : $fb; + } catch (Kronolith_Exception $e) { + if ($e->getCode() == Kronolith::ERROR_FB_NOT_FOUND) { + if ($url) { + throw new Kronolith_Exception(sprintf(_("No free/busy information found at the free/busy url of %s."), $email)); + } + throw new Kronolith_Exception(sprintf(_("No free/busy url found for %s."), $email)); + } } /* Or else return an empty VFB object. */ @@ -215,7 +223,7 @@ class Kronolith_FreeBusy { $vFb = Horde_iCalendar::newComponent('vfreebusy', $vCal); $vFb->setAttribute('ORGANIZER', $email); - return $json ? Kronolith_FreeBusy::toJson($vFb) : $vFb; + return $json ? self::toJson($vFb) : $vFb; } /** @@ -225,7 +233,7 @@ class Kronolith_FreeBusy { * * @return mixed The url on success or false on failure. */ - function getUrl($email) + public static function getUrl($email) { $sources = $GLOBALS['prefs']->getValue('search_sources'); $sources = empty($sources) ? array() : explode("\t", $sources); diff --git a/kronolith/lib/Geo.php b/kronolith/lib/Geo.php index e7649e316..e2bbbabcf 100644 --- a/kronolith/lib/Geo.php +++ b/kronolith/lib/Geo.php @@ -28,16 +28,13 @@ abstract class Kronolith_Geo * @param unknown_type $params Any driver specific parameters * * @return Kronolith_Geo + * @throws Kronolith_Exception */ static public function factory($driver = null, $params = array()) { $driver = basename($driver); $class = 'Kronolith_Geo_' . $driver; - - if (class_exists($class)) { - $driver = new $class(Horde::getDriverConfig('calendar', 'sql')); - } - + $driver = new $class(Horde::getDriverConfig('calendar', 'sql')); $driver->initialize(); return $driver; } diff --git a/kronolith/lib/Geo/Mysql.php b/kronolith/lib/Geo/Mysql.php index 9791af0bd..c679092e1 100644 --- a/kronolith/lib/Geo/Mysql.php +++ b/kronolith/lib/Geo/Mysql.php @@ -21,6 +21,7 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql * Set the location of the specified event _id * * @see kronolith/lib/Driver/Kronolith_Driver_Geo#setLocation($event_id, $point) + * @throws Kronolith_Exception */ public function setLocation($event_id, $point) { @@ -28,7 +29,8 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql $sql = "SELECT COUNT(*) FROM kronolith_events_geo WHERE event_id = ('" . $event_id . "')"; $count = $this->_db->getOne($sql); if ($count instanceof PEAR_Error) { - throw new Horde_Exception($count->getMessage()); + Horde::logMessage($count, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($count); } /* Do we actually have data? */ @@ -47,7 +49,8 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql } $result = $this->_write_db->query($sql); if ($result instanceof PEAR_Error) { - throw new Horde_Exception($result->getMessage()); + Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($result); } return $result; @@ -57,13 +60,15 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql * Get the location of the provided event_id. * * @see kronolith/lib/Driver/Kronolith_Driver_Geo#getLocation($event_id) + * @throws Kronolith_Exception */ public function getLocation($event_id) { $sql = "SELECT x(event_coordinates) as lat, y(event_coordinates) as lon FROM kronolith_events_geo WHERE event_id = '" . $event_id . "'"; $result = $this->_db->getRow($sql, null, DB_FETCHMODE_ASSOC); if ($result instanceof PEAR_Error) { - throw new Horde_Exception($result->getMessage()); + Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($result); } return $result; } @@ -79,6 +84,7 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql * MBRs * * @see kronolith/lib/Driver/Kronolith_Driver_Geo#search($criteria) + * @throws Kronolith_Exception */ public function search($criteria) { @@ -96,10 +102,10 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql $results = $this->_db->getAssoc($sql, false, null, DB_FETCHMODE_ASSOC); if ($results instanceof PEAR_Error) { - throw new Horde_Exception($results->getMessage()); + Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($results); } return $results; - } } \ No newline at end of file diff --git a/kronolith/lib/Geo/Sql.php b/kronolith/lib/Geo/Sql.php index d9c6961c8..48e352291 100644 --- a/kronolith/lib/Geo/Sql.php +++ b/kronolith/lib/Geo/Sql.php @@ -1,6 +1,7 @@ _write_db = DB::connect($this->_params, array('persistent' => !empty($this->_params['persistent']), 'ssl' => !empty($this->_params['ssl']))); - if (is_a($this->_write_db, 'PEAR_Error')) { - return $this->_write_db; + if ($this->_write_db instanceof PEAR_Error) { + throw new Kronolith_Exception($this->_write_db); } $this->_initConn($this->_write_db); @@ -54,8 +53,8 @@ class Kronolith_Geo_Sql extends Kronolith_Geo $this->_db = DB::connect($params, array('persistent' => !empty($params['persistent']), 'ssl' => !empty($params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; + if ($this->_db instanceof PEAR_Error) { + throw new Kronolith_Exception($this->_db); } $this->_initConn($this->_db); } else { @@ -76,37 +75,13 @@ class Kronolith_Geo_Sql extends Kronolith_Geo default: $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); } - - /* Handle any database specific initialization code to run. */ - switch ($db->dbsyntax) { - case 'oci8': - $query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"; - - /* Log the query at a DEBUG log level. */ - Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', - Horde_Auth::getAuth(), $query), - __FILE__, __LINE__, PEAR_LOG_DEBUG); - - $db->query($query); - break; - - case 'pgsql': - $query = "SET datestyle TO 'iso'"; - - /* Log the query at a DEBUG log level. */ - Horde::logMessage(sprintf('Kronolith_Driver_Sql::_initConn(): user = "%s"; query = "%s"', - Horde_Auth::getAuth(), $query), - __FILE__, __LINE__, PEAR_LOG_DEBUG); - - $db->query($query); - break; - } } /** * Set the location of the specified event _id * * @see kronolith/lib/Driver/Kronolith_Driver_Geo#setLocation($event_id, $point) + * @throws Kronolith_Exception */ public function setLocation($event_id, $point) { @@ -114,7 +89,8 @@ class Kronolith_Geo_Sql extends Kronolith_Geo $sql = 'SELECT COUNT(*) FORM kronolith_events_geo WHERE event_id = ?'; $count = $this->_db->getOne($sql, array($event_id)); if ($count instanceof PEAR_Error) { - throw new Horde_Exception($count->getMessage()); + Horde::logMessage($count, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($count); } /* Do we actually have data? If not, see if we are deleting an @@ -137,7 +113,8 @@ class Kronolith_Geo_Sql extends Kronolith_Geo } $result = $this->_write_db->query($sql, $params); if ($result instanceof PEAR_Error) { - throw new Horde_Exception($result->getMessage()); + Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($result); } return $result; @@ -147,13 +124,15 @@ class Kronolith_Geo_Sql extends Kronolith_Geo * Get the location of the provided event_id. * * @see kronolith/lib/Driver/Kronolith_Driver_Geo#getLocation($event_id) + * @throws Kronolith_Exception */ public function getLocation($event_id) { $sql = 'SELECT event_lat as lat, event_lng as lng FROM kronolith_events_geo WHERE event_id = ?'; $result = $this->_db->getRow($sql, array($event_id), DB_FETCHMODE_ASSOC); if ($result instanceof PEAR_Error) { - throw new Horde_Exception($result->getMessage()); + Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($result); } return $result; @@ -171,7 +150,11 @@ class Kronolith_Geo_Sql extends Kronolith_Geo public function deleteLocation($event_id) { $sql = 'DELETE FROM kronolith_events_geo WHERE event_id = ?'; - $this->_write_db->query($sql, array($event_id)); + $result = $this->_write_db->query($sql, array($event_id)); + if ($result instanceof PEAR_Error) { + Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + throw new Horde_Exception($result); + } } /** @@ -185,6 +168,7 @@ class Kronolith_Geo_Sql extends Kronolith_Geo * MBRs * * @see kronolith/lib/Driver/Kronolith_Driver_Geo#search($criteria) + * @throws Kronolith_Exception */ public function search($criteria) { diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 7efe48c1d..e714bc1a3 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -349,6 +349,7 @@ class Kronolith * * @return array The alarms active on the date. A hash with calendar names * as keys and arrays of events or event ids as values. + * @throws Kronolith_Exception */ public static function listAlarms($date, $calendars, $fullevent = false) { @@ -358,9 +359,6 @@ class Kronolith foreach ($calendars as $cal) { $kronolith_driver->open($cal); $alarms[$cal] = $kronolith_driver->listAlarms($date, $fullevent); - if (is_a($alarms[$cal], 'PEAR_Error')) { - return $alarms[$cal]; - } } return $alarms; @@ -374,6 +372,7 @@ class Kronolith * "Driver|calendar_id". * * @return array The events. + * @throws Kronolith_Exception */ public static function search($query, $calendar = null) { @@ -418,6 +417,7 @@ class Kronolith * listTimeObjects as well? * * @return array The events happening in this time period. + * @throws Kronolith_Exception */ public static function listEvents($startDate, $endDate, $calendars = null, $showRecurrence = true, @@ -433,9 +433,7 @@ class Kronolith foreach ($calendars as $calendar) { $driver->open($calendar); $events = $driver->listEvents($startDate, $endDate, true); - if (!is_a($events, 'PEAR_Error')) { - self::mergeEvents($results, $events); - } + self::mergeEvents($results, $events); } /* Resource calendars (this would only be populated if explicitly @@ -450,9 +448,7 @@ class Kronolith foreach ($GLOBALS['display_resource_calendars'] as $calendar) { $driver->open($calendar); $events = $driver->listEvents($startDate, $endDate, true); - if (!is_a($events, 'PEAR_Error')) { - self::mergeEvents($results, $events); - } + self::mergeEvents($results, $events); } } @@ -462,9 +458,7 @@ class Kronolith foreach ($GLOBALS['display_external_calendars'] as $external_cal) { $driver->open($external_cal); $events = $driver->listEvents($startDate, $endDate, true); - if (!is_a($events, 'PEAR_Error')) { - self::mergeEvents($results, $events); - } + self::mergeEvents($results, $events); } /* Remote Calendars. */ @@ -475,9 +469,7 @@ class Kronolith $driver->setParam($param, $value); } $events = $driver->listEvents($startDate, $endDate, true); - if (!is_a($events, 'PEAR_Error')) { - self::mergeEvents($results, $events); - } + self::mergeEvents($results, $events); } /* Holidays. */ @@ -485,9 +477,7 @@ class Kronolith foreach ($GLOBALS['display_holidays'] as $holiday) { $driver->open($holiday); $events = $driver->listEvents($startDate, $endDate, true); - if (!is_a($events, 'PEAR_Error')) { - self::mergeEvents($results, $events); - } + self::mergeEvents($results, $events); } } @@ -522,8 +512,6 @@ class Kronolith /** * Calculates recurrences of an event during a certain period. - * - * @access private */ public static function addEvents(&$results, &$event, $startDate, $endDate, $showRecurrence, $json, $coverDates = true) @@ -761,7 +749,10 @@ class Kronolith $count = 0; foreach (array_keys($calendars) as $calendar) { $kronolith_driver->open($calendar); - $count += $kronolith_driver->countEvents(); + try { + $count += $kronolith_driver->countEvents(); + } catch (Exception $e) { + } } /* Reopen last calendar. */ @@ -779,6 +770,7 @@ class Kronolith * calendar will be used. * * @return array The UID of all events that were added. + * @throws Kronolith_Exception */ public function quickAdd($text, $calendar = null) { @@ -808,11 +800,8 @@ class Kronolith $event->description = $description; $event->start = $d; $event->end = $d->add(array('hour' => 1)); + $event->save(); - $eventId = $event->save(); - if (is_a($eventId, 'PEAR_Error')) { - return $eventId; - } return $event; } @@ -1376,12 +1365,13 @@ class Kronolith * @param array $info Hash with calendar information. * * @return Horde_Share The new share. + * @throws Kronolith_Exception */ public static function addShare($info) { $calendar = $GLOBALS['kronolith_shares']->newShare(hash('md5', microtime())); - if (is_a($calendar, 'PEAR_Error')) { - return $calendar; + if ($calendar instanceof PEAR_Error) { + throw new Kronolith_Exception($calendar); } $calendar->set('name', $info['name']); @@ -1394,8 +1384,8 @@ class Kronolith $tagger->tag($calendar->getName(), $info['tags'], 'calendar'); $result = $GLOBALS['kronolith_shares']->addShare($calendar); - if (is_a($result, 'PEAR_Error')) { - return $result; + if ($result instanceof PEAR_Error) { + throw new Kronolith_Exception($result); } $GLOBALS['display_calendars'][] = $calendar->getName(); @@ -1409,13 +1399,15 @@ class Kronolith * * @param Horde_Share $share The share to update. * @param array $info Hash with calendar information. + * + * @throws Kronolith_Exception */ public static function updateShare(&$calendar, $info) { if (!Horde_Auth::getAuth() || ($calendar->get('owner') != Horde_Auth::getAuth() && (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin()))) { - return PEAR::raiseError(_("You are not allowed to change this calendar.")); + throw new Kronolith_Exception(_("You are not allowed to change this calendar.")); } $original_name = $calendar->get('name'); @@ -1423,16 +1415,10 @@ class Kronolith $calendar->set('color', $info['color']); $calendar->set('desc', $info['description']); $calendar->set('owner', empty($info['system']) ? Horde_Auth::getAuth() : null); - if ($original_name != $info['name']) { - $result = Kronolith::getDriver()->rename($original_name, $info['name']); - if (is_a($result, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Unable to rename \"%s\": %s"), $original_name, $result->getMessage())); - } - } $result = $calendar->save(); - if (is_a($result, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Unable to save calendar \"%s\": %s"), $info['name'], $result->getMessage())); + if ($result instanceof PEAR_Error) { + throw new Kronolith_Exception(sprintf(_("Unable to save calendar \"%s\": %s"), $info['name'], $result->getMessage())); } $tagger = self::getTagger(); @@ -1443,38 +1429,46 @@ class Kronolith * Deletes a share. * * @param Horde_Share $calendar The share to delete. + * + * @throws Kronolith_Exception */ public static function deleteShare($calendar) { if ($calendar->getName() == Horde_Auth::getAuth()) { - return PEAR::raiseError(_("This calendar cannot be deleted.")); + throw new Kronolith_Exception(_("This calendar cannot be deleted.")); } if (!Horde_Auth::getAuth() || ($calendar->get('owner') != Horde_Auth::getAuth() && (!is_null($calendar->get('owner')) || !Horde_Auth::isAdmin()))) { - return PEAR::raiseError(_("You are not allowed to delete this calendar.")); + throw new Kronolith_Exception(_("You are not allowed to delete this calendar.")); } // Delete the calendar. - $result = Kronolith::getDriver()->delete($calendar->getName()); - if (is_a($result, 'PEAR_Error')) { - return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $result->getMessage())); + try { + Kronolith::getDriver()->delete($calendar->getName()); + } catch (Exception $e) { + throw new Kronolith_Exception(sprintf(_("Unable to delete \"%s\": %s"), $calendar->get('name'), $ed->getMessage())); } // Remove share and all groups/permissions. - return $GLOBALS['kronolith_shares']->removeShare($calendar); + $result = $GLOBALS['kronolith_shares']->removeShare($calendar); + if ($result instanceof PEAR_Error) { + throw new Kronolith_Exception($result); + } } /** * Subscribes to a remote calendar. * * @param array $info Hash with calendar information. + * + * @throws Kronolith_Exception */ public static function subscribeRemoteCalendar($info) { if (!(strlen($info['name']) && strlen($info['url']))) { - return PEAR::raiseError(_("You must specify a name and a URL.")); + throw new Kronolith_Exception(_("You must specify a name and a URL.")); } if (strlen($info['username']) || strlen($info['password'])) { @@ -1504,6 +1498,7 @@ class Kronolith * @param string $url The calendar URL. * * @return array Hash with the deleted calendar's information. + * @throws Kronolith_Exception */ public static function unsubscribeRemoteCalendar($url) { @@ -1522,7 +1517,7 @@ class Kronolith } } if (!$remote_calendar) { - return PEAR::raiseError(_("The remote calendar was not found.")); + throw new Kronolith_Exception(_("The remote calendar was not found.")); } $GLOBALS['prefs']->setValue('remote_cals', serialize($remote_calendars)); @@ -1583,6 +1578,8 @@ class Kronolith */ public static function parseAttendees($newAttendees) { + global $notification; + if (empty($newAttendees)) { return; } @@ -1714,7 +1711,7 @@ class Kronolith $myemail = explode('@', $myemail); $from = Horde_Mime_Address::writeAddress($myemail[0], isset($myemail[1]) ? $myemail[1] : '', $ident->getValue('fullname')); - $share = &$GLOBALS['kronolith_shares']->getShare($event->calendar); + $share = $GLOBALS['kronolith_shares']->getShare($event->calendar); foreach ($event->attendees as $email => $status) { /* Don't bother sending an invitation/update if the recipient does @@ -1835,23 +1832,26 @@ class Kronolith * @param Kronolith_Event $event An event. * @param string $action The event action. One of "add", "edit", * or "delete". + * + * @throws Horde_Mime_Exception + * @throws Kronolith_Exception */ - public static function sendNotification(&$event, $action) + public static function sendNotification($event, $action) { global $conf; if (!in_array($action, array('add', 'edit', 'delete'))) { - return PEAR::raiseError('Unknown event action: ' . $action); + throw new Kronolith_Exception('Unknown event action: ' . $action); } require_once 'Horde/Group.php'; - $groups = &Group::singleton(); + $groups = Group::singleton(); $calendar = $event->calendar; $recipients = array(); - $share = &$GLOBALS['kronolith_shares']->getShare($calendar); - if (is_a($share, 'PEAR_Error')) { - return $share; + $share = $GLOBALS['kronolith_shares']->getShare($calendar); + if ($share instanceof PEAR_Error) { + throw new Kronolith_Exception($share); } $identity = Horde_Prefs_Identity::singleton(); @@ -1870,11 +1870,11 @@ class Kronolith foreach ($share->listGroups(Horde_Perms::READ) as $group) { $group = $groups->getGroupById($group); - if (is_a($group, 'PEAR_Error')) { + if ($group instanceof PEAR_Error) { continue; } $group_users = $group->listAllUsers(); - if (is_a($group_users, 'PEAR_Error')) { + if ($group_users instanceof PEAR_Error) { Horde::logMessage($group_users, __FILE__, __LINE__, PEAR_LOG_ERR); continue; } @@ -1943,20 +1943,18 @@ class Kronolith $mail->addHeader('User-Agent', 'Kronolith ' . $GLOBALS['registry']->getVersion()); $mime_mail->setBody($message, Horde_Nls::getCharset(), true); Horde::logMessage(sprintf('Sending event notifications for %s to %s', $event->title, implode(', ', $df_recipients)), __FILE__, __LINE__, PEAR_LOG_DEBUG); - try { - $mime_mail->send(Horde::getMailerConfig(), false, false); - } catch (Horde_Mime_Exception $e) {} + $mime_mail->send(Horde::getMailerConfig(), false, false); } } } - - return true; } /** * Check for resource declines and push notice to stack if found. * - * @param Kronolith_Event # + * @param Kronolith_Event $event + * + * @throws Kronolith_Exception */ public static function notifyOfResourceRejection($event) { @@ -2149,6 +2147,7 @@ class Kronolith * * @return Kronolith_Driver The newly created concrete Kronolith_Driver * instance, or a PEAR_Error on error. + * @throws Kronolith_Exception */ public static function getDriver($driver = null, $calendar = null) { @@ -2201,13 +2200,13 @@ class Kronolith case 'Holidays': if (empty($GLOBALS['conf']['holidays']['enable'])) { - return PEAR::raiseError(_("Holidays are disabled")); + throw new Kronolith_Exception(_("Holidays are disabled")); } $params['language'] = $GLOBALS['language']; break; default: - return PEAR::raiseError('No calendar driver specified'); + throw new Kronolith_Exception('No calendar driver specified'); break; } @@ -2271,39 +2270,43 @@ class Kronolith case 'EditEvent': case 'DeleteEvent': case 'ExportEvent': - if ($uid = Horde_Util::getFormData('uid')) { - $event = self::getDriver()->getByUID($uid); - } else { - $event = self::getDriver(Horde_Util::getFormData('type'), - Horde_Util::getFormData('calendar')) - ->getEvent(Horde_Util::getFormData('eventID'), - Horde_Util::getFormData('datetime')); + try { + if ($uid = Horde_Util::getFormData('uid')) { + $event = self::getDriver()->getByUID($uid); + } else { + $event = self::getDriver(Horde_Util::getFormData('type'), + Horde_Util::getFormData('calendar')) + ->getEvent(Horde_Util::getFormData('eventID'), + Horde_Util::getFormData('datetime')); + } + } catch (Horde_Exception $e) { + $event = $e->getMessage(); } switch ($view) { case 'Event': - if (!is_a($event, 'PEAR_Error') && + if (!is_string($event) && !$event->hasPermission(Horde_Perms::READ)) { - $event = PEAR::raiseError(_("Permission Denied")); + $event = _("Permission Denied"); } return new Kronolith_View_Event($event); case 'EditEvent': /* We check for read permissions, because we can always save a * copy if we can read the event. */ - if (!is_a($event, 'PEAR_Error') && + if (!is_string($event) && !$event->hasPermission(Horde_Perms::READ)) { - $event = PEAR::raiseError(_("Permission Denied")); + $event = _("Permission Denied"); } return new Kronolith_View_EditEvent($event); case 'DeleteEvent': - if (!is_a($event, 'PEAR_Error') && + if (!is_string($event) && !$event->hasPermission(Horde_Perms::DELETE)) { - $event = PEAR::raiseError(_("Permission Denied")); + $event = _("Permission Denied"); } return new Kronolith_View_DeleteEvent($event); case 'ExportEvent': - if (!is_a($event, 'PEAR_Error') && + if (!is_string($event) && !$event->hasPermission(Horde_Perms::READ)) { - $event = PEAR::raiseError(_("Permission Denied")); + $event = _("Permission Denied"); } return new Kronolith_View_ExportEvent($event); } @@ -2432,18 +2435,19 @@ class Kronolith if (empty(self::$_tagger)) { self::$_tagger = new Kronolith_Tagger(); } - return self::$_tagger; } public static function getGeoDriver() { - /* Get geolocation data */ if (!empty($GLOBALS['conf']['maps']['geodriver'])) { - return Kronolith_Geo::factory($GLOBALS['conf']['maps']['geodriver']); - } else { - return false; + try { + return Kronolith_Geo::factory($GLOBALS['conf']['maps']['geodriver']); + } catch (Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + } } + return false; } /** @@ -2452,7 +2456,8 @@ class Kronolith * * @param string $target The calendar id to retrieve. * - * @return mixed Kronolith_Resource or Horde_Share_Object + * @return Kronolith_Resource|Horde_Share_Object + * @throws Kronolith_Exception */ static public function getInternalCalendar($target) { diff --git a/kronolith/lib/LoginTasks/Task/PurgeEvents.php b/kronolith/lib/LoginTasks/Task/PurgeEvents.php index 34f36af4c..ec85c2b13 100644 --- a/kronolith/lib/LoginTasks/Task/PurgeEvents.php +++ b/kronolith/lib/LoginTasks/Task/PurgeEvents.php @@ -30,6 +30,8 @@ class Kronolith_LoginTasks_Task_PurgeEvents extends Horde_LoginTasks_Task * Purge old messages in the Trash folder. * * @return boolean Whether any messages were purged from the Trash folder. + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function execute() { @@ -39,12 +41,13 @@ class Kronolith_LoginTasks_Task_PurgeEvents extends Horde_LoginTasks_Task $del_time = new Horde_Date($_SERVER['REQUEST_TIME']); $del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep'); - /* Need to have Horde_Perms::DELETE on a calendar to delete events from it */ + /* Need to have Horde_Perms::DELETE on a calendar to delete events + * from it */ $calendars = Kronolith::listCalendars(false, Horde_Perms::DELETE); /* Start building an event object to use for the search */ $kronolith_driver = Kronolith::getDriver(); - $query = &$kronolith_driver->getEvent(); + $query = $kronolith_driver->getEvent(); $query->start = null; $query->end = $del_time; $query->status = null; @@ -59,11 +62,12 @@ class Kronolith_LoginTasks_Task_PurgeEvents extends Horde_LoginTasks_Task if ($event->calendar != $kronolith_driver->calendar) { $kronolith_driver->open($event->calendar); } - $results = $kronolith_driver->deleteEvent($event->id, true); - ++$count; - if (is_a($results, 'PEAR_Error')) { - Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR); - return $results; + try { + $results = $kronolith_driver->deleteEvent($event->id, true); + ++$count; + } catch (Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + throw $e; } } } diff --git a/kronolith/lib/Resource/Base.php b/kronolith/lib/Resource/Base.php index 67cd2c6a4..f6c6b0337 100644 --- a/kronolith/lib/Resource/Base.php +++ b/kronolith/lib/Resource/Base.php @@ -119,11 +119,13 @@ abstract class Kronolith_Resource_Base /** * Save resource to storage. + * + * @return Kronolith_Resource object + * @throws Kronolith_Exception */ public function save() { - $d = $this->getDriver(); - return $d->save($this); + return $this->getDriver()->save($this); } /** diff --git a/kronolith/lib/Resource/Group.php b/kronolith/lib/Resource/Group.php index 51e13661c..9f871436b 100644 --- a/kronolith/lib/Resource/Group.php +++ b/kronolith/lib/Resource/Group.php @@ -78,6 +78,7 @@ class Kronolith_Resource_Group extends Kronolith_Resource_Base * * * @return boolean + * @throws Kronolith_Exception */ public function isFree($event) { @@ -97,9 +98,6 @@ class Kronolith_Resource_Group extends Kronolith_Resource_Base $conflict = false; $resource = $this->_driver->getResource($resource_id); $busy = Kronolith::listEvents($start, $end, array($resource->get('calendar'))); - if ($busy instanceof PEAR_Error) { - throw new Horde_Exception($busy->getMessage()); - } /* No events at all during time period for requested event */ if (!count($busy)) { diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index 91d733207..2ac8f0402 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -21,6 +21,7 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * * * @return boolean + * @throws Kronolith_Exception */ public function isFree($event) { @@ -34,9 +35,6 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base /* Fetch events. */ $busy = Kronolith::listEvents($start, $end, array($this->get('calendar'))); - if ($busy instanceof PEAR_Error) { - throw new Horde_Exception($busy->getMessage()); - } /* No events at all during time period for requested event */ if (!count($busy)) { @@ -76,7 +74,7 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * * @param $event * - * @return void + * @throws Kronolith_Exception */ public function addEvent($event) { @@ -85,22 +83,16 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base /* Make sure it's not already attached. */ $uid = $event->uid; - $existing = $driver->getByUID($uid, array($this->get('calendar'))); - if (!($existing instanceof PEAR_Error)) { + try { + $existing = $driver->getByUID($uid, array($this->get('calendar'))); /* Already attached, just update */ $this->_copyEvent($event, $existing); $result = $existing->save(); - if (is_a($result, 'PEAR_Error')) { - throw new Kronolith_Exception($result->getMessage()); - } - } else { + } catch (Horde_Exception_NotFound $ex) { /* Create a new event */ $e = $driver->getEvent(); $this->_copyEvent($event, $e); $result = $e->save(); - if (is_a($result, 'PEAR_Error')) { - throw new Kronolith_Exception($result->getMessage()); - } } } @@ -108,17 +100,15 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * Remove this event from resource's calendar * * @param $event - * @return unknown_type + * + * @throws Kronolith_Exception + * @throws Horde_Exception_NotFound */ public function removeEvent($event) { $driver = Kronolith::getDriver('Resource', $this->get('calendar')); $re = $driver->getByUID($event->uid, array($this->get('calendar'))); - // Event will only be in the calendar if it's been accepted. This error - // should never happen, but put it here as a safeguard for now. - if (!($re instanceof PEAR_Error)) { - $driver->deleteEvent($re->id); - } + $driver->deleteEvent($re->id); } /** diff --git a/kronolith/lib/Storage.php b/kronolith/lib/Storage.php index e24548883..9d40fa868 100644 --- a/kronolith/lib/Storage.php +++ b/kronolith/lib/Storage.php @@ -1,38 +1,36 @@ * @package Kronolith */ -class Kronolith_Storage { - +abstract class Kronolith_Storage +{ /** * String containing the current username. * * @var string */ - var $_user = ''; + protected $_user = ''; /** - * Attempts to return a concrete Kronolith_Storage instance based on $driver. - * - * @param string $driver The type of concrete Kronolith_Storage subclass - * to return. The is based on the storage - * driver ($driver). The code is dynamically - * included. - * - * @param string $user The name of the user who owns the free/busy - * information + * Attempts to return a concrete Kronolith_Storage instance based on + * $driver. * - * @param array $params (optional) A hash containing any additional - * configuration or connection parameters a - * subclass might need. + * @param string $driver The type of concrete Kronolith_Storage subclass + * to return. The is based on the storage driver + * ($driver). The code is dynamically included. + * @param string $user The name of the user who owns the free/busy + * information. + * @param array $params A hash containing any additional configuration or + * connection parameters a subclass might need. * - * @return mixed The newly created concrete Kronolith_Storage instance, or - * false on an error. + * @return Kronolith_Storage The newly created concrete Kronolith_Storage + * instance. + * @throws Kronolith_Exception */ - function &factory($user = null, $driver = null, $params = null) + public static function factory($user = null, $driver = null, $params = null) { if (is_null($user)) { $user = Horde_Auth::getAuth(); @@ -52,12 +50,12 @@ class Kronolith_Storage { if (class_exists($class)) { $driver = new $class($user, $params); } else { - $driver = PEAR::raiseError(sprintf(_("Unable to load the definition of %s."), $class)); - return $driver; + throw new Kronolith_Exception(sprintf(_("Unable to load the definition of %s."), $class)); } - $result = $driver->initialize(); - if (is_a($result, 'PEAR_Error')) { + try { + $driver->initialize(); + } catch (Exception $e) { $driver = new Kronolith_Storage($params); } @@ -65,55 +63,8 @@ class Kronolith_Storage { } /** - * Attempts to return a reference to a concrete Kronolith_Storage instance - * based on $driver. It will only create a new instance if no - * Kronolith_Storage instance with the same parameters currently exists. - * - * This should be used if multiple storage sources are required. - * - * This method must be invoked as: $var = &Kronolith_Storage::singleton() - * - * @param string $driver The type of concrete Kronolith_Storage subclass - * to return. The is based on the storage - * driver ($driver). The code is dynamically - * included. - * - * @param string $user The name of the user who owns the free/busy - * information - * - * @param array $params (optional) A hash containing any additional - * configuration or connection parameters a - * subclass might need. - * - * @return mixed The created concrete Kronolith_Storage instance, or false - * on error. - */ - function &singleton($user = null, $driver = null, $params = null) - { - static $instances = array(); - - if (is_null($user)) { - $user = Horde_Auth::getAuth(); - } - - if (is_null($driver)) { - $driver = $GLOBALS['conf']['storage']['driver']; - } - - if (is_null($params)) { - $params = Horde::getDriverConfig('storage', $driver); - } - - $signature = serialize(array($user, $driver, $params)); - if (!isset($instances[$signature])) { - $instances[$signature] = &Kronolith_Storage::factory($user, $driver, $params); - } - - return $instances[$signature]; - } - - /** * Stub to initiate a driver. + * @throws Kronolith_Exception */ function initialize() { @@ -123,17 +74,10 @@ class Kronolith_Storage { /** * Stub to be overridden in the child class. */ - function search() - { - return PEAR::raiseError(_("Searching free/busy is not available.")); - } + abstract public function search($email, $private_only = false); /** * Stub to be overridden in the child class. */ - function store() - { - return PEAR::raiseError(_("Storing free/busy is not available.")); - } - + abstract public function store($email, $vfb, $public = false); } diff --git a/kronolith/lib/Storage/kolab.php b/kronolith/lib/Storage/kolab.php index c3b0c6f33..2aea3097e 100644 --- a/kronolith/lib/Storage/kolab.php +++ b/kronolith/lib/Storage/kolab.php @@ -1,8 +1,4 @@ * @package Kronolith */ -class Kronolith_Storage_kolab extends Kronolith_Storage { - - var $_params = array(); +class Kronolith_Storage_kolab extends Kronolith_Storage +{ + protected $_params = array(); - function Kronolith_Storage_kolab($user, $params = array()) + function __construct($user, $params = array()) { $this->_user = $user; $this->_params = $params; } - function search($email, $private_only = false) + /** + * @throws Kronolith_Exception + */ + public function search($email, $private_only = false) { global $conf; if (class_exists('Horde_Kolab_Session')) { - $session = &Horde_Kolab_Session::singleton(); + $session = Horde_Kolab_Session::singleton(); $server = $session->freebusy_server; - } else if (!is_callable('Kolab', 'getServer')) { - $server = sprintf('%s://%s:%d/freebusy/', - $conf['storage']['freebusy']['protocol'], - $conf['kolab']['imap']['server'], - $conf['storage']['freebusy']['port']); } else { $server = sprintf('%s://%s:%d/freebusy/', $conf['storage']['freebusy']['protocol'], @@ -52,12 +46,11 @@ class Kronolith_Storage_kolab extends Kronolith_Storage { $options = array_merge($options, $GLOBALS['conf']['http']['proxy']); } - require_once 'HTTP/Request.php'; $http = new HTTP_Request($fb_url, $options); $http->setBasicAuth(Horde_Auth::getAuth(), Horde_Auth::getCredential('password')); @$http->sendRequest(); if ($http->getResponseCode() != 200) { - return PEAR::raiseError(sprintf(_("Unable to retrieve free/busy information for %s"), + throw new Kronolith_Exception(sprintf(_("Unable to retrieve free/busy information for %s"), $email), Kronolith::ERROR_FB_NOT_FOUND); } $vfb_text = $http->getResponseBody(); @@ -67,18 +60,17 @@ class Kronolith_Storage_kolab extends Kronolith_Storage { $vfb = &$iCal->findComponent('VFREEBUSY'); if ($vfb === false) { - return PEAR::raiseError(sprintf(_("No free/busy information is available for %s"), + throw new Kronolith_Exception(sprintf(_("No free/busy information is available for %s"), $email), Kronolith::ERROR_FB_NOT_FOUND); } return $vfb; } - function store($email, $vfb, $public = false) + public function store($email, $vfb, $public = false) { // We don't care about storing FB info at the moment; we rather let // Kolab's freebusy.php script auto-generate it for us. - return true; } } diff --git a/kronolith/lib/Storage/sql.php b/kronolith/lib/Storage/sql.php index 6abd6b7df..adef297ad 100644 --- a/kronolith/lib/Storage/sql.php +++ b/kronolith/lib/Storage/sql.php @@ -1,19 +1,18 @@ * @package Kronolith */ -class Kronolith_Storage_sql extends Kronolith_Storage { - +class Kronolith_Storage_sql extends Kronolith_Storage +{ /** * Handle for the current database connection, used for reading. * * @var DB */ - var $_db; + protected $_db; /** * Handle for the current database connection, used for writing. Defaults @@ -21,21 +20,21 @@ class Kronolith_Storage_sql extends Kronolith_Storage { * * @var DB */ - var $_write_db; + protected $_write_db; /** * Hash containing connection parameters. * * @var array */ - var $_params = array(); + protected $_params = array(); /** * Constructs a new Kronolith_Storage SQL instance. * * @param array $params A hash containing connection parameters. */ - function Kronolith_Storage_sql($user, $params = array()) + public function __construct($user, $params = array()) { $this->_user = $user; @@ -47,9 +46,9 @@ class Kronolith_Storage_sql extends Kronolith_Storage { /** * Connect to the database * - * @return boolean True on success or PEAR_Error on failure. + * @throws Kronolith_Exception */ - function initialize() + public function initialize() { Horde::assertDriverConfig($this->_params, 'storage', array('phptype'), @@ -70,45 +69,39 @@ 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 (is_a($this->_write_db, 'PEAR_Error')) { - return PEAR::raiseError(_("Unable to connect to SQL server.")); + if ($this->_write_db instanceof PEAR_Error) { + throw new Kronolith_Exception($this->_write_db); } + $this->_initConn($this->_write_db); - // Set DB portability options. - switch ($this->_write_db->phptype) { - case 'mssql': - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection - * seperately. */ + /* Check if we need to set up the read DB connection seperately. */ if (!empty($this->_params['splitread'])) { $params = array_merge($this->_params, $this->_params['read']); $this->_db = &DB::connect($params, array('persistent' => !empty($params['persistent']), 'ssl' => !empty($params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { - return $this->_db; - } - - // Set DB portability options. - switch ($this->_db->phptype) { - case 'mssql': - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + if ($this->_db instanceof PEAR_Error) { + throw new Kronolith_Exception($this->_db); } - + $this->_initConn($this->_db); } else { /* Default to the same DB handle for the writer too. */ $this->_db =& $this->_write_db; } + } - return true; + /** + */ + private function _initConn(&$db) + { + // Set DB portability options. + switch ($db->phptype) { + case 'mssql': + $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); + break; + default: + $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); + } } /** @@ -120,8 +113,9 @@ class Kronolith_Storage_sql extends Kronolith_Storage { * * @return object Horde_iCalendar_vFreebusy on success * PEAR_Error on error or not found + * @throws Kronolith_Exception */ - function search($email, $private_only = false) + public function search($email, $private_only = false) { /* Build the SQL query. */ $query = sprintf('SELECT vfb_serialized FROM %s WHERE vfb_email=? AND (vfb_owner=?', @@ -141,7 +135,7 @@ class Kronolith_Storage_sql extends Kronolith_Storage { /* Execute the query. */ $result = $this->_db->query($query, $values); - if (!is_a($result, 'PEAR_Error')) { + if (!($result instanceof PEAR_Error)) { $row = $result->fetchRow(DB_GETMODE_ASSOC); $result->free(); if (is_array($row)) { @@ -151,7 +145,7 @@ class Kronolith_Storage_sql extends Kronolith_Storage { return $vfb; } } - return PEAR::raiseError(_("Not found"), Kronolith::ERROR_FB_NOT_FOUND); + throw new Kronolith_Exception(_("Not found"), Kronolith::ERROR_FB_NOT_FOUND); } /** @@ -161,17 +155,14 @@ class Kronolith_Storage_sql extends Kronolith_Storage { * @param Horde_iCalendar_vFreebusy $vfb TODO * @param boolean $private_only (optional) TODO * - * @return boolean True on success - * PEAR_Error on error or not found + * @throws Kronolith_Exception */ - function store($email, $vfb, $public = false) + public function store($email, $vfb, $public = false) { - $owner = (!$public) ? $this->_user : ''; - /* Build the SQL query. */ $query = sprintf('INSERT INTO %s (vfb_owner, vfb_email, vfb_serialized) VALUES (?, ?, ?)', $this->_params['table']); - $values = array($owner, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC)); + $values = array($public ? '' : $this->_user, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC)); /* Log the query at debug level. */ Horde::logMessage(sprintf('SQL insert by %s: query = "%s"', @@ -179,7 +170,10 @@ class Kronolith_Storage_sql extends Kronolith_Storage { __FILE__, __LINE__, PEAR_LOG_DEBUG); /* Execute the query. */ - return $this->_write_db->query($query, $values); + $result = $this->_write_db->query($query, $values); + if ($result instanceof PEAR_Error) { + throw new Kronolith_Exception($result); + } } } diff --git a/kronolith/lib/Tagger.php b/kronolith/lib/Tagger.php index a1ef0444f..d8f4eb9f1 100644 --- a/kronolith/lib/Tagger.php +++ b/kronolith/lib/Tagger.php @@ -197,7 +197,7 @@ class Kronolith_Tagger //TODO: Are there any cases where we can shortcut the postFilter? $results = array('calendar' => array(), - 'event' => $this->_postFilter($results, $filter['calendar'])); + 'event' => Kronolith::getDriver()->filterEventsByCalendar($results, $filter['calendar'])); } else { $args = array('tagId' => self::$_tagger->ensureTags($tags)); if (!empty($filter['userId'])) { @@ -224,20 +224,6 @@ class Kronolith_Tagger } /** - * Filter events in the $results array to return only those that are - * in $calendar. - * - * @param $results - * @param $calendar - * @return unknown_type - */ - protected function _postFilter($results, $calendar) - { - $driver = Kronolith::getDriver(); - return $driver->filterEventsByCalendar($results, $calendar); - } - - /** * List tags belonging to the current user beginning with $token. * Used for autocomplete code. * diff --git a/kronolith/lib/View/Day.php b/kronolith/lib/View/Day.php index cd3992325..427a88945 100644 --- a/kronolith/lib/View/Day.php +++ b/kronolith/lib/View/Day.php @@ -37,25 +37,22 @@ class Kronolith_View_Day extends Kronolith_Day { } if ($events === null) { - $events = Kronolith::listEvents( - $this, - new Horde_Date(array('year' => $this->year, - 'month' => $this->month, - 'mday' => $this->mday)), - $GLOBALS['display_calendars']); - if (is_a($events, 'PEAR_Error')) { - $this->_events = $events; - } else { - $this->_events = array_shift($events); + try { + $events = Kronolith::listEvents( + $this, + new Horde_Date(array('year' => $this->year, + 'month' => $this->month, + 'mday' => $this->mday)), + $GLOBALS['display_calendars']); + $this->_events = array_shift($events); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); + $this->_events = array(); } } else { $this->_events = $events; } - if (is_a($this->_events, 'PEAR_Error')) { - $GLOBALS['notification']->push($this->_events, 'horde.error'); - $this->_events = array(); - } if (!is_array($this->_events)) { $this->_events = array(); } diff --git a/kronolith/lib/View/DeleteEvent.php b/kronolith/lib/View/DeleteEvent.php index 086dfe5c0..de69fa6d9 100644 --- a/kronolith/lib/View/DeleteEvent.php +++ b/kronolith/lib/View/DeleteEvent.php @@ -11,18 +11,21 @@ class Kronolith_View_DeleteEvent { var $event; /** - * @param Kronolith_Event &$event + * @param Kronolith_Event $event */ - function Kronolith_View_DeleteEvent(&$event) + function Kronolith_View_DeleteEvent($event) { - $this->event =& $event; + $this->event = $event; } function getTitle() { - if (!$this->event || is_a($this->event, 'PEAR_Error')) { + if (!$this->event) { return _("Not Found"); } + if (is_string($this->event)) { + return $this->event; + } return sprintf(_("Delete %s"), $this->event->getTitle()); } @@ -33,9 +36,13 @@ class Kronolith_View_DeleteEvent { function html($active = true) { - if (!$this->event || is_a($this->event, 'PEAR_Error')) { - echo '

' . _("The requested event was not found.") . '

'; - return; + if (!$this->event) { + echo '

' . _("Event not found") . '

'; + exit; + } + if (is_string($this->event)) { + echo '

' . $this->event . '

'; + exit; } if ($datetime = Horde_Util::getFormData('datetime')) { diff --git a/kronolith/lib/View/EditEvent.php b/kronolith/lib/View/EditEvent.php index 73b1482f8..96e2056cb 100644 --- a/kronolith/lib/View/EditEvent.php +++ b/kronolith/lib/View/EditEvent.php @@ -11,18 +11,21 @@ class Kronolith_View_EditEvent { var $event; /** - * @param Kronolith_Event &$event + * @param Kronolith_Event $event */ - function Kronolith_View_EditEvent(&$event) + function Kronolith_View_EditEvent($event) { - $this->event = &$event; + $this->event = $event; } function getTitle() { - if (!$this->event || is_a($this->event, 'PEAR_Error')) { + if (!$this->event) { return _("Not Found"); } + if (is_string($this->event)) { + return $this->event; + } return sprintf(_("Edit %s"), $this->event->getTitle()); } @@ -33,21 +36,27 @@ class Kronolith_View_EditEvent { function html($active = true) { - $identity = Horde_Prefs_Identity::singleton(); - - if (!$this->event || is_a($this->event, 'PEAR_Error')) { - echo '

' . _("The requested event was not found.") . '

'; - return; + if (!$this->event) { + echo '

' . _("Event not found") . '

'; + exit; + } + if (is_string($this->event)) { + echo '

' . $this->event . '

'; + exit; } + $identity = Horde_Prefs_Identity::singleton(); + if ($this->event->hasPermission(Horde_Perms::EDIT)) { $calendar_id = $this->event->calendar; } else { $calendar_id = Kronolith::getDefaultCalendar(Horde_Perms::EDIT); } - if (!$this->event->hasPermission(Horde_Perms::EDIT) && - !is_a($share = &$this->event->getShare(), 'PEAR_Error')) { - $calendar_id .= ':' . $share->get('owner'); + if (!$this->event->hasPermission(Horde_Perms::EDIT)) { + try { + $calendar_id .= ':' . $this->event->getShare()->get('owner'); + } catch (Exception $e) { + } } $_SESSION['kronolith']['attendees'] = $this->event->attendees; $_SESSION['kronolith']['resources'] = $this->event->getResources(); diff --git a/kronolith/lib/View/Event.php b/kronolith/lib/View/Event.php index a4ef6144c..6d4421be8 100644 --- a/kronolith/lib/View/Event.php +++ b/kronolith/lib/View/Event.php @@ -10,18 +10,21 @@ class Kronolith_View_Event { var $event; /** - * @param Kronolith_Event &$event + * @param Kronolith_Event $event */ - function Kronolith_View_Event(&$event) + function Kronolith_View_Event($event) { - $this->event = &$event; + $this->event = $event; } function getTitle() { - if (!$this->event || is_a($this->event, 'PEAR_Error')) { + if (!$this->event) { return _("Not Found"); } + if (is_string($this->event)) { + return $this->event; + } return $this->event->getTitle(); } @@ -32,12 +35,16 @@ class Kronolith_View_Event { function html($active = true) { - global $conf, $prefs; - - if (!$this->event || is_a($this->event, 'PEAR_Error')) { - echo '

' . _("The requested event was not found.") . '

'; - return; + if (!$this->event) { + echo '

' . _("Event not found") . '

'; + exit; } + if (is_string($this->event)) { + echo '

' . $this->event . '

'; + exit; + } + + global $conf, $prefs; $createdby = ''; $modifiedby = ''; diff --git a/kronolith/lib/View/ExportEvent.php b/kronolith/lib/View/ExportEvent.php index 6176e3d01..b815d0af7 100644 --- a/kronolith/lib/View/ExportEvent.php +++ b/kronolith/lib/View/ExportEvent.php @@ -9,29 +9,34 @@ class Kronolith_View_ExportEvent { /** - * @param Kronolith_Event &$event + * @param Kronolith_Event $event */ - function Kronolith_View_ExportEvent(&$event) + function Kronolith_View_ExportEvent($event) { - if (!$event || $event instanceof PEAR_Error) { + if (!$event) { echo '

' . _("Event not found") . '

'; exit; } + if (is_string($event)) { + echo '

' . $event . '

'; + exit; + } $iCal = new Horde_iCalendar('2.0'); if ($event->calendarType == 'internal') { - $share = &$GLOBALS['kronolith_shares']->getShare($event->calendar); - if (!is_a($share, 'PEAR_Error')) { + try { + $share = $GLOBALS['kronolith_shares']->getShare($event->calendar); $iCal->setAttribute( 'X-WR-CALNAME', Horde_String::convertCharset($share->get('name'), Horde_Nls::getCharset(), 'utf-8')); + } catch (Exception $e) { } } - $vEvent = &$event->toiCalendar($iCal); + $vEvent = $event->toiCalendar($iCal); $iCal->addComponent($vEvent); $content = $iCal->exportvCalendar(); diff --git a/kronolith/lib/View/Month.php b/kronolith/lib/View/Month.php index 220d1c37d..95e2762b7 100644 --- a/kronolith/lib/View/Month.php +++ b/kronolith/lib/View/Month.php @@ -101,9 +101,10 @@ class Kronolith_View_Month { $this->_currentCalendars = array(true); } - $this->_events = Kronolith::listEvents($startDate, $endDate); - if (is_a($this->_events, 'PEAR_Error')) { - $GLOBALS['notification']->push($this->_events, 'horde.error'); + try { + $this->_events = Kronolith::listEvents($startDate, $endDate); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); $this->_events = array(); } if (!is_array($this->_events)) { diff --git a/kronolith/lib/View/Week.php b/kronolith/lib/View/Week.php index b76e68959..1aef1c378 100644 --- a/kronolith/lib/View/Week.php +++ b/kronolith/lib/View/Week.php @@ -69,9 +69,10 @@ class Kronolith_View_Week { $day->mday++; } $endDate = new Horde_Date($day); - $allevents = Kronolith::listEvents($this->startDate, $endDate); - if (is_a($allevents, 'PEAR_Error')) { - $GLOBALS['notification']->push($allevents, 'horde.error'); + try { + $allevents = Kronolith::listEvents($this->startDate, $endDate); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); $allevents = array(); } for ($i = $this->startDay; $i <= $this->endDay; ++$i) { diff --git a/kronolith/lib/View/Year.php b/kronolith/lib/View/Year.php index c436b39d0..a35e4cf47 100644 --- a/kronolith/lib/View/Year.php +++ b/kronolith/lib/View/Year.php @@ -21,9 +21,10 @@ class Kronolith_View_Year { 'month' => 12, 'mday' => 31)); - $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); - if (is_a($this->_events, 'PEAR_Error')) { - $GLOBALS['notification']->push($this->_events, 'horde.error'); + try { + $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['display_calendars']); + } catch (Exception $e) { + $GLOBALS['notification']->push($e, 'horde.error'); $this->_events = array(); } if (!is_array($this->_events)) { diff --git a/kronolith/lib/tests/bug6031.phpt b/kronolith/lib/tests/bug6031.phpt index 031fa1a57..3e8369a73 100644 --- a/kronolith/lib/tests/bug6031.phpt +++ b/kronolith/lib/tests/bug6031.phpt @@ -65,11 +65,7 @@ $end = new Horde_Date(172800); // List the events of tomorrow (none, since recurrence has exception) $a = $kron->listEvents($start, $end); -if (is_a($a, 'PEAR_Error')) { - var_dump($a->getMessage()); -} else { - var_dump($a); -} +var_dump($a); $start = new Horde_Date(259200); $end = new Horde_Date(345600); diff --git a/kronolith/perms.php b/kronolith/perms.php index 1805a265c..3212fea04 100644 --- a/kronolith/perms.php +++ b/kronolith/perms.php @@ -27,27 +27,27 @@ $reload = false; $actionID = Horde_Util::getFormData('actionID', 'edit'); switch ($actionID) { case 'edit': - $share = &$shares->getShareById(Horde_Util::getFormData('cid')); + $share = $shares->getShareById(Horde_Util::getFormData('cid')); if (!is_a($share, 'PEAR_Error')) { - $perm = &$share->getPermission(); + $perm = $share->getPermission(); } elseif (($category = Horde_Util::getFormData('share')) !== null) { - $share = &$shares->getShare($category); - if (!is_a($share, 'PEAR_Error')) { - $perm = &$share->getPermission(); + try { + $share = $shares->getShare($category); + $perm = $share->getPermission(); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } } - if (is_a($share, 'PEAR_Error')) { - $notification->push($share, 'horde.error'); - } elseif (!Horde_Auth::getAuth() || - (isset($share) && - !Horde_Auth::isAdmin() && - Horde_Auth::getAuth() != $share->get('owner'))) { + if (!Horde_Auth::getAuth() || + (isset($share) && + !Horde_Auth::isAdmin() && + Horde_Auth::getAuth() != $share->get('owner'))) { exit('permission denied'); } break; case 'editform': - $share = &$shares->getShareById(Horde_Util::getFormData('cid')); + $share = $shares->getShareById(Horde_Util::getFormData('cid')); if (is_a($share, 'PEAR_Error')) { $notification->push(_("Attempt to edit a non-existent share."), 'horde.error'); } else { @@ -56,7 +56,7 @@ case 'editform': Horde_Auth::getAuth() != $share->get('owner'))) { exit('permission denied'); } - $perm = &$share->getPermission(); + $perm = $share->getPermission(); // Process owner and owner permissions. $old_owner = $share->get('owner'); diff --git a/kronolith/resources/create.php b/kronolith/resources/create.php index fa7df5cf2..4067c552e 100644 --- a/kronolith/resources/create.php +++ b/kronolith/resources/create.php @@ -24,11 +24,11 @@ $form = new Kronolith_CreateResourceForm($vars); // Execute if the form is valid. if ($form->validate($vars)) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } else { + try { + $result = $form->execute(); $notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } header('Location: ' . Horde::applicationUrl('resources/', true)); diff --git a/kronolith/resources/delete.php b/kronolith/resources/delete.php index cc172d6e5..c2015c3f7 100644 --- a/kronolith/resources/delete.php +++ b/kronolith/resources/delete.php @@ -20,15 +20,15 @@ if (!Horde_Auth::isAdmin()) { } $vars = Horde_Variables::getDefaultVariables(); -$d = Kronolith::getDriver('Resource'); -$resource = $d->getResource($vars->get('c')); - -if ($resource instanceof PEAR_Error) { - $notification->push($resoruce, 'horde.error'); - header('Location: ' . Horde::applicationUrl('resources/', true)); - exit; -} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { - $notification->push(_("You are not allowed to delete this resource."), 'horde.error'); +try { + $resource = Kronolith::getDriver('Resource')->getResource($vars->get('c')); + if (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { + $notification->push(_("You are not allowed to delete this resource."), 'horde.error'); + header('Location: ' . Horde::applicationUrl('resources/', true)); + exit; + } +} catch (Exception $e) { + $notification->push($e, 'horde.error'); header('Location: ' . Horde::applicationUrl('resources/', true)); exit; } @@ -37,11 +37,11 @@ $form = new Kronolith_DeleteResourceForm($vars, $resource); // Execute if the form is valid (must pass with POST variables only). if ($form->validate(new Horde_Variables($_POST))) { - $result = $form->execute(); - if ($result instanceof PEAR_Error) { - $notification->push($result, 'horde.error'); - } elseif ($result) { + try { + $result = $form->execute(); $notification->push(sprintf(_("The resource \"%s\" has been deleted."), $resource->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } header('Location: ' . Horde::applicationUrl('resources/', true)); diff --git a/kronolith/resources/edit.php b/kronolith/resources/edit.php index 6babaf164..60bd7f6ae 100644 --- a/kronolith/resources/edit.php +++ b/kronolith/resources/edit.php @@ -20,15 +20,15 @@ if (!Horde_Auth::isAdmin()) { } $vars = Horde_Variables::getDefaultVariables(); -$d = Kronolith::getDriver('Resource'); -$resource = $d->getResource($vars->get('c')); - -if ($resource instanceof PEAR_Error) { - $notification->push($resource, 'horde.error'); - header('Location: ' . Horde::applicationUrl('resources/', true)); - exit; -} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { - $notification->push(_("You are not allowed to change this resource."), 'horde.error'); +try { + $resource = Kronolith::getDriver('Resource')->getResource($vars->get('c')); + if (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + $notification->push(_("You are not allowed to change this resource."), 'horde.error'); + header('Location: ' . Horde::applicationUrl('resources/', true)); + exit; + } +} catch (Exception $e) { + $notification->push($e, 'horde.error'); header('Location: ' . Horde::applicationUrl('resources/', true)); exit; } @@ -37,15 +37,15 @@ $form = new Kronolith_EditResourceForm($vars, $resource); // Execute if the form is valid. if ($form->validate($vars)) { $original_name = $resource->get('name'); - $result = $form->execute(); - if ($result instanceof PEAR_Error) { - $notification->push($result, 'horde.error'); - } else { + try { + $result = $form->execute(); if ($result->get('name') != $original_name) { $notification->push(sprintf(_("The resource \"%s\" has been renamed to \"%s\"."), $original_name, $resource->get('name')), 'horde.success'); } else { $notification->push(sprintf(_("The resource \"%s\" has been saved."), $original_name), 'horde.success'); } + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } header('Location: ' . Horde::applicationUrl('resources/', true)); diff --git a/kronolith/resources/groups/create.php b/kronolith/resources/groups/create.php index 4c9f8cfe7..063fe23e6 100644 --- a/kronolith/resources/groups/create.php +++ b/kronolith/resources/groups/create.php @@ -24,11 +24,11 @@ $form = new Kronolith_CreateResourceGroupForm($vars); // Execute if the form is valid. if ($form->validate($vars)) { - $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result, 'horde.error'); - } else { + try { + $result = $form->execute(); $notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } header('Location: ' . Horde::applicationUrl('resources/groups/', true)); diff --git a/kronolith/resources/groups/delete.php b/kronolith/resources/groups/delete.php index 71730201e..d2e3f6d50 100644 --- a/kronolith/resources/groups/delete.php +++ b/kronolith/resources/groups/delete.php @@ -20,15 +20,15 @@ if (!Horde_Auth::isAdmin()) { } $vars = Horde_Variables::getDefaultVariables(); -$d = Kronolith::getDriver('Resource'); -$resource = $d->getResource($vars->get('c')); - -if ($resource instanceof PEAR_Error) { - $notification->push($resoruce, 'horde.error'); - header('Location: ' . Horde::applicationUrl('resources/groups/', true)); - exit; -} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { - $notification->push(_("You are not allowed to delete this resource group."), 'horde.error'); +try { + $resource = Kronolith::getDriver('Resource')->getResource($vars->get('c')); + if (!$resource->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { + $notification->push(_("You are not allowed to delete this resource group."), 'horde.error'); + header('Location: ' . Horde::applicationUrl('resources/groups/', true)); + exit; + } +} catch (Exception $e) { + $notification->push($e, 'horde.error'); header('Location: ' . Horde::applicationUrl('resources/groups/', true)); exit; } @@ -37,11 +37,11 @@ $form = new Kronolith_DeleteResourceGroupForm($vars, $resource); // Execute if the form is valid (must pass with POST variables only). if ($form->validate(new Horde_Variables($_POST))) { - $result = $form->execute(); - if ($result instanceof PEAR_Error) { - $notification->push($result, 'horde.error'); - } elseif ($result) { + try { + $result = $form->execute(); $notification->push(sprintf(_("The resource group \"%s\" has been deleted."), $resource->get('name')), 'horde.success'); + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } header('Location: ' . Horde::applicationUrl('resources/groups/', true)); diff --git a/kronolith/resources/groups/edit.php b/kronolith/resources/groups/edit.php index 6aab3a815..161164f90 100644 --- a/kronolith/resources/groups/edit.php +++ b/kronolith/resources/groups/edit.php @@ -20,15 +20,15 @@ if (!Horde_Auth::isAdmin()) { } $vars = Horde_Variables::getDefaultVariables(); -$d = Kronolith::getDriver('Resource'); -$group = $d->getResource($vars->get('c')); - -if ($group instanceof PEAR_Error) { - $notification->push($group, 'horde.error'); - header('Location: ' . Horde::applicationUrl('resources/groups/', true)); - exit; -} elseif (!$group->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { - $notification->push(_("You are not allowed to change this resource."), 'horde.error'); +try { + $group = Kronolith::getDriver('Resource')->getResource($vars->get('c')); + if (!$group->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + $notification->push(_("You are not allowed to change this resource."), 'horde.error'); + header('Location: ' . Horde::applicationUrl('resources/groups/', true)); + exit; + } +} catch (Exception $e) { + $notification->push($e, 'horde.error'); header('Location: ' . Horde::applicationUrl('resources/groups/', true)); exit; } @@ -37,15 +37,15 @@ $form = new Kronolith_EditResourceGroupForm($vars, $group); // Execute if the form is valid. if ($form->validate($vars)) { $original_name = $group->get('name'); - $result = $form->execute(); - if ($result instanceof PEAR_Error) { - $notification->push($result, 'horde.error'); - } else { + try { + $result = $form->execute(); if ($result->get('name') != $original_name) { $notification->push(sprintf(_("The resource group \"%s\" has been renamed to \"%s\"."), $original_name, $group->get('name')), 'horde.success'); } else { $notification->push(sprintf(_("The resource group \"%s\" has been saved."), $original_name), 'horde.success'); } + } catch (Exception $e) { + $notification->push($e, 'horde.error'); } header('Location: ' . Horde::applicationUrl('resources/groups/', true)); diff --git a/kronolith/scripts/agenda.php b/kronolith/scripts/agenda.php index 2eaf1e0b5..2dfd053f6 100755 --- a/kronolith/scripts/agenda.php +++ b/kronolith/scripts/agenda.php @@ -40,8 +40,9 @@ function send_agendas() // potentially have an agenda preference set. $users = array(); foreach (array_keys($calendars) as $calendarId) { - $calendar = $GLOBALS['shares']->getShare($calendarId); - if (is_a($calendar, 'PEAR_Error')) { + try { + $calendar = $GLOBALS['shares']->getShare($calendarId); + } catch (Exception $e) { continue; } $users = array_merge($users, $calendar->listUsers(Horde_Perms::READ)); diff --git a/kronolith/scripts/import_squirrelmail_calendar.php b/kronolith/scripts/import_squirrelmail_calendar.php index d36a9857c..adace664a 100755 --- a/kronolith/scripts/import_squirrelmail_calendar.php +++ b/kronolith/scripts/import_squirrelmail_calendar.php @@ -120,11 +120,12 @@ while ($row = $handle->fetchRow(DB_FETCHMODE_ASSOC)) { } // Save event. - $event = &$kronolith_driver->getEvent(); + $event = $kronolith_driver->getEvent(); $event->fromiCalendar($components[0]); - $result = $event->save(); - if (is_a($result, 'PEAR_Error')) { - $cli->message(' ' . $result->getMessage(), 'cli.error'); + try { + $event->save(); + } catch (Exception $e) { + $cli->message(' ' . $e->getMessage(), 'cli.error'); continue; } $count++;