Track Horde_Share changes
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 03:39:05 +0000 (23:39 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 03:39:05 +0000 (23:39 -0400)
17 files changed:
nag/lib/Api.php
nag/lib/Application.php
nag/lib/Block/summary.php
nag/lib/Driver.php
nag/lib/Driver/Kolab.php
nag/lib/Exception.php [new file with mode: 0644]
nag/lib/Forms/task.php
nag/lib/Nag.php
nag/lib/Task.php
nag/task.php
nag/tasklists/delete.php
nag/tasklists/edit.php
nag/tasklists/info.php
nag/templates/list.html.php
nag/templates/list/task_summaries.inc
nag/templates/view/task.inc
nag/view.php

index fc6fbf6..aa3eee7 100644 (file)
@@ -132,10 +132,13 @@ class Nag_Api extends Horde_Registry_Api
      */
     public static function updateTasklist($id, $info)
     {
-        $tasklist = $GLOBALS['nag_shares']->getShare($id);
-        if (is_a($tasklist, 'PEAR_Error')) {
-            return $tasklist;
+        try {
+            $tasklist = $GLOBALS['nag_shares']->getShare($id);
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+            throw new Nag_Exception($e);
         }
+
         return Nag::updateTasklist($tasklist, $info);
     }
 
@@ -622,10 +625,10 @@ class Nag_Api extends Horde_Registry_Api
             } else {
                 // Remove share and all groups/permissions.
                 $share = $GLOBALS['nag_shares']->getShare($tasklistID);
-                $result = $GLOBALS['nag_shares']->removeShare($share);
-                if (is_a($result, 'PEAR_Error')) {
-                    $result->code = 500;
-                    return $result;
+                try {
+                    $GLOBALS['nag_shares']->removeShare($share);
+                } catch (Horde_Share_Exception $e) {
+                    throw new Nag_Exception($e->getMessage());
                 }
             }
         }
@@ -934,13 +937,14 @@ class Nag_Api extends Horde_Registry_Api
                 return PEAR::raiseError(_("Permission Denied"));
             }
 
