From 3d8e80a33b1552a9e36ee73de658ef86919dff5d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 28 Aug 2010 00:17:45 -0600 Subject: [PATCH] Consolidate removeUserDataFromAllApplications with removeUserData --- framework/Core/lib/Horde/Core/Auth/Application.php | 8 +-- horde/lib/Api.php | 58 +++++++--------------- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/framework/Core/lib/Horde/Core/Auth/Application.php b/framework/Core/lib/Horde/Core/Auth/Application.php index 7d56fb365..c9428c3a7 100644 --- a/framework/Core/lib/Horde/Core/Auth/Application.php +++ b/framework/Core/lib/Horde/Core/Auth/Application.php @@ -215,12 +215,6 @@ class Horde_Core_Auth_Application extends Horde_Auth_Base { if ($this->_base) { $this->_base->removeUser($userId); - - try { - $GLOBALS['registry']->callAppMethod('horde', 'removeUserDataFromAllApplications', array('args' => array($userId))); - } catch (Horde_Exception $e) { - throw new Horde_Auth_Exception($e); - } } else { if ($this->hasCapability('remove')) { $GLOBALS['registry']->callAppMethod($this->_app, $this->_apiMethods['remove'], array('args' => array($userId))); @@ -229,7 +223,7 @@ class Horde_Core_Auth_Application extends Horde_Auth_Base } try { - $GLOBALS['registry']->callAppMethod($this->_app, 'removeUserData', array('args' => array($userId))); + $GLOBALS['registry']->callByPackage('horde', 'removeUserData', array($userId, !empty($this->_base))); } catch (Horde_Exception $e) { throw new Horde_Auth_Exception($e); } diff --git a/horde/lib/Api.php b/horde/lib/Api.php index b38e6a72a..7ba249cb4 100644 --- a/horde/lib/Api.php +++ b/horde/lib/Api.php @@ -196,24 +196,24 @@ class Horde_Api extends Horde_Registry_Api /** * Removes user data. * - * @param string $user Name of user to remove data for. + * @param string $user Name of user to remove data for. + * @param boolean $allapps Remove data from all applications? * * @throws Horde_Exception */ - public function removeUserData($user) + public function removeUserData($user, $allapps = false) { - if (!$GLOBALS['registry']->isAdmin() && - $user != $GLOBALS['registry']->getAuth()) { + global $conf, $injector, $registry; + + if (!$registry->isAdmin() && ($user != $registry->getAuth())) { throw new Horde_Exception(_("You are not allowed to remove user data.")); } - global $conf; - /* Error flag */ $haveError = false; /* Remove user's prefs */ - $prefs = $GLOBALS['injector']->getInstance('Horde_Prefs')->getPrefs('horde', array( + $prefs = $injector->getInstance('Horde_Prefs')->getPrefs('horde', array( 'user' => $user )); try { @@ -236,7 +236,7 @@ class Horde_Api extends Horde_Registry_Api } /* Remove the user from all application permissions */ - $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); + $perms = $injector->getInstance('Horde_Perms'); try { $tree = $perms->getTree(); } catch (Horde_Perms_Exception $e) { @@ -260,41 +260,21 @@ class Horde_Api extends Horde_Registry_Api } } - if ($haveError) { - throw new Horde_Exception(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); - } - } - - /** - * Removes user data from all applications. - * - * @param string $user Name of user to remove data for. - * - * @throws Horde_Exception - */ - public function removeUserDataFromAllApplications($user) - { - global $registry; - - if (!$registry->isAdmin() && ($user != $registry->getAuth())) { - throw new Horde_Exception(_("You are not allowed to remove user data.")); - } - - $errors = array(); - - foreach ($registry->listAllApps() as $app) { - if ($registry->hasAppMethod($app, 'removeUserData')) { - try { - $registry->callAppMethod($app, 'removeUserData', array('args' => array($user))); - } catch (Horde_Exception $e) { - Horde::logMessage($e, 'ERR'); - $errors[] = $app; + if ($allapps) { + foreach ($registry->listAllApps() as $app) { + if ($registry->hasAppMethod($app, 'removeUserData')) { + try { + $registry->callAppMethod($app, 'removeUserData', array('args' => array($user))); + } catch (Horde_Exception $e) { + Horde::logMessage($e, 'ERR'); + $errors[] = $app; + } } } } - if (!empty($errors)) { - throw new Horde_Exception(sprintf(_("The following applications encountered errors removing user data: %s"), implode(', ', $errors))); + if ($haveError) { + throw new Horde_Exception(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); } } -- 2.11.0