Move removeUserData() into Horde_Registry_Application
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 11 Aug 2009 21:36:20 +0000 (15:36 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 11 Aug 2009 21:36:20 +0000 (15:36 -0600)
folks/lib/Api.php
folks/lib/Application.php
ingo/lib/Api.php
ingo/lib/Application.php
kronolith/lib/Api.php
kronolith/lib/Application.php
nag/lib/Api.php
nag/lib/Application.php
turba/lib/Api.php
turba/lib/Application.php

index c08c91e..5f3d82c 100644 (file)
@@ -366,16 +366,4 @@ class Folks_Api extends Horde_Registry_Api
         return $GLOBALS['folks_driver']->isOnline($user);
     }
 
-    /**
-     * Deletes a user and its data
-     *
-     * @param string $userId  The userId to delete.
-     *
-     * @return boolean  True on success or a PEAR_Error object on failure.
-     */
-    public function removeUserData($user = null)
-    {
-        return $this->removeUser($user);
-    }
-
 }
index 6c8f0af..2aed44a 100644 (file)
@@ -96,4 +96,17 @@ class Folks_Application extends Horde_Registry_Application
         return $GLOBALS['folks_driver']->deleteUser($userId);
     }
 
+
+    /**
+     * Deletes a user and its data
+     *
+     * @param string $userId  The userId to delete.
+     *
+     * @return boolean  True on success or a PEAR_Error object on failure.
+     */
+    public function removeUserData($user = null)
+    {
+        return $this->authRemoveUser($user);
+    }
+
 }
index 0724132..ff7c7f1 100644 (file)
@@ -23,68 +23,6 @@ class Ingo_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
-     */
-    public function removeUserData($user)
-    {
-        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
-            return PEAR::raiseError(_("You are not allowed to remove user data."));
-        }
-
-        require_once dirname(__FILE__) . '/../lib/base.php';
-
-        /* Remove all filters/rules owned by the user. */
-        $result = $GLOBALS['ingo_storage']->removeUserData($user);
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $result;
-        }
-
-        /* Now remove all shares owned by the user. */
-        if (!empty($GLOBALS['ingo_shares'])) {
-            /* Get the user's default share. */
-            $share = $GLOBALS['ingo_shares']->getShare($user);
-            if (is_a($share, 'PEAR_Error')) {
-                Horde::logMessage($share, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $share;
-            } else {
-                $result = $GLOBALS['ingo_shares']->removeShare($share);
-                if (is_a($result, 'PEAR_Error')) {
-                    Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-                    return $result;
-                }
-            }
-
-            /* Get a list of all shares this user has perms to and remove the
-             * perms. */
-            $shares = $GLOBALS['ingo_shares']->listShares($user);
-            if (is_a($shares, 'PEAR_Error')) {
-                Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
-            foreach ($shares as $share) {
-                $share->removeUser($user);
-            }
-
-            /* Get a list of all shares this user owns and has perms to delete
-             * and remove them. */
-            $shares = $GLOBALS['ingo_shares']->listShares($user, PERMS_DELETE, $user);
-            if (is_a($shares, 'PEAR_Error')) {
-                Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $shares;
-            }
-            foreach ($shares as $share) {
-                $GLOBALS['ingo_shares']->removeShare($share);
-            }
-        }
-
-        return true;
-    }
-
-    /**
      * Add addresses to the blacklist.
      *
      * @param string $addresses  The addresses to add to the blacklist.
index 7191ba2..55f7bd2 100644 (file)
@@ -49,4 +49,66 @@ class Ingo_Application extends Horde_Registry_Application
         return Ingo::getMenu();
     }
 
+    /**
+     * Removes user data.
+     *
+     * @param string $user  Name of user to remove data for.
+     *
+     * @return mixed  true on success | PEAR_Error on failure
+     */
+    public function removeUserData($user)
+    {
+        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
+            return PEAR::raiseError(_("You are not allowed to remove user data."));
+        }
+
+        require_once dirname(__FILE__) . '/../lib/base.php';
+
+        /* Remove all filters/rules owned by the user. */
+        $result = $GLOBALS['ingo_storage']->removeUserData($user);
+        if (is_a($result, 'PEAR_Error')) {
+            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+            return $result;
+        }
+
+        /* Now remove all shares owned by the user. */
+        if (!empty($GLOBALS['ingo_shares'])) {
+            /* Get the user's default share. */
+            $share = $GLOBALS['ingo_shares']->getShare($user);
+            if (is_a($share, 'PEAR_Error')) {
+                Horde::logMessage($share, __FILE__, __LINE__, PEAR_LOG_ERR);
+                return $share;
+            } else {
+                $result = $GLOBALS['ingo_shares']->removeShare($share);
+                if (is_a($result, 'PEAR_Error')) {
+                    Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+                    return $result;
+                }
+            }
+
+            /* Get a list of all shares this user has perms to and remove the
+             * perms. */
+            $shares = $GLOBALS['ingo_shares']->listShares($user);
+            if (is_a($shares, 'PEAR_Error')) {
+                Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
+            }
+            foreach ($shares as $share) {
+                $share->removeUser($user);
+            }
+
+            /* Get a list of all shares this user owns and has perms to delete
+             * and remove them. */
+            $shares = $GLOBALS['ingo_shares']->listShares($user, PERMS_DELETE, $user);
+            if (is_a($shares, 'PEAR_Error')) {
+                Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
+                return $shares;
+            }
+            foreach ($shares as $share) {
+                $GLOBALS['ingo_shares']->removeShare($share);
+            }
+        }
+
+        return true;
+    }
+
 }
