From: Michael M Slusarz Date: Mon, 15 Feb 2010 20:46:04 +0000 (-0700) Subject: Horde_Alarm now throws exceptions X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7b6d7f6c40c48d40b141c94a3afa57d745ebd862;p=horde.git Horde_Alarm now throws exceptions --- diff --git a/horde/admin/alarms.php b/horde/admin/alarms.php index 76aef3cc4..8c06cfcd4 100644 --- a/horde/admin/alarms.php +++ b/horde/admin/alarms.php @@ -61,37 +61,35 @@ if ($form->validate()) { $params['notify']['sound'] = $registry->get('themesuri', 'horde') . '/sounds/' . $params['notify']['sound']; } - $result = $horde_alarm->set( - array('id' => $info['alarm'], - 'title' => $info['title'], - 'text' => $info['text'], - 'start' => new Horde_Date($info['start']), - 'end' => empty($info['end']) ? null : new Horde_Date($info['end']), - 'methods' => $info['methods'], - 'params' => $params)); - if (is_a($result, 'PEAR_Error')) { - $notification->push($result); - } else { + try { + $horde_alarm->set(array( + 'id' => $info['alarm'], + 'title' => $info['title'], + 'text' => $info['text'], + 'start' => new Horde_Date($info['start']), + 'end' => empty($info['end']) ? null : new Horde_Date($info['end']), + 'methods' => $info['methods'], + 'params' => $params + )); $notification->push(_("The alarm has been saved."), 'horde.success'); + } catch (Horde_Alarm_Exception $e) { + $notification->push($e); } } $id = $vars->get('alarm'); if ($id) { if ($vars->get('delete')) { - $deleted = $horde_alarm->delete($id, ''); - if (is_a($deleted, 'PEAR_Error')) { - $notification->push($deleted); - $id = null; - } else { + try { + $horde_alarm->delete($id, ''); $notification->push(_("The alarm has been deleted."), 'horde.success'); + } catch (Horde_Alarm_Exception $e) { + $notification->push($e); + $id = null; } } else { - $alarm = $horde_alarm->get($id, ''); - if (is_a($alarm, 'PEAR_Error')) { - $notification->push($alarm); - $id = $alarm = null; - } else { + try { + $alarm = $horde_alarm->get($id, ''); $form->setTitle(sprintf(_("Edit \"%s\""), $alarm['title'])); $vars->set('title', $alarm['title']); $vars->set('text', $alarm['text']); @@ -105,18 +103,25 @@ if ($id) { $vars->set($method . '_' . $name, $value); } } + } catch (Horde_Alarm_Exception $e) { + $notification->push($alarm); + $id = $alarm = null; } } } -$alarms = $horde_alarm->listAlarms(''); +try { + $alarms = $horde_alarm->listAlarms(''); +} catch (Horde_Alarm_Exception $e) { + $alarms = $e; +} $title = _("Alarms"); require HORDE_TEMPLATES . '/common-header.inc'; require HORDE_TEMPLATES . '/admin/menu.inc'; echo '

' . _("Current Alarms"); -if (is_a($alarms, 'PEAR_Error')) { +if ($alarms instanceof Exception) { echo '

' . sprintf(_("Listing alarms failed: %s"), $alarms->getMessage()) . '

'; } else { echo ' (' . count($alarms) . ')'; diff --git a/horde/services/snooze.php b/horde/services/snooze.php index 147162961..ac4025c07 100644 --- a/horde/services/snooze.php +++ b/horde/services/snooze.php @@ -16,8 +16,10 @@ $id = Horde_Util::getPost('alarm'); $snooze = Horde_Util::getPost('snooze'); if ($id && $snooze) { - if (is_a($result = $alarm->snooze($id, Horde_Auth::getAuth(), (int)$snooze), 'PEAR_Error')) { - header('HTTP/1.0 500 ' . $result->getMessage()); + try { + $alarm->snooze($id, Horde_Auth::getAuth(), (int)$snooze); + } catch (Horde_Alarm_Exception $e) { + header('HTTP/1.0 500 ' . $e->getMessage()); } } else { header('HTTP/1.0 400 Bad Request');