From: Michael M Slusarz Date: Wed, 3 Feb 2010 01:01:45 +0000 (-0700) Subject: Avoid calling push/popApp() outside of Horde_Registry:: X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ab24638dc57aad9c18226592a5cebffe3911179a;p=horde.git Avoid calling push/popApp() outside of Horde_Registry:: --- diff --git a/framework/Alarm/Alarm.php b/framework/Alarm/Alarm.php index f01a9479d..8d9106bf9 100644 --- a/framework/Alarm/Alarm.php +++ b/framework/Alarm/Alarm.php @@ -188,55 +188,37 @@ class Horde_Alarm { return; } - $apps = $GLOBALS['registry']->listApps(null, false, Horde_Perms::READ); - if (is_a($apps, 'PEAR_Error')) { - return false; - } - foreach ($apps as $app) { - if ($GLOBALS['registry']->hasMethod('listAlarms', $app)) { + foreach ($GLOBALS['registry']->listApps(null, false, Horde_Perms::READ) as $app) { + if (!$GLOBALS['registry']->hasMethod('listAlarms', $app)) { + continue; + } + + /* Preload alarms that happen in the next ttl seconds. */ + if ($preload) { try { - $pushed = $GLOBALS['registry']->pushApp($app, array('check_perms' => false)); + $alarms = $GLOBALS['registry']->callByPackage($app, 'listAlarms', array(time() + $this->_params['ttl'], $user), array('noperms' => true)); } catch (Horde_Exception $e) { - Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); continue; } - /* Preload alarms that happen in the next ttl seconds. */ - if ($preload) { - try { - $alarms = $GLOBALS['registry']->callByPackage($app, 'listAlarms', array(time() + $this->_params['ttl'], $user)); - } catch (Horde_Exception $e) { - if ($pushed) { - $GLOBALS['registry']->popApp(); - } - continue; - } - } else { - $alarms = array(); - } - - /* Load current alarms if no preloading requested or if this - * is the first call in this session. */ - if (!$preload || !isset($_SESSION['horde']['alarm']['loaded'])) { - try { - $app_alarms = $GLOBALS['registry']->callByPackage($app, 'listAlarms', array(time(), $user)); - } catch (Horde_Exception $e) { - Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); - $app_alarms = array(); - } - $alarms = array_merge($alarms, $app_alarms); - } - - if ($pushed) { - $GLOBALS['registry']->popApp(); - } + } else { + $alarms = array(); + } - if (empty($alarms)) { - continue; + /* Load current alarms if no preloading requested or if this + * is the first call in this session. */ + if (!$preload || + !isset($_SESSION['horde']['alarm']['loaded'])) { + try { + $app_alarms = $GLOBALS['registry']->callByPackage($app, 'listAlarms', array(time(), $user), array('noperms' => true)); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + $app_alarms = array(); } + $alarms = array_merge($alarms, $app_alarms); + } - foreach ($alarms as $alarm) { - $this->set($alarm); - } + foreach ($alarms as $alarm) { + $this->set($alarm); } } diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 8992e4dca..976dedd18 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -724,14 +724,19 @@ class Horde_Registry /** * Output the hook corresponding to the specific package named. * - * @param string $app The application being called. - * @param string $call The method to call. - * @param array $args Arguments to the method. + * @param string $app The application being called. + * @param string $call The method to call. + * @param array $args Arguments to the method. + * @param array $options Additional options: + *
+     * 'noperms' - (boolean) If true, don't check the perms.
+     * 
* * @return mixed TODO * @throws Horde_Exception */ - public function callByPackage($app, $call, $args = array()) + public function callByPackage($app, $call, $args = array(), + $options = array()) { /* Note: calling hasMethod() makes sure that we've cached * $app's services and included the API file, so we don't try @@ -751,10 +756,13 @@ class Horde_Registry /* Switch application contexts now, if necessary, before * including any files which might do it for us. Return an * error immediately if pushApp() fails. */ - $pushed = $this->pushApp($app, array('check_perms' => !in_array($call, $this->_cache['api'][$app]['noperms']))); + $pushed = $this->pushApp($app, array('check_perms' => !in_array($call, $this->_cache['api'][$app]['noperms']) && empty($options['noperms']))); try { $result = call_user_func_array(array($api, $call), $args); + if ($result instanceof PEAR_Error) { + throw new Horde_Exception($result); + } } catch (Horde_Exception $e) { $result = $e; } @@ -765,12 +773,9 @@ class Horde_Registry $this->popApp(); } - if ($result instanceof Exception) { + if ($result instanceof Horde_Exception) { throw $e; } - if (is_a($result, 'PEAR_Error')) { - throw new Horde_Exception($result); - } return $result; }