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);
}
}
/**
* 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
/* 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;
}
$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;
}