From: Michael J. Rubinsky Date: Wed, 19 May 2010 22:42:20 +0000 (-0400) Subject: Track Horde_Share changes. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4df314b97c7341fa01c6159134fb7cd0df98a11d;p=horde.git Track Horde_Share changes. Still *alot* of H3 cruft in Mnemo...got some of it as I saw it while going through for share changes, but still a lot to do. --- diff --git a/mnemo/lib/Api.php b/mnemo/lib/Api.php index 25d14aea4..b428f82c7 100644 --- a/mnemo/lib/Api.php +++ b/mnemo/lib/Api.php @@ -35,49 +35,50 @@ class Mnemo_Api extends Horde_Registry_Api { $hasError = false; /* Get the share object for later deletion */ - $share = $GLOBALS['mnemo_shares']->getShare($user); - if (is_a($share, 'PEAR_Error')) { - Horde::logMessage($share->getMessage(), 'ERR'); - unset($share); + try { + $share = $GLOBALS['mnemo_shares']->getShare($user); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + } + $GLOBALS['display_notepads'] = array($user); + $memos = Mnemo::listMemos(); + if ($memos instanceof PEAR_Error) { + $hasError = true; + Horde::logMessage($mnemos->getMessage(), 'ERR'); } else { - $GLOBALS['display_notepads'] = array($user); - $memos = Mnemo::listMemos(); - if (is_a($memos, 'PEAR_Error')) { - $hasError = true; - Horde::logMessage($mnemos->getMessage(), 'ERR'); - } else { - $uids = array(); - foreach ($memos as $memo) { - $uids[] = $memo['uid']; - } + $uids = array(); + foreach ($memos as $memo) { + $uids[] = $memo['uid']; + } - /* ... and delete them. */ - foreach ($uids as $uid) { - _mnemo_delete($uid); - } + /* ... and delete them. */ + foreach ($uids as $uid) { + _mnemo_delete($uid); } + } - /* Remove the share itself */ - if (!empty($share)) { - $result = $GLOBALS['mnemo_shares']->removeShare($share); - if (is_a($result, 'PEAR_Error')) { - $hasError = true; - Horde::logMessage($result->getMessage(), 'ERR'); - } + /* Remove the share itself */ + if (!empty($share)) { + try { + $GLOBALS['mnemo_shares']->removeShare($share); + } catch (Horde_Share_Exception $e) { + $hasError = true; + Horde::logMessage($e->getMessage(), 'ERR'); } + } - /* Get a list of all shares this user has perms to and remove the perms */ + /* Get a list of all shares this user has perms to and remove the perms */ + try { $shares = $GLOBALS['mnemo_shares']->listShares($user); - if (is_a($shares, 'PEAR_Error')) { - $hasError = true; - Horde::logMessage($shares, 'ERR'); - } else { - foreach ($shares as $share) { - $share->removeUser($user); - } + foreach ($shares as $share) { + $share->removeUser($user); } + } catch (Horde_Share_Exception $e) { + $hasError = true; + Horde::logMessage($e, 'ERR'); } + if ($hasError) { return PEAR::raiseError(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user)); } else { diff --git a/mnemo/lib/Block/summary.php b/mnemo/lib/Block/summary.php index 5d46cb23f..f9fd7f78a 100644 --- a/mnemo/lib/Block/summary.php +++ b/mnemo/lib/Block/summary.php @@ -85,10 +85,8 @@ class Horde_Block_Mnemo_summary extends Horde_Block { if (!empty($this->_params['show_notepad'])) { $owner = $memo['memolist_id']; - $share = &$shares->getShare($owner); - if (!is_a($share, 'PEAR_Error')) { - $owner = $share->get('name'); - } + $share = $shares->getShare($owner); + $owner = $share->get('name'); $html .= '' . htmlspecialchars($owner) . ''; } diff --git a/mnemo/lib/Exception.php b/mnemo/lib/Exception.php new file mode 100644 index 000000000..dd5adcd7c --- /dev/null +++ b/mnemo/lib/Exception.php @@ -0,0 +1,15 @@ + + * @package Mnemo + */ +class Mnemo_Exception extends Horde_Exception_Prior +{ +} diff --git a/mnemo/lib/Forms/CreateNotepad.php b/mnemo/lib/Forms/CreateNotepad.php index 4d2428637..79e164b20 100644 --- a/mnemo/lib/Forms/CreateNotepad.php +++ b/mnemo/lib/Forms/CreateNotepad.php @@ -39,9 +39,11 @@ class Mnemo_CreateNotepadForm extends Horde_Form { function execute() { // Create new share. - $notepad = $GLOBALS['mnemo_shares']->newShare(md5(microtime())); - if (is_a($notepad, 'PEAR_Error')) { - return $notepad; + try { + $notepad = $GLOBALS['mnemo_shares']->newShare(md5(microtime())); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Mnemo_Exception($e); } $notepad->set('name', $this->_vars->get('name')); $notepad->set('desc', $this->_vars->get('description')); diff --git a/mnemo/lib/Forms/DeleteNotepad.php b/mnemo/lib/Forms/DeleteNotepad.php index 8b980934f..a2c8e8075 100644 --- a/mnemo/lib/Forms/DeleteNotepad.php +++ b/mnemo/lib/Forms/DeleteNotepad.php @@ -61,9 +61,11 @@ class Mnemo_DeleteNotepadForm extends Horde_Form { return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $this->_notepad->get('name'), $result->getMessage())); } else { // Remove share and all groups/permissions. - $result = $GLOBALS['mnemo_shares']->removeShare($this->_notepad); - if (is_a($result, 'PEAR_Error')) { - return $result; + try { + $GLOBALS['mnemo_shares']->removeShare($this->_notepad); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + return; } } @@ -71,14 +73,15 @@ class Mnemo_DeleteNotepadForm extends Horde_Form { if (count(Mnemo::listNotepads(true)) == 0) { // If the default share doesn't exist then create it. if (!$GLOBALS['mnemo_shares']->exists(Horde_Auth::getAuth())) { - require_once 'Horde/Identity.php'; - $identity = &Identity::singleton(); + + $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity(); $name = $identity->getValue('fullname'); if (trim($name) == '') { $name = Horde_Auth::getAuth(); } - $notepad = &$GLOBALS['mnemo_shares']->newShare(Horde_Auth::getAuth()); - if (is_a($notepad, 'PEAR_Error')) { + try { + $notepad = $GLOBALS['mnemo_shares']->newShare(Horde_Auth::getAuth()); + } catch (Horde_Share_Exception $e) { return; } $notepad->set('name', sprintf(_("%s's Notepad"), $name)); diff --git a/mnemo/lib/Mnemo.php b/mnemo/lib/Mnemo.php index 760aa8308..e6abb0330 100644 --- a/mnemo/lib/Mnemo.php +++ b/mnemo/lib/Mnemo.php @@ -173,9 +173,10 @@ class Mnemo { if ($owneronly && !Horde_Auth::getAuth()) { return array(); } - $notepads = $GLOBALS['mnemo_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name'); - if (is_a($notepads, 'PEAR_Error')) { - Horde::logMessage($notepads, 'ERR'); + try { + $notepads = $GLOBALS['mnemo_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(); } @@ -301,10 +302,10 @@ class Mnemo { $ashare = $GLOBALS['mnemo_shares']->getShare($aowner); $bshare = $GLOBALS['mnemo_shares']->getShare($bowner); - 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'); } @@ -328,10 +329,10 @@ class Mnemo { $ashare = $GLOBALS['mnemo_shares']->getShare($aowner); $bshare = $GLOBALS['mnemo_shares']->getShare($bowner); - 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'); } diff --git a/mnemo/list.php b/mnemo/list.php index 7acda20d0..814636d0a 100644 --- a/mnemo/list.php +++ b/mnemo/list.php @@ -91,11 +91,11 @@ if (count($memos)) { $memourl = Horde_Util::addParameter( 'memo.php', array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'])); - $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']); - - $notepad = $memo['memolist_id']; - if (!is_a($share, 'PEAR_Error')) { + try { + $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']); $notepad = $share->get('name'); + } catch (Horde_Share_Exception $e) { + $notepad = $memo['memolist_id']; } require MNEMO_TEMPLATES . '/list/memo_summaries.inc'; diff --git a/mnemo/memo.php b/mnemo/memo.php index e3e50b2e9..cbc49d92d 100644 --- a/mnemo/memo.php +++ b/mnemo/memo.php @@ -19,7 +19,7 @@ function showPassphrase($memo) { global $notification; - if (!is_a($memo['body'], 'PEAR_Error')) { + if (!($memo['body'] instanceof PEAR_Error)) { return false; } @@ -85,7 +85,7 @@ case 'add_memo': if (empty($memolist_id)) { $memolist_id = Mnemo::getDefaultNotepad(); } - if (is_a($memolist_id, 'PEAR_Error')) { + if ($memolist_id instanceof PEAR_Error) { $notification->push($memolist_id, 'horde.error'); } $memo_id = null; @@ -129,10 +129,13 @@ case 'save_memo': $memo_passphrase = Horde_Util::getFormData('memo_passphrase'); $memo_passphrase2 = Horde_Util::getFormData('memo_passphrase2'); - $share = $GLOBALS['mnemo_shares']->getShare($notepad_target); - if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("Access denied saving note: %s"), $share->getMessage()), 'horde.error'); - } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + try { + $share = $GLOBALS['mnemo_shares']->getShare($notepad_target); + } catch (Horde_Share_Exception $e) { + throw new Mnemo_Exception($e); + } + + if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { $notification->push(sprintf(_("Access denied saving note to %s."), $share->get('name')), 'horde.error'); } elseif ($memo_passphrase != $memo_passphrase2) { $notification->push(_("The passwords don't match."), 'horde.error'); @@ -165,16 +168,22 @@ case 'save_memo': /* If $memo_id is set, we're modifying an existing note. Otherwise, * we're adding a new note with the provided attributes. */ if (!empty($memo_id) && - !is_a(Mnemo::getMemo($memolist_original, $memo_id), 'PEAR_Error')) { + !(Mnemo::getMemo($memolist_original, $memo_id) instanceof PEAR_Error)) { $storage = &Mnemo_Driver::singleton($memolist_original); if ($memolist_original != $notepad_target) { /* Moving the note to another notepad. */ - $share = &$GLOBALS['mnemo_shares']->getShare($memolist_original); - if (!is_a($share, 'PEAR_Error') && - $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { - $share = &$GLOBALS['mnemo_shares']->getShare($notepad_target); - if (!is_a($share, 'PEAR_Error') && - $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + try { + $share = $GLOBALS['mnemo_shares']->getShare($memolist_original); + } catch (Horde_Share_Exception $e) { + throw new Mnemo_Exception($e); + } + if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { + try { + $share = &$GLOBALS['mnemo_shares']->getShare($notepad_target); + } catch (Horde_Share_Exception $e) { + throw new Mnemo_Exception($e); + } + if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { $result = $storage->move($memo_id, $notepad_target); $storage = &Mnemo_Driver::singleton($notepad_target); } else { @@ -206,7 +215,7 @@ case 'save_memo': } /* Check our results. */ - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { $notification->push(sprintf(_("There was an error saving the note: %s"), $result->getMessage()), 'horde.warning'); } else { $notification->push(sprintf(_("Successfully saved \"%s\"."), $memo_desc), 'horde.success'); @@ -223,13 +232,15 @@ case 'delete_memos': $memolist_id = Horde_Util::getFormData('memolist'); if (!is_null($memo_id) && Mnemo::getMemo($memolist_id, $memo_id)) { - $share = &$GLOBALS['mnemo_shares']->getShare($memolist_id); - if (!is_a($share, 'PEAR_Error') && - $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { + try { + $share = $GLOBALS['mnemo_shares']->getShare($memolist_id); + } catch (Horde_Share_Exception $e) { + throw new Mnemo_Exception($e); + } + if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { $storage = &Mnemo_Driver::singleton($memolist_id); $result = $storage->delete($memo_id); - - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { $notification->push(sprintf(_("There was an error removing the note: %s"), $result->getMessage()), 'horde.warning'); } else { $notification->push(_("The note was deleted."), 'horde.success'); diff --git a/mnemo/note/pdf.php b/mnemo/note/pdf.php index 54ea73c8e..c721bbe08 100644 --- a/mnemo/note/pdf.php +++ b/mnemo/note/pdf.php @@ -20,7 +20,7 @@ $passphrase = Horde_Util::getFormData('memo_passphrase'); $storage = &Mnemo_Driver::singleton(); if ($uid = Horde_Util::getFormData('uid')) { $note = $storage->getByUID($uid, $passphrase); - if (is_a($note, 'PEAR_Error')) { + if ($note instanceof PEAR_Error) { header('Location: ' . Horde::applicationUrl('list.php', true)); exit; } @@ -40,13 +40,14 @@ if ($uid = Horde_Util::getFormData('uid')) { /* Get the current memo. */ $note = Mnemo::getMemo($notelist_id, $note_id, $passphrase); } - -$share = &$GLOBALS['mnemo_shares']->getShare($notelist_id); -if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $share->getMessage()), 'horde.error'); +try { + $share = $GLOBALS['mnemo_shares']->getShare($notelist_id); +} catch (Horde_Share_Exception $e) { + $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $e->getMessage()), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; -} elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { +} +if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { $notification->push(sprintf(_("You do not have permission to view the notepad %s."), $share->get('name')), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; diff --git a/mnemo/notepads/delete.php b/mnemo/notepads/delete.php index 08d594d94..71249f93e 100644 --- a/mnemo/notepads/delete.php +++ b/mnemo/notepads/delete.php @@ -27,14 +27,14 @@ if ($notepad_id == Horde_Auth::getAuth()) { header('Location: ' . Horde::applicationUrl('notepads/', true)); exit; } - -$notepad = $mnemo_shares->getShare($notepad_id); -if (is_a($notepad, 'PEAR_Error')) { - $notification->push($notepad, 'horde.error'); +try { + $notepad = $mnemo_shares->getShare($notepad_id); +} catch (Horde_Share_Exception $e) { + $notification->push($e->getMessage(), 'horde.error'); header('Location: ' . Horde::applicationUrl('notepads/', true)); exit; -} elseif (!Horde_Auth::getAuth() || - $notepad->get('owner') != Horde_Auth::getAuth()) { +} +if (!Horde_Auth::getAuth() || $notepad->get('owner') != Horde_Auth::getAuth()) { $notification->push(_("You are not allowed to delete this notepad."), 'horde.error'); header('Location: ' . Horde::applicationUrl('notepads/', true)); exit; @@ -45,7 +45,7 @@ $form = new Mnemo_DeleteNotepadForm($vars, $notepad); // 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 notepad \"%s\" has been deleted."), $notepad->get('name')), 'horde.success'); diff --git a/mnemo/notepads/edit.php b/mnemo/notepads/edit.php index ddf5012eb..eef01e9b7 100644 --- a/mnemo/notepads/edit.php +++ b/mnemo/notepads/edit.php @@ -21,13 +21,16 @@ if (!Horde_Auth::getAuth()) { } $vars = Horde_Variables::getDefaultVariables(); -$notepad = $mnemo_shares->getShare($vars->get('n')); -if (is_a($notepad, 'PEAR_Error')) { - $notification->push($notepad, 'horde.error'); +try { + $notepad = $mnemo_shares->getShare($vars->get('n')); +} catch (Horde_Share_Exception $e) { + $notification->push($e->getMessage(), 'horde.error'); header('Location: ' . Horde::applicationUrl('notepads/', true)); exit; -} elseif (!Horde_Auth::getAuth() || - $notepad->get('owner') != Horde_Auth::getAuth()) { +} +if (!Horde_Auth::getAuth() || + $notepad->get('owner') != Horde_Auth::getAuth()) { + $notification->push(_("You are not allowed to change this notepad."), 'horde.error'); header('Location: ' . Horde::applicationUrl('notepads/', true)); exit; diff --git a/mnemo/notes/index.php b/mnemo/notes/index.php index 934c750f5..7d01021b7 100644 --- a/mnemo/notes/index.php +++ b/mnemo/notes/index.php @@ -66,11 +66,11 @@ if (count($memos)) { $memourl = Horde_Util::addParameter( 'memo.php', array('memo' => $memo['memo_id'], 'memolist' => $memo['memolist_id'])); - $share = &$GLOBALS['mnemo_shares']->getShare($memo['memolist_id']); - - $notepad = $memo['memolist_id']; - if (!is_a($share, 'PEAR_Error')) { + try { + $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']); $notepad = $share->get('name'); + } catch (Horde_Share_Exception $e) { + $notepad = $memo['memolist_id']; } require MNEMO_TEMPLATES . '/list/memo_summaries.inc'; diff --git a/mnemo/templates/list/memo_summaries.inc b/mnemo/templates/list/memo_summaries.inc index 727ec3c6a..e9350b0eb 100644 --- a/mnemo/templates/list/memo_summaries.inc +++ b/mnemo/templates/list/memo_summaries.inc @@ -1,7 +1,7 @@ hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { +if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { $label = sprintf(_("Edit \"%s\""), $memo['desc']); echo Horde::link(Horde::applicationUrl(Horde_Util::addParameter($memourl, 'actionID', 'modify_memo')), $label) . Horde::img('edit.png', $label, '') . ''; diff --git a/mnemo/templates/memo/memo.inc b/mnemo/templates/memo/memo.inc index c9fa2928d..b59716018 100644 --- a/mnemo/templates/memo/memo.inc +++ b/mnemo/templates/memo/memo.inc @@ -6,8 +6,8 @@ if ($memo_id): $memourl = Horde_Util::addParameter('memo.php', array('memo' => $memo_id, 'memolist' => $memolist_id)); - $share = &$GLOBALS['mnemo_shares']->getShare($memolist_id); - if (!is_a($share, 'PEAR_Error') && $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)): ?> + $share = $GLOBALS['mnemo_shares']->getShare($memolist_id); + if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)): ?> " onclick="window.location='';" /> diff --git a/mnemo/templates/view/memo.inc b/mnemo/templates/view/memo.inc index e439cd275..761b90762 100644 --- a/mnemo/templates/view/memo.inc +++ b/mnemo/templates/view/memo.inc @@ -2,7 +2,7 @@ $memourl = Horde_Util::addParameter('memo.php', array('memo' => $memo_id, 'memolist' => $memolist_id)); -$share = &$GLOBALS['mnemo_shares']->getShare($memolist_id); +$share = $GLOBALS['mnemo_shares']->getShare($memolist_id); ?>
diff --git a/mnemo/view.php b/mnemo/view.php index e7a4249ae..4ee5609a3 100644 --- a/mnemo/view.php +++ b/mnemo/view.php @@ -38,13 +38,14 @@ if ($uid = Horde_Util::getFormData('uid')) { /* Get the current memo. */ $memo = Mnemo::getMemo($memolist_id, $memo_id, $passphrase); } - -$share = $GLOBALS['mnemo_shares']->getShare($memolist_id); -if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $share->getMessage()), 'horde.error'); +try { + $share = $GLOBALS['mnemo_shares']->getShare($memolist_id); +} catch (Horde_Share_Exception $e) { + $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $e->getMessage()), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; -} elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { +} +if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { $notification->push(sprintf(_("You do not have permission to view the notepad %s."), $share->get('name')), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit;