Consolidate removeUserDataFromAllApplications with removeUserData
authorMichael M Slusarz <slusarz@curecanti.org>
Sat, 28 Aug 2010 06:17:45 +0000 (00:17 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sat, 28 Aug 2010 18:22:07 +0000 (12:22 -0600)
framework/Core/lib/Horde/Core/Auth/Application.php
horde/lib/Api.php

index 7d56fb3..c9428c3 100644 (file)
@@ -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);
             }
index b38e6a7..7ba249c 100644 (file)
@@ -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));
         }
     }