-        $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
-        if (is_a($share, 'PEAR_Error')) {
-            return $share;
+        try {
+            $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+            throw new Nag_Exception($e);
         }
-
         $task = Nag::getTask($tasklist_id, $task_id);
-        if (is_a($task, 'PEAR_Error')) {
+        if ($task instanceof PEAR_Error) {
             return $task;
         }
 
@@ -1378,13 +1382,14 @@ class Nag_Api extends Horde_Registry_Api
         $tasklists = is_null($user) ? array_keys($GLOBALS['nag_shares']->listAllShares()) :  $GLOBALS['display_tasklists'];
 
         $alarms = Nag::listAlarms($time, $tasklists);
-        if (is_a($alarms, 'PEAR_Error')) {
+        if (is_a($alarms instanceof PEAR_Error) {
             return $alarms;
         }
 
         foreach ($alarms as $alarm) {
-            $share = $GLOBALS['nag_shares']->getShare($alarm->tasklist);
-            if (is_a($share, 'PEAR_Error')) {
+            try {
+                $share = $GLOBALS['nag_shares']->getShare($alarm->tasklist);
+            } catch (Horde_Share_Exception $e) {
                 continue;
             }
             if (empty($user)) {
index 657a287..aed9603 100644 (file)
@@ -242,48 +242,51 @@ class Nag_Application extends Horde_Registry_Application
         $hasError = false;
 
         /* Get the share for later deletion */
-        $share = $GLOBALS['nag_shares']->getShare($user);
-        if(is_a($share, 'PEAR_Error')) {
+        try {
+            $share = $GLOBALS['nag_shares']->getShare($user);
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+        }
+
+        /* Get the list of all tasks */
+        $tasks = Nag::listTasks(null, null, null, $user, 1);
+        if ($tasks instanceof PEAR_Error) {
+            $hasError = true;
             Horde::logMessage($share, 'ERR');
-            unset($share);
         } else {
-            /* Get the list of all tasks */
-            $tasks = Nag::listTasks(null, null, null, $user, 1);
-            if (is_a($tasks, 'PEAR_Error')) {
-                $hasError = true;
-                Horde::logMessage($share, 'ERR');
-            } else {
-                $uids = array();
-                $tasks->reset();
-                while ($task = $tasks->each()) {
-                    $uids[] = $task->uid;
-                }
+            $uids = array();
+            $tasks->reset();
+            while ($task = $tasks->each()) {
+                $uids[] = $task->uid;
+            }
 
-                /* ... and delete them. */
-                foreach ($uids as $uid) {
-                    $this->delete($uid);
-                }
+            /* ... and delete them. */
+            foreach ($uids as $uid) {
+                $this->delete($uid);
             }
         }
 
+
         /* ...and finally, delete the actual share */
         if (!empty($share)) {
-            $result = $GLOBALS['nag_shares']->removeShare($share);
-            if (is_a($result, 'PEAR_Error')) {
+            try {
+                $GLOBALS['nag_shares']->removeShare($share);
+            } catch (Horde_Share_Exception $e) {
                 $hasError = true;
                 Horde::logMessage($result, 'ERR');
             }
         }
 
         /* Now remove perms for this user from all other shares */
-        $shares = $GLOBALS['nag_shares']->listShares($user);
-        if (is_a($shares, 'PEAR_Error')) {
+        try {
+            $shares = $GLOBALS['nag_shares']->listShares($user);
+            foreach ($shares as $share) {
+               $share->removeUser($user);
+            }
+        } catch (Horde_Share_Exception $e) {
             $hasError = true;
             Horde::logMessage($shares, 'ERR');
         }
-        foreach ($shares as $share) {
-            $share->removeUser($user);
-        }
 
         if ($hasError) {
             return PEAR::raiseError(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
index 9dace3a..dd0cb72 100644 (file)
@@ -204,9 +204,7 @@ class Horde_Block_nag_summary extends Horde_Block {
                 $owner = $task->tasklist;
                 $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope();
                 $share = $shares->getShare($owner);
-                if (!is_a($share, 'PEAR_Error')) {
-                    $owner = $share->get('name');
-                }
+                $owner = $share->get('name');
                 $html .= '<td width="1%" class="nowrap">'
                     . htmlspecialchars($owner) . '&nbsp;</td>';
             }
index 8663ac4..500df70 100644 (file)
@@ -309,9 +309,11 @@ class Nag_Driver
         $log_tasklist = $this->_tasklist;
         if (!is_null($tasklist) && $task->tasklist != $tasklist) {
             /* Moving the task to another tasklist. */
-            $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
-            if (is_a($share, 'PEAR_Error')) {
-                return $share;
+            try {
+                $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
+            } catch (Horde_Share_Exception $e) {
+                Horde::logMessage($e->getMessage(), 'ERR');
+                throw new Nag_Exception($e);
             }
 
             if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
@@ -319,9 +321,11 @@ class Nag_Driver
                 return false;
             }
 
-            $share = $GLOBALS['nag_shares']->getShare($tasklist);
-            if (is_a($share, 'PEAR_Error')) {
-                return $share;
+            try {
+                $share = $GLOBALS['nag_shares']->getShare($tasklist);
+            } catch (Horde_Share_Exception $e) {
+                Horde::logMessage($e->getMessage(), 'ERR');
+                throw new Nag_Exception($e);
             }
 
             if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
@@ -329,7 +333,7 @@ class Nag_Driver
             }
 
             $moved = $this->_move($task->id, $tasklist);
-            if (is_a($moved, 'PEAR_Error')) {
+            if ($moved instanceof PEAR_Error) {
                 return $moved;
             }
             $new_storage = Nag_Driver::singleton($tasklist);
index bf2d6d6..bd11167 100644 (file)
@@ -1043,7 +1043,7 @@ class Nag_Driver_kolab_wrapper_new extends Nag_Driver_kolab_wrapper {
     function listAlarms($date)
     {
         $task_list = $this->_store->getObjects();
-        if (is_a($task_list, 'PEAR_Error')) {
+        if ($task_list instanceof PEAR_Error) {
             return $task_list;
         }
 
diff --git a/nag/lib/Exception.php b/nag/lib/Exception.php
new file mode 100644 (file)
index 0000000..b686261
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Base exception class for Nag.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Nag
+ */
+class Nag_Exception extends Horde_Exception_Prior
+{
+}
index 7d473aa..7acbcb4 100644 (file)
@@ -49,20 +49,19 @@ class Nag_TaskForm extends Horde_Form {
             $task_enums[htmlspecialchars($task->id)] = str_repeat('&nbsp;', $task->indent * 4) . htmlentities($task->name, ENT_COMPAT, Horde_Nls::getCharset());
         }
         $users = array();
-        $share = &$GLOBALS['nag_shares']->getShare($tasklist);
-        if (!is_a($share, 'PEAR_Error')) {
-            $users = $share->listUsers(Horde_Perms::READ);
-            $groups = $share->listGroups(Horde_Perms::READ);
-            if (count($groups)) {
-                require_once 'Horde/Group.php';
-                $horde_group = Group::singleton();
-                foreach ($groups as $group) {
-                    $users = array_merge($users,
-                                         $horde_group->listAllUsers($group));
-                }
+        $share = $GLOBALS['nag_shares']->getShare($tasklist);
+        $users = $share->listUsers(Horde_Perms::READ);
+        $groups = $share->listGroups(Horde_Perms::READ);
+        if (count($groups)) {
+            require_once 'Horde/Group.php';
+            $horde_group = Group::singleton();
+            foreach ($groups as $group) {
+                $users = array_merge($users,
+                                     $horde_group->listAllUsers($group));
             }
-            $users = array_flip($users);
         }
+        $users = array_flip($users);
+
         if (count($users)) {
             foreach (array_keys($users) as $user) {
                 $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity($user);
index 473d323..ece4d2b 100644 (file)
@@ -368,9 +368,10 @@ class Nag
         if ($owneronly && !Horde_Auth::getAuth()) {
             return array();
         }
-        $tasklists = $GLOBALS['nag_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name');
-        if (is_a($tasklists, 'PEAR_Error')) {
-            Horde::logMessage($tasklists, 'ERR');
+        try {
+            $tasklists = $GLOBALS['nag_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name');
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
             return array();
         }
 
@@ -438,20 +439,18 @@ class Nag
      */
     public static function addTasklist($info)
     {
-        $tasklist = $GLOBALS['nag_shares']->newShare(md5(microtime()));
-        if (is_a($tasklist, 'PEAR_Error')) {
-            return $tasklist;
-        }
-        $tasklist->set('name', $info['name']);
-        $tasklist->set('color', $info['color']);
-        $tasklist->set('desc', $info['description']);
-        if (!empty($info['system'])) {
-            $tasklist->set('owner', null);
-        }
+        try {
+            $tasklist = $GLOBALS['nag_shares']->newShare(md5(microtime()));
+            $tasklist->set('name', $info['name']);
+            $tasklist->set('color', $info['color']);
+            $tasklist->set('desc', $info['description']);
+            if (!empty($info['system'])) {
+                $tasklist->set('owner', null);
+            }
 
-        $result = $GLOBALS['nag_shares']->addShare($tasklist);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+            $GLOBALS['nag_shares']->addShare($tasklist);
+        } catch (Horde_Share_Exception $e) {
+            throw new Nag_Exception($e);
         }
 
         $GLOBALS['display_tasklists'][] = $tasklist->getName();
@@ -504,7 +503,7 @@ class Nag
         // Delete the task list.
         $storage = &Nag_Driver::singleton($tasklist->getName());
         $result = $storage->deleteAll();
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $tasklist->get('name'), $result->getMessage()));
         }
 
@@ -829,9 +828,11 @@ class Nag
             return PEAR::raiseError('Unknown event action: ' . $action);
         }
 
-        $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
-        if (is_a($share, 'PEAR_Error')) {
-            return $share;
+        try {
+            $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+            throw new Nag_Exception($e);
         }
 
         require_once 'Horde/Group.php';
@@ -937,15 +938,14 @@ class Nag
                 }
                 if ($old_task->parent_id != $task->parent_id) {
                     $old_parent = $old_task->getParent();
-                    if (!is_a($old_parent, 'PEAR_Error')) {
-                        $parent = $task->getParent();
-                        if (!is_a($parent, 'PEAR_Error')) {
-                            $notification_message .= "\n - "
-                                . sprintf(_("Changed parent task from \"%s\" to \"%s\""),
-                                          $old_parent ? $old_parent->name : _("no parent"),
-                                          $parent ? $parent->name : _("no parent"));
-                        }
+                    $parent = $task->getParent();
+                    if (!is_a($parent, 'PEAR_Error')) {
+                        $notification_message .= "\n - "
+                            . sprintf(_("Changed parent task from \"%s\" to \"%s\""),
+                                      $old_parent ? $old_parent->name : _("no parent"),
+                                      $parent ? $parent->name : _("no parent"));
                     }
+
                 }
                 if ($old_task->category != $task->category) {
                     $notification_message .= "\n - "
@@ -1389,10 +1389,10 @@ class Nag
         $aowner = $a->tasklist;
         $bowner = $b->tasklist;
 
-        if (!is_a($ashare, 'PEAR_Error') && $aowner != $ashare->get('owner')) {
+        if ($aowner != $ashare->get('owner')) {
             $aowner = $ashare->get('name');
         }
-        if (!is_a($bshare, 'PEAR_Error') && $bowner != $bshare->get('owner')) {
+        if ($bowner != $bshare->get('owner')) {
             $bowner = $bshare->get('name');
         }
 
@@ -1421,10 +1421,10 @@ class Nag
         $aowner = $a->tasklist;
         $bowner = $b->tasklist;
 
-        if (!is_a($ashare, 'PEAR_Error') && $aowner != $ashare->get('owner')) {
+        if ($aowner != $ashare->get('owner')) {
             $aowner = $ashare->get('name');
         }
-        if (!is_a($bshare, 'PEAR_Error') && $bowner != $bshare->get('owner')) {
+        if ($bowner != $bshare->get('owner')) {
             $bowner = $bshare->get('name');
         }
 
index ebc4a44..ee2a25d 100644 (file)
@@ -705,9 +705,11 @@ class Nag_Task {
             $json->m = $this->methods;
             //$json->pv = (boolean)$this->private;
 
-            $share = $GLOBALS['nag_shares']->getShare($this->tasklist);
-            if (is_a($share, 'PEAR_Error')) {
-                return $share;
+            try {
+                $share = $GLOBALS['nag_shares']->getShare($this->tasklist);
+            } catch (Horde_Share_exception $e) {
+                Horde::logMessage($e->getMessage(), 'ERR');
+                throw new Nag_Exception($e);
             }
             $json->pe = $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT);
             $json->pd = $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE);
index 02abbe0..9a91490 100644 (file)
@@ -13,29 +13,30 @@ function _delete($task_id, $tasklist_id)
 {
     if (!empty($task_id)) {
         $task = Nag::getTask($tasklist_id, $task_id);
-        if (is_a($task, 'PEAR_Error')) {
+        if ($task instanceof PEAR_Error) {
             $GLOBALS['notification']->push(
                 sprintf(_("Error deleting task: %s"),
                         $task->getMessage()), 'horde.error');
         } else {
-            $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
-            if (is_a($share, 'PEAR_Error') ||
-                !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
-                $GLOBALS['notification']->push(
-                    _("Access denied deleting task."), 'horde.error');
+            try {
+                $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
+            } catch (Horde_Share_Exception $e) {
+                throw new Nag_Exception($e);
+            }
+            if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+                $GLOBALS['notification']->push(_("Access denied deleting task."), 'horde.error');
             } else {
                 $storage = Nag_Driver::singleton($tasklist_id);
-                $result = $storage->delete($task_id);
-                if (is_a($result, 'PEAR_Error')) {
+                try {
+                    $storage->delete($task_id);
+                } catch (Horde_Share_Exception $e) {
                     $GLOBALS['notification']->push(
                         sprintf(_("There was a problem deleting %s: %s"),
-                                $task->name, $result->getMessage()),
+                                $task->name, $e->getMessage()),
                         'horde.error');
-                } else {
-                    $GLOBALS['notification']->push(sprintf(_("Deleted %s."),
-                                                           $task->name),
-                                                   'horde.success');
                 }
+                $GLOBALS['notification']->push(sprintf(_("Deleted %s."), $task->name),
+                                               'horde.success');
             }
         }
     }
@@ -85,10 +86,12 @@ case 'add_task':
 case 'modify_task':
     $task_id = $vars->get('task');
     $tasklist_id = $vars->get('tasklist');
-    $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
-    if (is_a($share, 'PEAR_Error')) {
-        $notification->push(sprintf(_("Access denied editing task: %s"), $share->getMessage()), 'horde.error');
-    } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+    try {
+        $share = $GLOBALS['nag_shares']->getShare($tasklist_id);s
+    } catch (Horde_Share_Exception $e) {
+        $notification->push(sprintf(_("Access denied editing task: %s"), $e->getMessage()), 'horde.error');
+    }
+    if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
         $notification->push(_("Access denied editing task."), 'horde.error');
     } else {
         $task = Nag::getTask($tasklist_id, $task_id);
@@ -124,12 +127,14 @@ case 'save_task':
         count(Nag::listTasklists(false, Horde_Perms::EDIT)) <= 1) {
         $info['tasklist_id'] = $info['old_tasklist'] = Nag::getDefaultTasklist(Horde_Perms::EDIT);
     }
-    $share = $GLOBALS['nag_shares']->getShare($info['tasklist_id']);
-    if (is_a($share, 'PEAR_Error')) {
-        $notification->push(sprintf(_("Access denied saving task: %s"), $share->getMessage()), 'horde.error');
+    try {
+        $share = $GLOBALS['nag_shares']->getShare($info['tasklist_id']);
+    } catch (Horde_Share_Exception $e) {
+        $notification->push(sprintf(_("Access denied saving task: %s"), $e->getMessage()), 'horde.error');
         header('Location: ' . Horde::applicationUrl('list.php', true));
         exit;
-    } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+    }
+    if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
         $notification->push(sprintf(_("Access denied saving task to %s."), $share->get('name')), 'horde.error');
         header('Location: ' . Horde::applicationUrl('list.php', true));
         exit;
@@ -178,7 +183,7 @@ case 'save_task':
     }
 
     /* Check our results. */
-    if (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $notification->push(sprintf(_("There was a problem saving the task: %s."), $result->getMessage()), 'horde.error');
     } else {
         $notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success');
@@ -201,7 +206,7 @@ case 'complete_task':
     if (isset($task_id)) {
         $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
         $task = Nag::getTask($tasklist_id, $task_id);
-        if (is_a($share, 'PEAR_Error') || !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+        if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
             $notification->push(sprintf(_("Access denied completing task %s."), $task->name), 'horde.error');
         } else {
             $task->completed = !$task->completed;
@@ -211,7 +216,7 @@ case 'complete_task':
                 $task->completed_date = null;
             }
             $result = $task->save();
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 $notification->push(sprintf(_("There was a problem completing %s: %s"),
                                             $task->name, $result->getMessage()), 'horde.error');
             } else {
index 3f31243..b3ccb0e 100644 (file)
@@ -24,13 +24,15 @@ if ($tasklist_id == Horde_Auth::getAuth()) {
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
     exit;
 }
-$tasklist = $nag_shares->getShare($tasklist_id);
-if (is_a($tasklist, 'PEAR_Error')) {
+try {
+    $tasklist = $nag_shares->getShare($tasklist_id);
+} catch (Horde_Share_Exception $e) {
     $notification->push($tasklist, 'horde.error');
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
     exit;
-} elseif ($tasklist->get('owner') != Horde_Auth::getAuth() &&
-          (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) {
+}
+if ($tasklist->get('owner') != Horde_Auth::getAuth() &&
+    (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) {
     $notification->push(_("You are not allowed to delete this task list."), 'horde.error');
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
     exit;
@@ -41,7 +43,7 @@ $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 (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $notification->push($result, 'horde.error');
     } elseif ($result) {
         $notification->push(sprintf(_("The task list \"%s\" has been deleted."), $tasklist->get('name')), 'horde.success');
index c481772..dd264ef 100644 (file)
@@ -18,13 +18,15 @@ if (!Horde_Auth::getAuth()) {
 }
 
 $vars = Horde_Variables::getDefaultVariables();
-$tasklist = $nag_shares->getShare($vars->get('t'));
-if (is_a($tasklist, 'PEAR_Error')) {
-    $notification->push($tasklist, 'horde.error');
+try {
+    $tasklist = $nag_shares->getShare($vars->get('t'));
+} catch (Horde_Share_Exception $e) {
+    $notification->push($e->getMessage(), 'horde.error');
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
     exit;
-} elseif ($tasklist->get('owner') != Horde_Auth::getAuth() &&
-          (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) {
+}
+if ($tasklist->get('owner') != Horde_Auth::getAuth() &&
+    (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) {
     $notification->push(_("You are not allowed to change this task list."), 'horde.error');
     header('Location: ' . Horde::applicationUrl('tasklists/', true));
     exit;
@@ -35,7 +37,7 @@ $form = new Nag_EditTaskListForm($vars, $tasklist);
 if ($form->validate($vars)) {
     $original_name = $tasklist->get('name');
     $result = $form->execute();
-    if (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $notification->push($result, 'horde.error');
     } else {
         if ($tasklist->get('name') != $original_name) {
index df04acd..1a48d4e 100644 (file)
@@ -14,8 +14,9 @@ if (!Horde_Auth::getAuth()) {
     exit;
 }
 
-$tasklist = $nag_shares->getShare(Horde_Util::getFormData('t'));
-if (is_a($tasklist, 'PEAR_Error')) {
+try {
+    $tasklist = $nag_shares->getShare(Horde_Util::getFormData('t'));
+} catch (Horde_Share_Exception $e) {
     exit;
 }
 
index 4a793be..2cc68fb 100644 (file)
@@ -43,8 +43,12 @@ if ($tasks->hasTasks()) {
             $share = $GLOBALS['nag_shares']->newShare('**EXTERNAL**');
             $owner = $task->tasklist_name;
         } else {
-            $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
-            $owner = is_a($share, 'PEAR_Error') ? $task->tasklist : $share->get('name');
+            try {
+                $share = $GLOBALS['nag_shares']->getShare($task->tasklist);
+                $owner = $share->get('name');
+            } catch (Horde_Share_Exception $e) {
+                $owner = $task->tasklist;
+            }
         }
 
         require NAG_TEMPLATES . '/list/task_summaries.inc';
index bacdbe3..97cc7be 100644 (file)
@@ -1,8 +1,7 @@
 <tr class="<?php echo $style ?>">
   <td>
 <?php
-if (!is_a($share, 'PEAR_Error') &&
-    $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
     if (!$task->completed) {
         if (!$task->childrenCompleted()) {
             $label = _("Incomplete sub tasks, complete them first");
@@ -33,8 +32,7 @@ if (!is_a($share, 'PEAR_Error') &&
 <?php endif; ?>
   <td>
     <?php
-    if (!is_a($share, 'PEAR_Error') &&
-        $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT) &&
+    if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT) &&
         (!$task->private || $task->owner == Horde_Auth::getAuth())) {
         $label = sprintf(_("Edit \"%s\""), $task->name);
         echo Horde::link($task->edit_link, $label) . Horde::img('edit.png', $label) . '</a>';
@@ -47,8 +45,7 @@ if (!is_a($share, 'PEAR_Error') &&
     $task_name = strlen($task->name)
         ? htmlspecialchars($task->name)
         : _("[none]");
-    if (!is_a($share, 'PEAR_Error') &&
-        $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+    if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
         echo Horde::link($task->view_link, '', '', '', '', $task->desc)
             . $task_name . '</a>';
     } else {
index 304ce43..393ad38 100644 (file)
@@ -41,7 +41,7 @@
  <tr>
   <td class="rightAlign" valign="top"><strong><?php echo _("Completed?") ?></strong></td>
   <td>
-  <?php if (!is_a($share, 'PEAR_Error') && $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+  <?php if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
             if (empty($task->completed)) {
                 echo Horde::link(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete Task"), 'widget') . Horde::img('unchecked.png', _("Complete Task")) . '</a>';
             } else {
index 7bc48e7..447ce01 100644 (file)
@@ -14,7 +14,7 @@ Horde_Registry::appInit('nag');
 if ($uid = Horde_Util::getFormData('uid')) {
     $storage = Nag_Driver::singleton();
     $task = $storage->getByUID($uid);
-    if (is_a($task, 'PEAR_Error')) {
+    if ($task instanceof PEAR_Error) {
         header('Location: ' . Horde::applicationUrl('list.php', true));
         exit;
     }
@@ -47,7 +47,7 @@ $task->loadChildren();
 
 /* Check permissions on $tasklist_id. */
 $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
-if (is_a($share, 'PEAR_Error') || !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
     $notification->push(_("You do not have permission to view this tasklist."), 'horde.error');
     header('Location: ' . Horde::applicationUrl('list.php', true));
     exit;
@@ -99,21 +99,24 @@ Horde::addScriptFile('stripe.js', 'horde');
 $taskurl = Horde_Util::addParameter('task.php',
                               array('task' => $task_id,
                                     'tasklist' => $tasklist_id));
-$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
-
-if (!is_a($share, 'PEAR_Error')) {
-    if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
-        if (!$task->completed) {
-            $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete"), 'smallheader', '', '', _("_Complete"));
-        }
-        if (!$task->private || $task->owner == Horde_Auth::getAuth()) {
-            $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'modify_task')), _("Edit"), 'smallheader', '', '', _("_Edit"));
-        }
+try {
+    $share = $GLOBALS['nag_shares']->getShare($tasklist_id);
+} catch (Horde_Share_Exception $e) {
+    Horde::logMessage($e->getMessage(), 'ERR');
+    throw new Nag_Exception($e);
+}
+if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
+    if (!$task->completed) {
+        $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete"), 'smallheader', '', '', _("_Complete"));
     }
-    if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
-        $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'delete_tasks')), _("Delete"), 'smallheader', '', $prefs->getValue('delete_opt') ? 'return window.confirm(\'' . addslashes(_("Really delete this task?")) . '\');' : '', _("_Delete"));
+    if (!$task->private || $task->owner == Horde_Auth::getAuth()) {
+        $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'modify_task')), _("Edit"), 'smallheader', '', '', _("_Edit"));
     }
 }
+if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) {
+    $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'delete_tasks')), _("Delete"), 'smallheader', '', $prefs->getValue('delete_opt') ? 'return window.confirm(\'' . addslashes(_("Really delete this task?")) . '\');' : '', _("_Delete"));
+}
+
 require NAG_TEMPLATES . '/common-header.inc';
 require NAG_TEMPLATES . '/menu.inc';