Horde_Alarm now throws exceptions
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Feb 2010 20:46:04 +0000 (13:46 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Feb 2010 21:52:38 +0000 (14:52 -0700)
horde/admin/alarms.php
horde/services/snooze.php

index 76aef3c..8c06cfc 100644 (file)
@@ -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 '<h1 class="header">' . _("Current Alarms");
-if (is_a($alarms, 'PEAR_Error')) {
+if ($alarms instanceof Exception) {
     echo '</h1><p class="headerbox"><em>' . sprintf(_("Listing alarms failed: %s"), $alarms->getMessage()) . '</em></p>';
 } else {
     echo ' (' . count($alarms) . ')</h1>';
index 1471629..ac4025c 100644 (file)
@@ -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');