index 2e104ab..da35a5d 100644 (file)
@@ -19,70 +19,6 @@ class Kronolith_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
-     */
-    public function removeUserData($user)
-    {
-        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
-            return PEAR::raiseError(_("You are not allowed to remove user data."));
-        }
-
-        $no_maint = true;
-        require_once dirname(__FILE__) . '/base.php';
-
-        /* Remove all events owned by the user in all calendars. */
-        $result = Kronolith::getDriver()->removeUserData($user);
-
-        /* Now delete history as well. */
-        $history = Horde_History::singleton();
-        if (method_exists($history, 'removeByParent')) {
-            $histories = $history->removeByParent('kronolith:' . $user);
-        } else {
-            /* Remove entries 100 at a time. */
-            $all = $history->getByTimestamp('>', 0, array(), 'kronolith:' . $user);
-            if (is_a($all, 'PEAR_Error')) {
-                Horde::logMessage($all, __FILE__, __LINE__, PEAR_LOG_ERR);
-            } else {
-                $all = array_keys($all);
-                while (count($d = array_splice($all, 0, 100)) > 0) {
-                    $history->removebyNames($d);
-                }
-            }
-        }
-
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-
-        /* Get the user's default share */
-        $share = $GLOBALS['kronolith_shares']->getShare($user);
-        if (is_a($share, 'PEAR_Error')) {
-            Horde::logMessage($share, __FILE__, __LINE__, PEAR_LOG_ERR);
-        } else {
-            $result = $GLOBALS['kronolith_shares']->removeShare($share);
-            if (is_a($result, 'PEAR_Error')) {
-                $hasError = true;
-                Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
-        }
-
-        /* Get a list of all shares this user has perms to and remove the perms */
-        $shares = $GLOBALS['kronolith_shares']->listShares($user);
-        if (is_a($shares, 'PEAR_Error')) {
-            Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
-        }
-        foreach ($shares as $share) {
-            $share->removeUser($user);
-        }
-
-        return true;
-    }
-
-    /**
      * Returns the share helper prefix
      *
      * @return string
index 1152fe2..0f11b22 100644 (file)
@@ -252,4 +252,68 @@ class Kronolith_Application extends Horde_Registry_Application
         $GLOBALS['prefs']->setValue('fb_cals', serialize($fb_calsFiltered));
     }
 
+    /**
+     * Removes user data.
+     *
+     * @param string $user  Name of user to remove data for.
+     *
+     * @return mixed  true on success | PEAR_Error on failure
+     */
+    public function removeUserData($user)
+    {
+        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
+            return PEAR::raiseError(_("You are not allowed to remove user data."));
+        }
+
+        $no_maint = true;
+        require_once dirname(__FILE__) . '/base.php';
+
+        /* Remove all events owned by the user in all calendars. */
+        $result = Kronolith::getDriver()->removeUserData($user);
+
+        /* Now delete history as well. */
+        $history = Horde_History::singleton();
+        if (method_exists($history, 'removeByParent')) {
+            $histories = $history->removeByParent('kronolith:' . $user);
+        } else {
+            /* Remove entries 100 at a time. */
+            $all = $history->getByTimestamp('>', 0, array(), 'kronolith:' . $user);
+            if (is_a($all, 'PEAR_Error')) {
+                Horde::logMessage($all, __FILE__, __LINE__, PEAR_LOG_ERR);
+            } else {
+                $all = array_keys($all);
+                while (count($d = array_splice($all, 0, 100)) > 0) {
+                    $history->removebyNames($d);
+                }
+            }
+        }
+
+        if (is_a($result, 'PEAR_Error')) {
+            return $result;
+        }
+
+        /* Get the user's default share */
+        $share = $GLOBALS['kronolith_shares']->getShare($user);
+        if (is_a($share, 'PEAR_Error')) {
+            Horde::logMessage($share, __FILE__, __LINE__, PEAR_LOG_ERR);
+        } else {
+            $result = $GLOBALS['kronolith_shares']->removeShare($share);
+            if (is_a($result, 'PEAR_Error')) {
+                $hasError = true;
+                Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+            }
+        }
+
+        /* Get a list of all shares this user has perms to and remove the perms */
+        $shares = $GLOBALS['kronolith_shares']->listShares($user);
+        if (is_a($shares, 'PEAR_Error')) {
+            Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
+        }
+        foreach ($shares as $share) {
+            $share->removeUser($user);
+        }
+
+        return true;
+    }
+
 }
