From: Michael J. Rubinsky Date: Thu, 20 May 2010 04:30:42 +0000 (-0400) Subject: Start getting Turba caught up with Horde_Share changes X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=283b143b7ab4b1ea4097530b7889e526eafe394e;p=horde.git Start getting Turba caught up with Horde_Share changes --- diff --git a/turba/addressbooks/delete.php b/turba/addressbooks/delete.php index 44546d837..d56ab7b7f 100644 --- a/turba/addressbooks/delete.php +++ b/turba/addressbooks/delete.php @@ -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; diff --git a/turba/addressbooks/edit.php b/turba/addressbooks/edit.php index b28a5e69e..a60f2ca2f 100644 --- a/turba/addressbooks/edit.php +++ b/turba/addressbooks/edit.php @@ -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; diff --git a/turba/browse.php b/turba/browse.php index 504debad2..e152e4219 100644 --- a/turba/browse.php +++ b/turba/browse.php @@ -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 diff --git a/turba/lib/Api.php b/turba/lib/Api.php index b65f14dc2..7c56b292f 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -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; } diff --git a/turba/lib/Application.php b/turba/lib/Application.php index ed34da516..05f7f0a7f 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -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) { diff --git a/turba/lib/Driver.php b/turba/lib/Driver.php index 93dee05b6..642112bfc 100644 --- a/turba/lib/Driver.php +++ b/turba/lib/Driver.php @@ -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'])) { diff --git a/turba/lib/Driver/Imsp.php b/turba/lib/Driver/Imsp.php index 36a4d4a0d..a37dda5f1 100644 --- a/turba/lib/Driver/Imsp.php +++ b/turba/lib/Driver/Imsp.php @@ -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'])) { diff --git a/turba/lib/Driver/Kolab.php b/turba/lib/Driver/Kolab.php index 8eac8d8e9..a9e36a494 100644 --- a/turba/lib/Driver/Kolab.php +++ b/turba/lib/Driver/Kolab.php @@ -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; diff --git a/turba/lib/Driver/Vbook.php b/turba/lib/Driver/Vbook.php index 8dbaece22..c8c83b2f5 100644 --- a/turba/lib/Driver/Vbook.php +++ b/turba/lib/Driver/Vbook.php @@ -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']); diff --git a/turba/lib/Forms/CreateAddressBook.php b/turba/lib/Forms/CreateAddressBook.php index bec1b4234..3bc8e7961 100644 --- a/turba/lib/Forms/CreateAddressBook.php +++ b/turba/lib/Forms/CreateAddressBook.php @@ -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; } diff --git a/turba/lib/Forms/DeleteAddressBook.php b/turba/lib/Forms/DeleteAddressBook.php index e334ff4eb..e8f4d5db4 100644 --- a/turba/lib/Forms/DeleteAddressBook.php +++ b/turba/lib/Forms/DeleteAddressBook.php @@ -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')) { diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index e13f76397..a71b6a492 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -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 diff --git a/turba/search.php b/turba/search.php index a039d1b07..7a9a929a5 100644 --- a/turba/search.php +++ b/turba/search.php @@ -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(); }