Clean up application removeUserData() functions
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 1 Sep 2010 00:01:21 +0000 (18:01 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 1 Sep 2010 00:30:58 +0000 (18:30 -0600)
ingo/lib/Application.php
kronolith/lib/Application.php
mnemo/lib/Api.php
nag/lib/Application.php
turba/lib/Application.php

index e750fe4..ba91e0b 100644 (file)
@@ -157,21 +157,16 @@ class Ingo_Application extends Horde_Registry_Application
      *
      * @param string $user  Name of user to remove data for.
      *
-     * @throws Horde_Auth_Exception.
+     * @throws Ingo_Exception.
      */
     public function removeUserData($user)
     {
-        if (!$GLOBALS['registry']->isAdmin() &&
-            ($user != $GLOBALS['registry']->getAuth())) {
-            throw new Horde_Auth_Exception(_("You are not allowed to remove user data."));
-        }
-
         /* Remove all filters/rules owned by the user. */
         try {
             $GLOBALS['ingo_storage']->removeUserData($user);
         } catch (Ingo_Exception $e) {
             Horde::logMessage($e, 'ERR');
-            throw new Horde_Auth_Exception($e);
+            throw $e;
         }
 
         /* Now remove all shares owned by the user. */
@@ -181,7 +176,7 @@ class Ingo_Application extends Horde_Registry_Application
                 $share = $GLOBALS['ingo_shares']->getShare($user);
                 $GLOBALS['ingo_shares']->removeShare($share);
             } catch (Horde_Share_Exception $e) {
-                Horde::logMessage($e->getMessage(), 'ERR');
+                Horde::logMessage($e, 'ERR');
                 throw new Ingo_Exception($e);
             }
 
@@ -192,7 +187,7 @@ class Ingo_Application extends Horde_Registry_Application
                 foreach ($shares as $share) {
                     $share->removeUser($user);
                 }
-            } catch (Horde_Shares_Exception $e) {
+            } catch (Horde_Share_Exception $e) {
                 Horde::logMessage($e, 'ERR');
             }
 
index ef88b27..aac36b8 100644 (file)
@@ -429,11 +429,6 @@ class Kronolith_Application extends Horde_Registry_Application
      */
     public function removeUserData($user)
     {
-        if (!$GLOBALS['registry']->isAdmin() &&
-            $user != $GLOBALS['registry']->getAuth()) {
-            throw new Kronolith_Exception(_("You are not allowed to remove user data."));
-        }
-
         /* Remove all events owned by the user in all calendars. */
         $result = Kronolith::getDriver()->removeUserData($user);
 
@@ -443,6 +438,7 @@ class Kronolith_Application extends Horde_Registry_Application
             $result = $GLOBALS['kronolith_shares']->removeShare($share);
         } catch (Exception $e) {
             Horde::logMessage($e, 'ERR');
+            throw $e;
         }
 
         /* Get a list of all shares this user has perms to and remove the
@@ -454,6 +450,7 @@ class Kronolith_Application extends Horde_Registry_Application
             }
         } catch (Horde_Share_Exception $e) {
             Horde::logMessage($e, 'ERR');
+            throw $e;
         }
     }
 
index 78f6ce4..aec1b7a 100644 (file)
@@ -5,46 +5,38 @@
  * This file defines Mnemo's external API interface.  Other applications can
  * interact with Mnemo through this API.
  *
- * $Horde: mnemo/lib/api.php,v 1.99 2009-11-24 04:13:44 chuck Exp $
- *
  * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file LICENSE for license information (ASL). If you
  * did not receive this file, see http://www.horde.org/licenses/asl.php.
  *
- * @since   Mnemo 1.0
- * @package Mnemo
+ * @category Horde
+ * @package  Mnemo
  */
 
-class Mnemo_Api extends Horde_Registry_Api {
-
+class Mnemo_Api extends Horde_Registry_Api
+{
     /**
      * Removes user data.
      *
      * @param string $user  Name of user to remove data for.
      *
-     * @return mixed  true on success | PEAR_Error on failure
+     * @throws Mnemo_Exception
      */
     public function removeUserData($user)
     {
-        if (!$GLOBALS['registry']->isAdmin() && $user != $GLOBALS['registry']->getAuth()) {
-            return PEAR::raiseError(_("You are not allowed to remove user data."));
-        }
-
-        /* Error flag */
-        $hasError = false;
-
         /* Get the share object for later deletion */
         try {
             $share = $GLOBALS['mnemo_shares']->getShare($user);
         } catch (Horde_Share_Exception $e) {
-            Horde::logMessage($e->getMessage(), 'ERR');
+            Horde::logMessage($e), 'ERR');
         }
+
         $GLOBALS['display_notepads'] = array($user);
         $memos = Mnemo::listMemos();
         if ($memos instanceof PEAR_Error) {
-            $hasError = true;
-            Horde::logMessage($mnemos->getMessage(), 'ERR');
+            Horde::logMessage($mnemos, 'ERR');
+            throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user));
         } else {
             $uids = array();
             foreach ($memos as $memo) {
@@ -62,27 +54,21 @@ class Mnemo_Api extends Horde_Registry_Api {
             try {
                 $GLOBALS['mnemo_shares']->removeShare($share);
             } catch (Horde_Share_Exception $e) {
-                $hasError = true;
-                Horde::logMessage($e->getMessage(), 'ERR');
+                Horde::logMessage($e, 'ERR');
+                throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user));
             }
         }
 