index cb74fde..c524bb9 100644 (file)
@@ -19,92 +19,6 @@ class Nag_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
-     */
-    public function removeUserData($user)
-    {
-        require_once dirname(__FILE__) . '/base.php';
-
-        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
-            return PEAR::raiseError(_("You are not allowed to remove user data."));
-        }
-
-        /* Error flag */
-        $hasError = false;
-
-        /* Get the share for later deletion */
-        $share = $GLOBALS['nag_shares']->getShare($user);
-        if(is_a($share, 'PEAR_Error')) {
-            Horde::logMessage($share->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-            unset($share);
-        } else {
-            /* Get the list of all tasks */
-            $tasks = Nag::listTasks(null, null, null, $user, 1);
-            if (is_a($tasks, 'PEAR_Error')) {
-                $hasError = true;
-                Horde::logMessage($share->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-            } else {
-                $uids = array();
-                $tasks->reset();
-                while ($task = $tasks->each()) {
-                    $uids[] = $task->uid;
-                }
-
-                /* ... and delete them. */
-                foreach ($uids as $uid) {
-                    $this->delete($uid);
-                }
-            }
-        }
-
-        /* Now delete history as well. */
-        $history = Horde_History::singleton();
-        if (method_exists($history, 'removeByParent')) {
-            $histories = $history->removeByParent('nag:' . $user);
-        } else {
-            /* Remove entries 100 at a time. */
-            $all = $history->getByTimestamp('>', 0, array(), 'nag:' . $user);
-            if (is_a($all, 'PEAR_Error')) {
-                Horde::logMessage($all, __FILE__, __LINE__, PEAR_LOG_ERR);
-            } else {
-                $all = array_keys($all);
-                while (count($d = array_splice($all, 0, 100)) > 0) {
-                    $history->removebyNames($d);
-                }
-            }
-        }
-
-        /* ...and finally, delete the actual share */
-        if (!empty($share)) {
-            $result = $GLOBALS['nag_shares']->removeShare($share);
-            if (is_a($result, 'PEAR_Error')) {
-                $hasError = true;
-                Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
-        }
-
-        /* Now remove perms for this user from all other shares */
-        $shares = $GLOBALS['nag_shares']->listShares($user);
-        if (is_a($shares, 'PEAR_Error')) {
-            $hasError = true;
-            Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
-        }
-        foreach ($shares as $share) {
-            $share->removeUser($user);
-        }
-
-        if ($hasError) {
-            return PEAR::raiseError(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
-        } else {
-            return true;
-        }
-    }
-
-    /**
      * Retrieves the current user's task list from storage.
      *
      * This function will also sort the resulting list, if requested.
index 526eb94..2a202c3 100644 (file)
@@ -73,4 +73,90 @@ class Nag_Application extends Horde_Registry_Application
         return Nag::getMenu();
     }
 
+    /**
+     * Removes user data.
+     *
+     * @param string $user  Name of user to remove data for.
+     *
+     * @return mixed  true on success | PEAR_Error on failure
+     */
+    public function removeUserData($user)
+    {
+        require_once dirname(__FILE__) . '/base.php';
+
+        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
+            return PEAR::raiseError(_("You are not allowed to remove user data."));
+        }
+
+        /* Error flag */
+        $hasError = false;
+
+        /* Get the share for later deletion */
+        $share = $GLOBALS['nag_shares']->getShare($user);
+        if(is_a($share, 'PEAR_Error')) {
+            Horde::logMessage($share->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+            unset($share);
+        } else {
+            /* Get the list of all tasks */
+            $tasks = Nag::listTasks(null, null, null, $user, 1);
+            if (is_a($tasks, 'PEAR_Error')) {
+                $hasError = true;
+                Horde::logMessage($share->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+            } else {
+                $uids = array();
+                $tasks->reset();
+                while ($task = $tasks->each()) {
+                    $uids[] = $task->uid;
+                }
+
+                /* ... and delete them. */
+                foreach ($uids as $uid) {
+                    $this->delete($uid);
+                }
+            }
+        }
+
+        /* Now delete history as well. */
+        $history = Horde_History::singleton();
+        if (method_exists($history, 'removeByParent')) {
+            $histories = $history->removeByParent('nag:' . $user);
+        } else {
+            /* Remove entries 100 at a time. */
+            $all = $history->getByTimestamp('>', 0, array(), 'nag:' . $user);
+            if (is_a($all, 'PEAR_Error')) {
+                Horde::logMessage($all, __FILE__, __LINE__, PEAR_LOG_ERR);
+            } else {
+                $all = array_keys($all);
+                while (count($d = array_splice($all, 0, 100)) > 0) {
+                    $history->removebyNames($d);
+                }
+            }
+        }
+
+        /* ...and finally, delete the actual share */
+        if (!empty($share)) {
+            $result = $GLOBALS['nag_shares']->removeShare($share);
+            if (is_a($result, 'PEAR_Error')) {
+                $hasError = true;
+                Horde::logMessage($result->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+            }
+        }
+
+        /* Now remove perms for this user from all other shares */
+        $shares = $GLOBALS['nag_shares']->listShares($user);
+        if (is_a($shares, 'PEAR_Error')) {
+            $hasError = true;
+            Horde::logMessage($shares, __FILE__, __LINE__, PEAR_LOG_ERR);
+        }
+        foreach ($shares as $share) {
+            $share->removeUser($user);
+        }
+
+        if ($hasError) {
+            return PEAR::raiseError(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user));
+        } else {
+            return true;
+        }
+    }
+
 }
index 21dffdb..ec6e00c 100644 (file)
@@ -28,79 +28,6 @@ class Turba_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
-     */
-    public function removeUserData($user)
-    {
-        require_once dirname(__FILE__) . '/base.php';
-
-        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
-            return PEAR::raiseError(_("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'])) {
-                // Shares not enabled for this source
-                $driver = Turba_Driver::singleton($source);
-                if (is_a($driver, 'PEAR_Error')) {
-                    Horde::logMessage($driver, __FILE__, __LINE__, PEAR_LOG_ERR);
-                    $hasError = true;
-                } else {
-                    $result = $driver->removeUserData($user);
-                    if (is_a($result, 'PEAR_Error')) {
-                        Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-                    }
-                }
-            }
-        }
-
-        /* Only attempt share removal if we have shares configured */
-        if (!empty($_SESSION['turba']['has_share'])) {
-            $shares = &$GLOBALS['turba_shares']->listShares(
-                $user, PERMS_EDIT, $user);
-
-            /* 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);
-                    $driver = Turba_Driver::singleton($config);
-                    $result = $driver->removeUserData($user);
-                    if (is_a($result, 'PEAR_Error')) {
-                        Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-                        $hasError = true;
-                    }
-                }
-            }
-
-            /* 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, __FILE__, __LINE__, PEAR_LOG_ERR);
-            }
-            foreach ($shares as $share) {
-                $share->removeUser($user);
-            }
-
-        }
-
-        if ($hasError) {
-            return PEAR::raiseError(sprintf(_("There was an error removing an address book for %s"), $user));
-        }
-
-        return true;
-    }
-
-    /**
      * Callback for comment API
      *
      * @param integer $id  Internal data identifier
index de2d8cd..0e6eb43 100644 (file)
@@ -117,4 +117,77 @@ class Turba_Application extends Horde_Registry_Application
         return Turba::getMenu();
     }
 
+    /**
+     * Removes user data.
+     *
+     * @param string $user  Name of user to remove data for.
+     *
+     * @return mixed  true on success | PEAR_Error on failure
+     */
+    public function removeUserData($user)
+    {
+        require_once dirname(__FILE__) . '/base.php';
+
+        if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) {
+            return PEAR::raiseError(_("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'])) {
+                // Shares not enabled for this source
+                $driver = Turba_Driver::singleton($source);
+                if (is_a($driver, 'PEAR_Error')) {
+                    Horde::logMessage($driver, __FILE__, __LINE__, PEAR_LOG_ERR);
+                    $hasError = true;
+                } else {
+                    $result = $driver->removeUserData($user);
+                    if (is_a($result, 'PEAR_Error')) {
+                        Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+                    }
+                }
+            }
+        }
+
+        /* Only attempt share removal if we have shares configured */
+        if (!empty($_SESSION['turba']['has_share'])) {
+            $shares = &$GLOBALS['turba_shares']->listShares(
+                $user, PERMS_EDIT, $user);
+
+            /* 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);
+                    $driver = Turba_Driver::singleton($config);
+                    $result = $driver->removeUserData($user);
+                    if (is_a($result, 'PEAR_Error')) {
+                        Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+                        $hasError = true;
+                    }
+                }
+            }
+
+            /* 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, __FILE__, __LINE__, PEAR_LOG_ERR);
+            }
+            foreach ($shares as $share) {
+                $share->removeUser($user);
+            }
+
+        }
+
+        if ($hasError) {
+            return PEAR::raiseError(sprintf(_("There was an error removing an address book for %s"), $user));
+        }
+
+        return true;
+    }
+
 }