Horde_Share throws exceptions
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 5 Jul 2010 17:59:53 +0000 (13:59 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 5 Jul 2010 17:59:53 +0000 (13:59 -0400)
nag/lib/Nag.php
nag/tasklists/create.php
nag/tasklists/delete.php
nag/tasklists/edit.php

index 3c72678..d2bf346 100644 (file)
@@ -469,22 +469,28 @@ class Nag
      *
      * @param Horde_Share $share  The share to update.
      * @param array $info         Hash with task list information.
+     *
+     * @throws Horde_Exception_PermissionDenied
+     * @throws Nag_Exception
      */
-    public static function updateTasklist(&$tasklist, $info)
+    public static function updateTasklist($tasklist, $info)
     {
         if (!$GLOBALS['registry']->getAuth() ||
             ($tasklist->get('owner') != $GLOBALS['registry']->getAuth() &&
              (!is_null($tasklist->get('owner')) || !$GLOBALS['registry']->isAdmin()))) {
-            return PEAR::raiseError(_("You are not allowed to change this task list."));
+
+            throw new Horde_Exception_PermissionDenied(_("You are not allowed to change this task list."));
         }
 
         $tasklist->set('name', $info['name']);
         $tasklist->set('color', $info['color']);
         $tasklist->set('desc', $info['description']);
         $tasklist->set('owner', empty($info['system']) ? $GLOBALS['registry']->getAuth() : null);
-        $result = $tasklist->save();
-        if (is_a($result, 'PEAR_Error')) {
-            return PEAR::raiseError(sprintf(_("Unable to save task list \"%s\": %s"), $info['name'], $result->getMessage()));
+
+        try {
+            $tasklist->save();
+        } catch (Horde_Share_Exception $e) {
+            throw new Nag_Exception(sprintf(_("Unable to save task list \"%s\": %s"), $info['name'], $e->getMessage()));
         }
     }
 
@@ -496,24 +502,28 @@ class Nag
     public static function deleteTasklist($tasklist)
     {
         if ($tasklist->getName() == $GLOBALS['registry']->getAuth()) {
-            return PEAR::raiseError(_("This task list cannot be deleted."));
+            throw new Horde_Exception_PermissionDenied(_("This task list cannot be deleted."));
         }
 
         if (!$GLOBALS['registry']->getAuth() ||
             ($tasklist->get('owner') != $GLOBALS['registry']->getAuth() &&
              (!is_null($tasklist->get('owner')) || !$GLOBALS['registry']->isAdmin()))) {
-            return PEAR::raiseError(_("You are not allowed to delete this task list."));
+            throw new Horde_Exception_PermissionDenied(_("You are not allowed to delete this task list."));
         }
 
         // Delete the task list.
         $storage = &Nag_Driver::singleton($tasklist->getName());
         $result = $storage->deleteAll();
         if ($result instanceof PEAR_Error) {
-            return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $tasklist->get('name'), $result->getMessage()));
+            throw new Nag_Exception(sprintf(_("Unable to delete \"%s\": %s"), $tasklist->get('name'), $result->getMessage()));
         }
 
         // Remove share and all groups/permissions.
-        return $GLOBALS['nag_shares']->removeShare($tasklist);
+        try {
+            return $GLOBALS['nag_shares']->removeShare($tasklist);
+        } catch (Horde_Share_Exception $e) {
+            throw new Nag_Exception($e);
+        }
     }
 
     /**
index 7271587..b7d3aab 100644 (file)
@@ -23,11 +23,11 @@ $form = new Nag_CreateTaskListForm($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 task list \"%s\" has been created."), $vars->get('name')), 'horde.success');
+    } catch (Exception $e) {
+        $notification->push($e, 'horde.error');
     }
 
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
index 89b9d62..28f24ea 100644 (file)
@@ -42,11 +42,11 @@ $form = new Nag_DeleteTaskListForm($vars, $tasklist);
 
 // 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 task list \"%s\" has been deleted."), $tasklist->get('name')), 'horde.success');
+    } catch (Exception $e) {
+        $notification->push($e, 'horde.error');
     }
 
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
index 31a8b40..a49c8c1 100644 (file)
@@ -36,15 +36,15 @@ $form = new Nag_EditTaskListForm($vars, $tasklist);
 // Execute if the form is valid.
 if ($form->validate($vars)) {
     $original_name = $tasklist->get('name');
-    $result = $form->execute();
-    if ($result instanceof PEAR_Error) {
-        $notification->push($result, 'horde.error');
-    } else {
+    try {
+        $result = $form->execute();
         if ($tasklist->get('name') != $original_name) {
             $notification->push(sprintf(_("The task list \"%s\" has been renamed to \"%s\"."), $original_name, $tasklist->get('name')), 'horde.success');
         } else {
             $notification->push(sprintf(_("The task list \"%s\" has been saved."), $original_name), 'horde.success');
         }
+    } catch (Exception $e) {
+        $notification->push($e, 'horde.error');
     }
 
     header('Location: ' . Horde::applicationUrl('tasklists/', true));