Horde_Share changes for WHups
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 04:38:35 +0000 (00:38 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 04:38:35 +0000 (00:38 -0400)
whups/lib/Query.php

index c1c563c..22892c8 100644 (file)
@@ -885,14 +885,15 @@ class Whups_QueryManager {
      * @param integer $queryId  A query id.
      *
      * @return Whups_Query  The matching query or null if not found.
+     * @throws Whups_Exception
      */
     function getQuery($queryId)
     {
-        $share = $this->_shareManager->getShareById($queryId);
-        if (is_a($share, 'PEAR_Error')) {
-            return $share;
+        try {
+            $share = $this->_shareManager->getShareById($queryId);
+        } catch (Horde_Share_Exception $e) {
+            throw new Whups_Exception($e);
         }
-
         return $this->_getQuery($share);
     }
 
@@ -902,13 +903,15 @@ class Whups_QueryManager {
      * @param string $slug  A query slug.
      *
      * @return Whups_Query  The matching query or null if not found.
+     * @throws Whups_Exception
      */
     function getQueryBySlug($slug)
     {
-        $shares = $this->_shareManager->listShares(Horde_Auth::getAuth(), Horde_Perms::READ,
-                                                   array('slug' => $slug));
-        if (is_a($shares, 'PEAR_Error')) {
-            return $shares;
+        try {
+            $shares = $this->_shareManager->listShares(Horde_Auth::getAuth(), Horde_Perms::READ,
+                                                       array('slug' => $slug));
+        } catch (Horde_Share_Exception $e) {
+            throw new Whups_Exception($e);
         }
         if (!count($shares)) {
             return;
@@ -927,7 +930,7 @@ class Whups_QueryManager {
     function _getQuery($share)
     {
         $queryDetails = $GLOBALS['whups_driver']->getQuery($share->getId());
-        if (is_a($queryDetails, 'PEAR_Error')) {
+        if ($queryDetails instanceof PEAR_Error) {
             return $queryDetails;
         }
 
@@ -950,8 +953,9 @@ class Whups_QueryManager {
      */
     function hasPermission($queryId, $userid, $permission, $creator = null)
     {
-        $share = $this->_shareManager->getShareById($queryId);
-        if (is_a($share, 'PEAR_Error')) {
+        try {
+            $share = $this->_shareManager->getShareById($queryId);
+        } catch (Horde_Share_Exception $e) {
             // If the share doesn't exist yet, then it has open perms.
             return true;
         }
@@ -963,9 +967,10 @@ class Whups_QueryManager {
      */
     function listQueries($user, $return_slugs = false)
     {
-        $shares = $this->_shareManager->listShares($user);
-        if (is_a($shares, 'PEAR_Error')) {
-            return $shares;
+        try {
+            $shares = $this->_shareManager->listShares($user);
+        } catch (Horde_Share_Exception $e) {
+            throw new Whups_Exception($e):
         }
 
         $queries = array();
@@ -988,17 +993,19 @@ class Whups_QueryManager {
 
     /**
      * @param Whups_Query $query The query to save.
+     * @throws Whups_Exception
      */
     function save($query)
     {
         if ($query->id) {
             // Query already exists; get its share and update the name
             // if necessary.
-            $share = $this->_shareManager->getShareById($query->id);
-            if (is_a($share, 'PEAR_Error')) {
+            try {
+                $share = $this->_shareManager->getShareById($query->id);
+            } catch (Horde_Share_Exception $e) {
                 // Share has an id but doesn't exist; just throw an
                 // error.
-                return $share;
+                throw new Whups_Exception($e);
             }
             if ($share->get('name') != $query->name ||
                 $share->get('slug') != $query->slug) {
@@ -1011,9 +1018,10 @@ class Whups_QueryManager {
             $share = $this->_shareManager->newShare(md5(microtime()));
             $share->set('name', $query->name);
             $share->set('slug', $query->slug);
-            $result = $this->_shareManager->addShare($share);
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
+            try {
+                $this->_shareManager->addShare($share);
+            } catch (Horde_Share_Exception $e) {
+                throw new Whups_Exception($e);
             }
             $query->id = $share->getId();
         }
@@ -1032,18 +1040,14 @@ class Whups_QueryManager {
             return;
         }
 
-        $share = $this->_shareManager->getShareById($query->id);
-        if (is_a($share, 'PEAR_Error')) {
-            return $share;
-        }
-
-        $result = $this->_shareManager->removeShare($share);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+        try {
+            $share = $this->_shareManager->getShareById($query->id);
+            $this->_shareManager->removeShare($share);
+        } catch (Horde_Share_Exception $e) {
+            throw new Whups_Exception($e);
         }
-
         $result = $GLOBALS['whups_driver']->deleteQuery($query->id);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }