From: Michael J. Rubinsky Date: Mon, 5 Jul 2010 17:59:53 +0000 (-0400) Subject: Horde_Share throws exceptions X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dd901625c8f3574de37747664f578f9399fcebc6;p=horde.git Horde_Share throws exceptions --- diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index 3c726783b..d2bf3465a 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -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); + } } /** diff --git a/nag/tasklists/create.php b/nag/tasklists/create.php index 7271587b1..b7d3aabf9 100644 --- a/nag/tasklists/create.php +++ b/nag/tasklists/create.php @@ -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)); diff --git a/nag/tasklists/delete.php b/nag/tasklists/delete.php index 89b9d62a9..28f24eae3 100644 --- a/nag/tasklists/delete.php +++ b/nag/tasklists/delete.php @@ -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)); diff --git a/nag/tasklists/edit.php b/nag/tasklists/edit.php index 31a8b4000..a49c8c157 100644 --- a/nag/tasklists/edit.php +++ b/nag/tasklists/edit.php @@ -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));