Avoid calling push/popApp() outside of Horde_Registry::
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 01:01:45 +0000 (18:01 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 01:56:05 +0000 (18:56 -0700)
framework/Alarm/Alarm.php
framework/Core/lib/Horde/Registry.php

index f01a947..8d9106b 100644 (file)
@@ -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);
             }
         }
 
index 8992e4d..976dedd 100644 (file)
@@ -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:
+     * <pre>
+     * 'noperms' - (boolean) If true, don't check the perms.
+     * </pre>
      *
      * @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;
     }