From 1384a4a59894e9b48cb82ffaf3e57b778c76e91e Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 11 Aug 2009 15:36:20 -0600 Subject: [PATCH] Move removeUserData() into Horde_Registry_Application --- folks/lib/Api.php | 12 ------ folks/lib/Application.php | 13 +++++++ ingo/lib/Api.php | 62 ------------------------------- ingo/lib/Application.php | 62 +++++++++++++++++++++++++++++++ kronolith/lib/Api.php | 64 -------------------------------- kronolith/lib/Application.php | 64 ++++++++++++++++++++++++++++++++ nag/lib/Api.php | 86 ------------------------------------------- nag/lib/Application.php | 86 +++++++++++++++++++++++++++++++++++++++++++ turba/lib/Api.php | 73 ------------------------------------ turba/lib/Application.php | 73 ++++++++++++++++++++++++++++++++++++ 10 files changed, 298 insertions(+), 297 deletions(-) diff --git a/folks/lib/Api.php b/folks/lib/Api.php index c08c91ef1..5f3d82cfd 100644 --- a/folks/lib/Api.php +++ b/folks/lib/Api.php @@ -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); - } - } diff --git a/folks/lib/Application.php b/folks/lib/Application.php index 6c8f0afbf..2aed44a14 100644 --- a/folks/lib/Application.php +++ b/folks/lib/Application.php @@ -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); + } + } diff --git a/ingo/lib/Api.php b/ingo/lib/Api.php index 0724132d0..ff7c7f141 100644 --- a/ingo/lib/Api.php +++ b/ingo/lib/Api.php @@ -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. diff --git a/ingo/lib/Application.php b/ingo/lib/Application.php index 7191ba2ae..55f7bd29d 100644 --- a/ingo/lib/Application.php +++ b/ingo/lib/Application.php @@ -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; + } + } diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index 2e104abff..da35a5d60 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -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 diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index 1152fe2c2..0f11b2221 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -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; + } + } diff --git a/nag/lib/Api.php b/nag/lib/Api.php index cb74fde11..c524bb949 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -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. diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 526eb94f8..2a202c328 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -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; + } + } + } diff --git a/turba/lib/Api.php b/turba/lib/Api.php index 21dffdba2..ec6e00c7a 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -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 diff --git a/turba/lib/Application.php b/turba/lib/Application.php index de2d8cde0..0e6eb4371 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -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; + } + } -- 2.11.0