From: Michael M Slusarz Date: Wed, 9 Jun 2010 04:21:58 +0000 (-0600) Subject: Improvements to removeUserDataFromAllApplications() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8833a205a23668ee25146144822b83ea1ecb832f;p=horde.git Improvements to removeUserDataFromAllApplications() --- diff --git a/horde/lib/Api.php b/horde/lib/Api.php index 9a452047b..3c9203664 100644 --- a/horde/lib/Api.php +++ b/horde/lib/Api.php @@ -84,8 +84,8 @@ class Horde_Api extends Horde_Registry_Api * @param array $filter An array of the statuses that should be returned. * Defaults to non-hidden. * - * @return array List of apps registered with Horde. If no applications are - * defined returns an empty array. + * @return array List of apps registered with Horde. If no applications + * are defined returns an empty array. */ public function listApps($filter = null) { @@ -271,31 +271,27 @@ class Horde_Api extends Horde_Registry_Api */ public function removeUserDataFromAllApplications($user) { - if (!$GLOBALS['registry']->isAdmin() && $user != Auth::getAuth()) { + global $registry; + + if (!$registry->isAdmin() && ($user != $registry->getAuth())) { throw new Horde_Exception(_("You are not allowed to remove user data.")); } - /* Error flag */ - $haveError = false; + $errors = array(); - /* Get all APIs */ - $apis = $this->listAPIs(); - foreach ($apis as $api) { - if ($GLOBALS['registry']->hasAppMethod($api, 'removeUserData')) { - $result = $GLOBALS['registry']->callAppMethod($api, 'removeUserData', array('args' => array($user))); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, 'ERR'); - $haveError = true; + 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; } } } - $result = $this->removeUserData($user); - if (is_a($result, 'PEAR_Error')) { - $haveError = true; - } - if ($haveError) { - throw new Horde_Exception(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); + if (!empty($errors)) { + throw new Horde_Exception(sprintf(_("The following applications encountered errors removing user data: %s"), implode(', ', $errors))); } }