Start getting Turba caught up with Horde_Share changes
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 04:30:42 +0000 (00:30 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 20 May 2010 04:30:42 +0000 (00:30 -0400)
13 files changed:
turba/addressbooks/delete.php
turba/addressbooks/edit.php
turba/browse.php
turba/lib/Api.php
turba/lib/Application.php
turba/lib/Driver.php
turba/lib/Driver/Imsp.php
turba/lib/Driver/Kolab.php
turba/lib/Driver/Vbook.php
turba/lib/Forms/CreateAddressBook.php
turba/lib/Forms/DeleteAddressBook.php
turba/lib/Turba.php
turba/search.php

index 44546d8..d56ab7b 100644 (file)
@@ -29,13 +29,16 @@ if ($addressbook_id == Horde_Auth::getAuth()) {
     exit;
 }
 
-$addressbook = $turba_shares->getShare($addressbook_id);
-if (is_a($addressbook, 'PEAR_Error')) {
-    $notification->push($addressbook, 'horde.error');
+try {
+    $addressbook = $turba_shares->getShare($addressbook_id);
+} catch (Horde_Share_Exception $e) {
+    $notification->push($e, 'horde.error');
     header('Location: ' . Horde::applicationUrl('addressbooks/', true));
     exit;
-} elseif (!Horde_Auth::getAuth() ||
-          $addressbook->get('owner') != Horde_Auth::getAuth()) {
+}
+if (!Horde_Auth::getAuth() ||
+    $addressbook->get('owner') != Horde_Auth::getAuth()) {
+
     $notification->push(_("You are not allowed to delete this addressbook."), 'horde.error');
     header('Location: ' . Horde::applicationUrl('addressbooks/', true));
     exit;
index b28a5e6..a60f2ca 100644 (file)
@@ -22,13 +22,16 @@ if (!Horde_Auth::getAuth() || empty($_SESSION['turba']['has_share'])) {
 }
 
 $vars = Horde_Variables::getDefaultVariables();
-$addressbook = $turba_shares->getShare($vars->get('a'));
-if (is_a($addressbook, 'PEAR_Error')) {
-    $notification->push($addressbook, 'horde.error');
+try {
+    $addressbook = $turba_shares->getShare($vars->get('a'));
+} catch (Horde_Share_Exception $e) {
+    $notification->push($e->getMessage(), 'horde.error');
     header('Location: ' . Horde::applicationUrl('addressbooks/', true));
     exit;
-} elseif (!Horde_Auth::getAuth() ||
-          $addressbook->get('owner') != Horde_Auth::getAuth()) {
+}
+if (!Horde_Auth::getAuth() ||
+    $addressbook->get('owner') != Horde_Auth::getAuth()) {
+
     $notification->push(_("You are not allowed to change this addressbook."), 'horde.error');
     header('Location: ' . Horde::applicationUrl('addressbooks/', true));
     exit;
index 504deba..e152e42 100644 (file)
@@ -26,7 +26,7 @@ $params = array(
     'addSources' => $addSources,
     'cfgSources' => $cfgSources,
     'attributes' => $attributes,
-    'turba_shares' => &$turba_shares,
+    'turba_shares' => $turba_shares,
     'conf' => $conf,
     'source' => $default_source,
     'browser' => $browser
index b65f14d..7c56b29 100644 (file)
@@ -122,9 +122,6 @@ class Turba_Api extends Horde_Registry_Api
 
         if (!empty($_SESSION['turba']['has_share'])) {
             $shares = Turba::listShares(true);
-            if ($shares instanceof PEAR_Error) {
-                return false;
-            }
             foreach ($shares as $uid => $share) {
                 $params = @unserialize($share->get('params'));
                 if (empty($params['source'])) {
@@ -270,7 +267,7 @@ class Turba_Api extends Horde_Registry_Api
             $curpath = 'turba/' . $parts[0] . '/';
             foreach ($addressbooks as $addressbook => $info) {
                 if (in_array('name', $properties)) {
-                    if (is_a($info, 'Horde_Share_Object')) {
+                    if ($info instanceof Horde_Share_Object) {
                         $name = $info->get('title');
                     } else {
                         $name = $info['title'];
@@ -654,7 +651,7 @@ class Turba_Api extends Horde_Registry_Api
         $cManager = new Horde_Prefs_CategoryManager();
         $categories = $cManager->get();
 
-        if (!is_a($content, 'Horde_iCalendar_vcard')) {
+        if (!($content instanceof Horde_iCalendar_vcard)) {
             switch ($contentType) {
             case 'array':
                 break;
@@ -677,7 +674,7 @@ class Turba_Api extends Horde_Registry_Api
                 default:
                     $ids = array();
                     foreach ($iCal->getComponents() as $c) {
-                        if (is_a($c, 'Horde_iCalendar_vcard')) {
+                        if ($c instanceof Horde_iCalendar_vcard) {
                             $content = $driver->toHash($c);
                             $result = $driver->search($content);
                             if ($result instanceof PEAR_Error) {
@@ -710,7 +707,7 @@ class Turba_Api extends Horde_Registry_Api
             }
         }
 
-        if (is_a($content, 'Horde_iCalendar_vcard')) {
+        if ($content instanceof Horde_iCalendar_vcard) {
             $content = $driver->toHash($content);
         }
 
@@ -1192,7 +1189,7 @@ class Turba_Api extends Horde_Registry_Api
                 }
 
                 $search = $driver->search($criteria, Turba::getPreferredSortOrder(), 'OR', array(), array(), $matchBegin);
-                if (!is_a($search, 'Turba_List')) {
+                if (!($search instanceof Turba_List)) {
                     continue;
                 }
 
@@ -1266,7 +1263,7 @@ class Turba_Api extends Horde_Registry_Api
                         $seeninlist = array();
                         $members = $ob->listMembers();
                         $listName = $ob->getValue('name');
-                        if (!is_a($members, 'Turba_List')) {
+                        if (!($members instanceof Turba_List)) {
                             continue;
                         }
                         if ($members->count() > 0) {
@@ -1421,7 +1418,7 @@ class Turba_Api extends Horde_Registry_Api
                 }
 
                 $res = $driver->search(array());
-                if (!is_a($res, 'Turba_List')) {
+                if (!($res instanceof Turba_List)) {
                     throw new Horde_Exception(_("Search failed"));
                 }
 
@@ -1731,7 +1728,7 @@ class Turba_Api extends Horde_Registry_Api
             }
 
             $list = $driver->search(array('email' => $address), null, 'AND', array(), $strict ? array('email') : array());
-            if (!is_a($list, 'Turba_List')) {
+            if (!($list instanceof Turba_List)) {
                 continue;
             }
 
@@ -1793,7 +1790,7 @@ class Turba_Api extends Horde_Registry_Api
                 }
 
                 $res = $driver->search(array('email' => $address));
-                if (is_a($res, 'Turba_List')) {
+                if ($res instanceof Turba_List) {
                     if ($res->count() > 1) {
                         continue;
                     }
index ed34da5..05f7f0a 100644 (file)
@@ -405,7 +405,7 @@ class Turba_Application extends Horde_Registry_Application
 
         /* Only attempt share removal if we have shares configured */
         if (!empty($_SESSION['turba']['has_share'])) {
-            $shares = &$GLOBALS['turba_shares']->listShares(
+            $shares = $GLOBALS['turba_shares']->listShares(
                 $user, Horde_Perms::EDIT, $user);
 
             /* Look for the deleted user's default share and remove it */
@@ -423,16 +423,15 @@ class Turba_Application extends Horde_Registry_Application
                 }
             }
 
-            /* Get a list of all shares this user has perms to and remove the
-             * perms. */
-            $shares = $GLOBALS['turba_shares']->listShares($user);
-            if (is_a($shares, 'PEAR_Error')) {
-                Horde::logMessage($shares, 'ERR');
-            }
-            foreach ($shares as $share) {
-                $share->removeUser($user);
+            /* Get a list of all shares this user has perms to and remove the perms. */
+            try {
+                $shares = $GLOBALS['turba_shares']->listShares($user);
+                foreach ($shares as $share) {
+                    $share->removeUser($user);
+                }
+            } catch (Horde_Share_Exception $e) {
+                Horde::logMessage($e, 'ERR');
             }
-
         }
 
         if ($hasError) {
index 93dee05..642112b 100644 (file)
@@ -2591,16 +2591,15 @@ class Turba_Driver
      *
      * @param array $params  The params for the share.
      *
-     * @return mixed  The share object or PEAR_Error.
+     * @return Horde_Share  The share object.
      */
-    function &createShare($share_id, $params)
+    function createShare($share_id, $params)
     {
         // If the raw address book name is not set, use the share name
         if (empty($params['params']['name'])) {
             $params['params']['name'] = $share_id;
         }
-        $result = &Turba::createShare($share_id, $params);
-        return $result;
+        return Turba::createShare($share_id, $params);
     }
 
     /**
@@ -2811,7 +2810,7 @@ class Turba_Driver
      *
      * @return boolean
      */
-    function checkDefaultShare(&$share, $srcconfig)
+    function checkDefaultShare($share, $srcconfig)
     {
         $params = @unserialize($share->get('params'));
         if (!isset($params['default'])) {
index 36a4d4a..a37dda5 100644 (file)
@@ -627,7 +627,7 @@ class Turba_Driver_Imsp extends Turba_Driver
      *
      * @return mixed  The share object or PEAR_Error.
      */
-    function &createShare($share_id, $params)
+    function createShare($share_id, $params)
     {
         if (isset($params['default']) && $params['default'] === true) {
             $params['params']['name'] = $this->params['username'];
@@ -679,7 +679,7 @@ class Turba_Driver_Imsp extends Turba_Driver
      *
      * @see turba/lib/Turba_Driver#checkDefaultShare($share, $srcconfig)
      */
-    function checkDefaultShare(&$share, $srcConfig)
+    function checkDefaultShare($share, $srcConfig)
     {
         $params = @unserialize($share->get('params'));
         if (!isset($params['default'])) {
index 8eac8d8..a9e36a4 100644 (file)
@@ -165,17 +165,17 @@ class Turba_Driver_Kolab extends Turba_Driver
      *
      * @return mixed  The share object or PEAR_Error.
      */
-    function &createShare($share_id, $params)
+    function createShare($share_id, $params)
     {
         if (isset($params['params']['default']) && $params['params']['default'] === true) {
             $share_id = Horde_Auth::getAuth();
         }
 
-        $result = &Turba::createShare($share_id, $params);
+        $result = Turba::createShare($share_id, $params);
         return $result;
     }
 
-    function checkDefaultShare(&$share, $srcConfig)
+    function checkDefaultShare($share, $srcConfig)
     {
         $params = @unserialize($share->get('params'));
         return isset($params['default']) ? $params['default'] : false;
index 8dbaece..c8c83b2 100644 (file)
@@ -54,7 +54,7 @@ class Turba_Driver_Vbook extends Turba_Driver
     function _init()
     {
         /* Grab a reference to the share for this vbook. */
-        $this->_share = &$this->_params['share'];
+        $this->_share = $this->_params['share'];
 
         /* Load the underlying driver. */
         $this->_driver = &Turba_Driver::singleton($this->_params['source']);
index bec1b42..3bc8e79 100644 (file)
@@ -36,7 +36,7 @@ class Turba_CreateAddressBookForm extends Horde_Form {
         include TURBA_BASE . '/config/sources.php';
 
         $driver = Turba_Driver::singleton($cfgSources[$GLOBALS['conf']['shares']['source']]);
-        if (is_a($driver, 'PEAR_Error')) {
+        if ($driver instanceof PEAR_Error) {
             return $driver;
         }
 
index e334ff4..e8f4d5d 100644 (file)
@@ -64,9 +64,11 @@ class Turba_DeleteAddressBookForm extends Horde_Form {
 
         // Address book successfully deleted from backend, remove the
         // share.
-        $result = $GLOBALS['turba_shares']->removeShare($this->_addressbook);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+        try {
+            $GLOBALS['turba_shares']->removeShare($this->_addressbook);
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage(), 'ERR');
+            throw new Turba_Exception($e);
         }
 
         if (isset($_SESSION['turba']['source']) && $_SESSION['turba']['source'] == Horde_Util::getFormData('deleteshare')) {
index e13f763..a71b6a4 100644 (file)
@@ -369,11 +369,11 @@ class Turba {
     {
         global $notification;
 
-        $shares = Turba::listShares();
-
-        // Notify the user if we failed, but still return the $cfgSource array.
-        if (is_a($shares, 'PEAR_Error')) {
-            $notification->push($shares, 'horde.error');
+        try {
+            $shares = Turba::listShares();
+        } catch (Horde_Share_Exception $e) {
+            // Notify the user if we failed, but still return the $cfgSource array.
+            $notification->push($e->getMessage(), 'horde.error');
             return $sources;
         }
 
@@ -387,7 +387,7 @@ class Turba {
             $params = @unserialize($shares[$name]->get('params'));
             if (isset($params['type']) && $params['type'] == 'vbook') {
                 // We load vbooks last in case they're based on other shares.
-                $params['share'] = &$shares[$name];
+                $params['share'] = $shares[$name];
                 $vbooks[$name] = $params;
             } elseif (!empty($params['source']) &&
                       !empty($sources[$params['source']]['use_shares'])) {
@@ -412,7 +412,7 @@ class Turba {
 
                 $share = $sources[$params['source']];
                 $share['params']['config'] = $sources[$params['source']];
-                $share['params']['config']['params']['share'] = &$shares[$name];
+                $share['params']['config']['params']['share'] = $shares[$name];
                 $share['params']['config']['params']['name'] = $params['name'];
                 $share['title'] = $shares[$name]->get('name');
                 $share['type'] = 'share';
@@ -434,20 +434,21 @@ class Turba {
             if (Horde_Auth::getAuth() && empty($defaults[$source])) {
                 // User's default share is missing.
                 $driver = Turba_Driver::singleton($source);
-                if (!is_a($driver, 'PEAR_Error')) {
+                if (!($driver instanceof PEAR_Error)) {
                     $sourceKey = md5(mt_rand());
-                    $share = &$driver->createShare(
-                        $sourceKey,
-                        array('params' => array('source' => $source,
-                                                'default' => true,
-                                                'name' => Horde_Auth::getAuth())));
-                    if (is_a($share, 'PEAR_Error')) {
-                        Horde::logMessage($share, 'ERR');
+                    try {
+                        $share = $driver->createShare(
+                            $sourceKey,
+                            array('params' => array('source' => $source,
+                                                    'default' => true,
+                                                    'name' => Horde_Auth::getAuth())));
+                    } catch (Horde_Share_Exception $e) {
+                        Horde::logMessage($e, 'ERR');
                         continue;
                     }
 
                     $source_config = $sources[$source];
-                    $source_config['params']['share'] = &$share;
+                    $source_config['params']['share'] = $share;
                     $newSources[$sourceKey] = $source_config;
                 } else {
                     $notification->push($driver, 'horde.error');
@@ -481,7 +482,7 @@ class Turba {
      *
      * @param Horde_Share object  The share to base config on.
      */
-    function getSourceFromShare(&$share)
+    function getSourceFromShare($share)
     {
         // Require a fresh config file.
         require TURBA_BASE . '/config/sources.php';
@@ -489,7 +490,7 @@ class Turba {
         $params = @unserialize($share->get('params'));
         $newConfig = $cfgSources[$params['source']];
         $newConfig['params']['config'] = $cfgSources[$params['source']];
-        $newConfig['params']['config']['params']['share'] = &$share;
+        $newConfig['params']['config']['params']['share'] = $share;
         $newConfig['params']['config']['params']['name'] = $params['name'];
         $newConfig['title'] = $share->get('name');
         $newConfig['type'] = 'share';
@@ -517,11 +518,12 @@ class Turba {
             return array();
         }
 
-        $sources = $GLOBALS['turba_shares']->listShares(
-            Horde_Auth::getAuth(), $permission,
-            $owneronly ? Horde_Auth::getAuth() : null);
-        if (is_a($sources, 'PEAR_Error')) {
-            Horde::logMessage($sources, 'ERR');
+        try {
+            $sources = $GLOBALS['turba_shares']->listShares(
+                Horde_Auth::getAuth(), $permission,
+                $owneronly ? Horde_Auth::getAuth() : null);
+        } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e, 'ERR');
             return array();
         }
         return $sources;
@@ -535,7 +537,7 @@ class Turba {
      *
      * @return mixed  The new share object or PEAR_Error
      */
-    function &createShare($share_id, $params)
+    function createShare($share_id, $params)
     {
         if (!isset($params['name'])) {
             /* Sensible default for empty display names */
@@ -551,30 +553,24 @@ class Turba {
         }
 
         /* Generate the new share. */
-        $share = &$GLOBALS['turba_shares']->newShare($share_id);
-        if (is_a($share, 'PEAR_Error')) {
-            return $share;
-        }
+        try {
+            $share = $GLOBALS['turba_shares']->newShare($share_id);
 
-        /* Set the display name for this share. */
-        $share->set('name', $name);
+            /* Set the display name for this share. */
+            $share->set('name', $name);
 
-        /* Now any other params. */
-        foreach ($params as $key => $value) {
-            if (!is_scalar($value)) {
-                $value = serialize($value);
+            /* Now any other params. */
+            foreach ($params as $key => $value) {
+                if (!is_scalar($value)) {
+                    $value = serialize($value);
+                }
+                $share->set($key, $value);
             }
-            $share->set($key, $value);
-        }
-
-        $result = $GLOBALS['turba_shares']->addShare($share);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-
-        $result = $share->save();
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
+            $GLOBALS['turba_shares']->addShare($share);
+            $result = $share->save();
+         } catch (Horde_Share_Exception $e) {
+            Horde::logMessage($e->getMessage, 'ERR');
+            throw new Nag_Exception($e);
         }
 
         /* Update share_id as backends like Kolab change it to the IMAP folder
index a039d1b..7a9a929 100644 (file)
@@ -25,11 +25,11 @@ function _createVBook($params)
                                     'source' => $params['source'],
                                     'criteria' => $params['criteria'])));
 
-    $share = Turba::createShare(md5(microtime()), $params);
-    if (is_a($share, 'PEAR_Error')) {
-        return $share;
+    try {
+        $share = Turba::createShare(md5(microtime()), $params);
+    } catch (Horde_Share_Exception $e) {
+        throw new Turba_Exception($e);
     }
-
     return $share->getName();
 }