-        /* 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);
             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 {
-            return true;
+            throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user));
         }
     }
 
index 95ee7f8..9823538 100644 (file)
@@ -230,29 +230,22 @@ class Nag_Application extends Horde_Registry_Application
      *
      * @param string $user  Name of user to remove data for.
      *
-     * @return mixed  true on success | PEAR_Error on failure
+     * @throws Nag_Exception
      */
     public function removeUserData($user)
     {
-        if (!$GLOBALS['registry']->isAdmin() && $user != $GLOBALS['registry']->getAuth()) {
-            return PEAR::raiseError(_("You are not allowed to remove user data."));
-        }
-
-        /* Error flag */
-        $hasError = false;
-
         /* Get the share for later deletion */
         try {
             $share = $GLOBALS['nag_shares']->getShare($user);
         } catch (Horde_Share_Exception $e) {
-            Horde::logMessage($e->getMessage(), 'ERR');
+            Horde::logMessage($e, 'ERR');
         }
 
         /* Get the list of all tasks */
         $tasks = Nag::listTasks(null, null, null, $user, 1);
         if ($tasks instanceof PEAR_Error) {
-            $hasError = true;
-            Horde::logMessage($share, 'ERR');
+            Horde::logMessage($tasks, 'ERR');
+            throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
         } else {
             $uids = array();
             $tasks->reset();
@@ -266,14 +259,13 @@ class Nag_Application extends Horde_Registry_Application
             }
         }
 
-
         /* ...and finally, delete the actual share */
         if (!empty($share)) {
             try {
                 $GLOBALS['nag_shares']->removeShare($share);
             } catch (Horde_Share_Exception $e) {
-                $hasError = true;
-                Horde::logMessage($result, 'ERR');
+                Horde::logMessage($e, 'ERR');
+                throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
             }
         }
 
@@ -284,14 +276,8 @@ class Nag_Application extends Horde_Registry_Application
                $share->removeUser($user);
             }
         } catch (Horde_Share_Exception $e) {
-            $hasError = true;
-            Horde::logMessage($shares, 'ERR');
-        }
-
-        if ($hasError) {
-            return PEAR::raiseError(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
-        } else {
-            return true;
+            Horde::logMessage($e, 'ERR');
+            throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
         }
     }
 
index 579d486..efa52a4 100644 (file)
@@ -387,18 +387,12 @@ class Turba_Application extends Horde_Registry_Application
      *
      * @param string $user  Name of user to remove data for.
      *
-     * @throws Horde_Exception
+     * @throws Turba_Exception
      */
     public function removeUserData($user)
     {
-        if (!$GLOBALS['registry']->isAdmin() &&
-            ($user != $GLOBALS['registry']->getAuth())) {
-            throw new Horde_Exception(_("You are not allowed to remove user data."));
-        }
-
         /* We need a clean copy of the $cfgSources array here.*/
         require TURBA_BASE . '/config/sources.php';
-        $hasError = false;
 
         foreach ($cfgSources as $source) {
             if (empty($source['use_shares'])) {
@@ -407,57 +401,57 @@ class Turba_Application extends Horde_Registry_Application
                     $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
                 } catch (Turba_Exception $e) {
                     Horde::logMessage($e, 'ERR');
-                    $hasError = true;
-                    continue;
+                    throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
                 }
 
                 try {
                     $driver->removeUserData($user);
                 } catch (Turba_Exception $e) {
                     Horde::logMessage($e, 'ERR');
+                    throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
                 }
             }
         }
 
         /* Only attempt share removal if we have shares configured */
-        if (!empty($_SESSION['turba']['has_share'])) {
-            $shares = $GLOBALS['turba_shares']->listShares(
-                $user, Horde_Perms::EDIT, $user);
+        if (empty($_SESSION['turba']['has_share'])) {
+            return;
+        }
 
-            /* Look for the deleted user's default share and remove it */
-            foreach ($shares as $share) {
-                $params = @unserialize($share->get('params'));
-                /* Only attempt to delete the user's default share */
-                if (!empty($params['default'])) {
-                    $config = Turba::getSourceFromShare($share);
-                    try {
-                        $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($config);
-                    } catch (Turba_Exception $e) {
-                        continue;
-                    }
+        $shares = $GLOBALS['turba_shares']->listShares($user, Horde_Perms::EDIT, $user);
 
-                    try {
-                        $driver->removeUserData($user);
-                    } catch (Turba_Exception $e) {
-                        Horde::logMessage($e, 'ERR');
-                        $hasError = true;
-                    }
+        /* Look for the deleted user's default share and remove it */
+        foreach ($shares as $share) {
+            $params = @unserialize($share->get('params'));
+
+            /* Only attempt to delete the user's default share */
+            if (!empty($params['default'])) {
+                $config = Turba::getSourceFromShare($share);
+                try {
+                    $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($config);
+                } catch (Turba_Exception $e) {
+                    continue;
                 }
-            }
 
-            /* 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);
+                try {
+                    $driver->removeUserData($user);
+                } catch (Turba_Exception $e) {
+                    Horde::logMessage($e, 'ERR');
+                    throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
                 }
-            } catch (Horde_Share_Exception $e) {
-                Horde::logMessage($e, 'ERR');
             }
         }
 
-        if ($hasError) {
-            throw new Horde_Exception(sprintf(_("There was an error removing an address book for %s"), $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');
+            throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
         }
     }