* @param string $type The service to display.
* <pre>
* TODO
- * 'ajax', 'cache', 'download', 'go', 'prefsapi'
+ * 'ajax', 'cache', 'download', 'go', 'logintasks', 'prefsapi'
* 'help', 'problem', 'logout', 'login', 'options'
* </pre>
* @param string $app The name of the current Horde application.
case 'login':
return self::url($webroot . '/login.php');
+ case 'logintasks':
+ return self::url($webroot . '/services/logintasks.php')->add('app', $app);
+
case 'options':
case 'prefsapi':
if (!in_array($GLOBALS['conf']['prefs']['driver'], array('', 'none'))) {
--- /dev/null
+<?php
+/**
+ * @category Horde
+ * @package Core
+ */
+class Horde_Core_Binder_LoginTasks implements Horde_Injector_Binder
+{
+ public function create(Horde_Injector $injector)
+ {
+ return new Horde_Core_Factory_LoginTasks($injector);
+ }
+
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based Horde_LoginTasks:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+
+/**
+ * A Horde_Injector:: based Horde_LoginTasks:: factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Core
+ */
+class Horde_Core_Factory_LoginTasks
+{
+ /**
+ * Instances.
+ *
+ * @var array
+ */
+ private $_instances = array();
+
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Return the Horde_LoginTasks:: instance.
+ *
+ * @param string $app The current application.
+ *
+ * @return Horde_LoginTasks The singleton instance.
+ */
+ public function getOb($app)
+ {
+ if (!isset($this->_instances[$app])) {
+ $this->_instances[$app] = new Horde_LoginTasks(new Horde_Core_LoginTasks_Backend_Horde($app));
+ }
+
+ return $this->_instances[$app];
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * This class provides the Horde specific implementation of the LoginTasks
+ * backend.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @category Horde
+ * @package Core
+ */
+class Horde_Core_LoginTasks_Backend_Horde extends Horde_LoginTasks_Backend
+{
+ /**
+ * The Horde application that is currently active.
+ *
+ * @var string
+ */
+ private $_app;
+
+ /**
+ * Constructor.
+ *
+ * @param string $app The currently active Horde application.
+ */
+ public function __construct($app)
+ {
+ $this->_app = $app;
+ }
+
+ /**
+ * Is the current session authenticated?
+ *
+ * @return boolean True if the user is authenticated, false otherwise.
+ */
+ public function isAuthenticated()
+ {
+ return (Horde_Auth::getAuth() !== false);
+ }
+
+ /**
+ * Retrieve a cached tasklist if it exists.
+ *
+ * @return Horde_LoginTasks_Tasklist|boolean The cached task list or
+ * false if no task list was
+ * cached.
+ */
+ public function getTasklistFromCache()
+ {
+ if (isset($_SESSION['horde_logintasks'][$this->_app])) {
+ return @unserialize($_SESSION['horde_logintasks'][$this->_app]);
+ }
+ return false;
+ }
+
+ /**
+ * Store a login tasklist in the cache.
+ *
+ * @param Horde_LoginTasks_Tasklist|boolean $tasklist The tasklist to be
+ * stored.
+ */
+ public function storeTasklistInCache($tasklist)
+ {
+ $_SESSION['horde_logintasks'][$this->_app] = serialize($tasklist);
+ }
+
+ /**
+ * Register the shutdown handler.
+ *
+ * @param array $shutdown The shutdown function.
+ */
+ public function registerShutdown($shutdown)
+ {
+ register_shutdown_function($shutdown);
+ }
+
+ /**
+ * Get the class names of the task classes that need to be performed.
+ *
+ * @return array An array of class names.
+ */
+ public function getTasks()
+ {
+ /* Add Horde tasks here if not yet run. */
+ $app_list = array($this->_app);
+ if (($this->_app != 'horde') &&
+ !isset($_SESSION['horde_logintasks']['horde'])) {
+ array_unshift($app_list, 'horde');
+ }
+
+ $tasks = array();
+
+ foreach ($app_list as $app) {
+ foreach (array_merge($GLOBALS['registry']->getAppDrivers($app, 'LoginTasks_SystemTask'), $GLOBALS['registry']->getAppDrivers($app, 'LoginTasks_Task')) as $val) {
+ $tasks[$val] = $app;
+ }
+ }
+
+ return $tasks;
+ }
+
+ /**
+ * Get the information about the last time the tasks were run. Array keys
+ * are app names, values are last run timestamps. Special key '_once'
+ * contains list of ONCE tasks previously run.
+ *
+ * @return array The information about the last time the tasks were run.
+ */
+ public function getLastRun()
+ {
+ $lasttask_pref = @unserialize($GLOBALS['prefs']->getValue('last_logintasks'));
+ if (!is_array($lasttask_pref)) {
+ $lasttask_pref = array();
+ }
+
+ return $lasttask_pref;
+ }
+
+ /**
+ * Store the information about the last time the tasks were run.
+ *
+ * @param array $last The information about the last time the tasks were
+ * run.
+ */
+ public function setLastRun(array $last)
+ {
+ $GLOBALS['prefs']->setValue('last_logintasks', serialize($last));
+ }
+
+ /**
+ * Mark the current time as time the login tasks were run for the last
+ * time.
+ */
+ public function markLastRun()
+ {
+ $lasttasks = $this->getLastRun();
+ $lasttasks[$this->_app] = time();
+ if (($this->_app != 'horde') &&
+ !isset($_SESSION['horde_logintasks']['horde'])) {
+ $lasttasks['horde'] = time();
+ $_SESSION['horde_logintasks']['horde'] = true;
+ }
+ $GLOBALS['prefs']->setValue('last_logintasks', serialize($lasttasks));
+ }
+
+ /**
+ * Redirect to the given URL.
+ *
+ * @param string $url The URL to redirect to.
+ */
+ public function redirect($url)
+ {
+ header('Location: ' . $url);
+ exit;
+ }
+
+ /**
+ * Return the URL of the login tasks view.
+ *
+ * @param array $tasks The tasks to be displayed next.
+ *
+ * @return string The URL of the login tasks view.
+ */
+ public function getLoginTasksUrl(array $tasks = null)
+ {
+ return Horde::getServiceLink('logintasks', $this->_app);
+ }
+}
'Horde_History' => new Horde_Core_Binder_History(),
'Horde_Lock' => new Horde_Core_Binder_Lock(),
'Horde_Log_Logger' => new Horde_Core_Binder_Logger(),
+ 'Horde_LoginTasks' => new Horde_Core_Binder_LoginTasks(),
'Horde_Mail' => new Horde_Core_Binder_Mail(),
'Horde_Memcache' => new Horde_Core_Binder_Memcache(),
'Horde_Notification' => new Horde_Core_Binder_Notification(),
/* Do login tasks. */
if ($checkPerms) {
- $tasks = Horde_LoginTasks::singleton($app);
+ $tasks = $GLOBALS['injector']->getInstance('Horde_LoginTasks')->getOb($app);
if (!empty($options['logintasks'])) {
$tasks->runTasks(false, Horde::selfUrl(true, true, true));
}
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Import perms UI handling class from horde/Perms.
+ <notes>* Import Horde backend driver from horde/LoginTasks.
+ * Import perms UI handling class from horde/Perms.
* Import prefs UI handling class from horde/Prefs.
* Convert from PEAR Log to Horde_Log for logging.
* Add Horde_Themes:: class.
<file name="Identity.php" role="php" />
<file name="Lock.php" role="php" />
<file name="Logger.php" role="php" />
+ <file name="LoginTasks.php" role="php" />
<file name="Mail.php" role="php" />
<file name="Memcache.php" role="php" />
<file name="Notification.php" role="php" />
<file name="KolabServer.php" role="php" />
<file name="KolabSession.php" role="php" />
<file name="KolabStorage.php" role="php" />
+ <file name="LoginTasks.php" role="php" />
</dir> <!-- /lib/Horde/Core/Factory -->
<dir name="Log">
<file name="Logger.php" role="php" />
</dir> <!-- /lib/Horde/Core/Log -->
+ <dir name="LoginTasks">
+ <dir name="Backend">
+ <file name="Horde.php" role="php" />
+ </dir> <!-- /lib/Horde/Core/LoginTasks/Backend -->
+ </dir> <!-- /lib/Horde/Core/LoginTasks -->
<dir name="Notification">
<file name="Hordelog.php" role="php" />
<file name="Status.php" role="php" />
<channel>pear.horde.org</channel>
</package>
<package>
+ <name>LoginTasks</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Prefs</name>
<channel>pear.horde.org</channel>
</package>
<install name="lib/Horde/Core/Binder/Identity.php" as="Horde/Core/Binder/Identity.php" />
<install name="lib/Horde/Core/Binder/Lock.php" as="Horde/Core/Binder/Lock.php" />
<install name="lib/Horde/Core/Binder/Logger.php" as="Horde/Core/Binder/Logger.php" />
+ <install name="lib/Horde/Core/Binder/LoginTasks.php" as="Horde/Core/Binder/LoginTasks.php" />
<install name="lib/Horde/Core/Binder/Mail.php" as="Horde/Core/Binder/Mail.php" />
<install name="lib/Horde/Core/Binder/Memcache.php" as="Horde/Core/Binder/Memcache.php" />
<install name="lib/Horde/Core/Binder/Notification.php" as="Horde/Core/Binder/Notification.php" />
<install name="lib/Horde/Core/Factory/KolabServer.php" as="Horde/Core/Factory/KolabServer.php" />
<install name="lib/Horde/Core/Factory/KolabSession.php" as="Horde/Core/Factory/KolabSession.php" />
<install name="lib/Horde/Core/Factory/KolabStorage.php" as="Horde/Core/Factory/KolabStorage.php" />
+ <install name="lib/Horde/Core/Factory/LoginTasks.php" as="Horde/Core/Factory/LoginTasks.php" />
<install name="lib/Horde/Core/Log/Logger.php" as="Horde/Core/Log/Logger.php" />
+ <install name="lib/Horde/Core/LoginTasks/Backend/Horde.php" as="Horde/Core/LoginTasks/Backend/Horde.php" />
<install name="lib/Horde/Core/Notification/Hordelog.php" as="Horde/Core/Notification/Hordelog.php" />
<install name="lib/Horde/Core/Notification/Status.php" as="Horde/Core/Notification/Status.php" />
<install name="lib/Horde/Core/Perms/Ui.php" as="Horde/Core/Perms/Ui.php" />
const PRIORITY_NORMAL = 2;
/**
- * Singleton instance.
- *
- * @var array
- */
- static protected $_instances = array();
-
- /**
* The Horde_LoginTasks_Backend object provides all utilities we need for
* handling the login tasks.
*
protected $_tasklist;
/**
- * Attempts to return a reference to a concrete Horde_LoginTasks
- * instance based on $app. It will only create a new instance
- * if no instance with the same parameters currently exists.
- *
- * This method must be invoked as:
- * $var = Horde_LoginTasks::singleton($app[, $params]);
- *
- * @param string $app See self::__construct().
- *
- * @return Horde_LoginTasks The singleton instance.
- */
- static public function singleton($app)
- {
- if (empty(self::$_instances[$app])) {
- self::$_instances[$app] = new self(
- new Horde_LoginTasks_Backend_Horde(
- $GLOBALS['registry'],
- $GLOBALS['prefs'],
- $app
- )
- );
- }
-
- return self::$_instances[$app];
- }
-
- /**
* Constructor.
*
- * @param string $app The name of the Horde application.
+ * @param Horde_LoginTasks_Backend $backend The backend to use.
*/
public function __construct(Horde_LoginTasks_Backend $backend)
{
/**
* Is the current session authenticated?
*
- * @return boolean True if the user is authenticated, false otherwise.
+ * @return boolean True if the user is authenticated, false otherwise.
*/
abstract public function isAuthenticated();
/**
* Retrieve a cached tasklist if it exists.
*
- * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false
- * if no task list was cached.
+ * @return Horde_LoginTasks_Tasklist|boolean The cached task list or
+ * false if no task list was
+ * cached.
*/
abstract public function getTasklistFromCache();
/**
* Store a login tasklist in the cache.
*
- * @param Horde_LoginTasks_Tasklist|boolean The tasklist to be stored.
- *
- * @return NULL
+ * @param Horde_LoginTasks_Tasklist|boolean $tasklist The tasklist to be
+ * stored.
*/
abstract public function storeTasklistInCache($tasklist);
/**
* Register the shutdown handler.
*
- * @param array The shutdown function
- *
- * @return NULL
+ * @param array $shutdown The shutdown function.
*/
abstract public function registerShutdown($shutdown);
/**
* Get the class names of the task classes that need to be performed.
*
- * @return array An array of class names.
+ * @return array An array of class names.
*/
abstract public function getTasks();
* are app names, values are last run timestamps. Special key '_once'
* contains list of ONCE tasks previously run.
*
- * @return array The information about the last time the tasks were run.
+ * @return array The information about the last time the tasks were run.
*/
abstract public function getLastRun();
/**
* Store the information about the last time the tasks were run.
*
- * @param array $last The information about the last time the tasks were run.
- *
- * @return NULL
+ * @param array $last The information about the last time the tasks were
+ * run.
*/
abstract public function setLastRun(array $last);
/**
- * Mark the current time as time the login tasks were run for the last time.
- *
- * @return NULL
+ * Mark the current time as time the login tasks were run for the last
+ * time.
*/
abstract public function markLastRun();
/**
* Redirect to the given URL.
*
- * @param string $url The URL to redirect to.
- *
- * @return NULL
+ * @param string $url The URL to redirect to.
*/
abstract public function redirect($url);
/**
* Return the URL of the login tasks view.
*
- * @param array $tasks The tasks to be displayed next.
+ * @param array $tasks The tasks to be displayed next.
*
- * @return string The URL of the login tasks view
+ * @return string The URL of the login tasks view
*/
abstract public function getLoginTasksUrl(array $tasks = null);
-}
\ No newline at end of file
+}
+++ /dev/null
-<?php
-/**
- * The Horde_LoginTasks_Backend_Horde:: class provides the Horde specific
- * implementation of the LoginTasks backend
- *
- * Copyright 2001-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Michael Slusarz <slusarz@horde.org>
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @package Horde_LoginTasks
- */
-class Horde_LoginTasks_Backend_Horde
-extends Horde_LoginTasks_Backend
-{
- /**
- * The Horde application that is currently active.
- *
- * @var string
- */
- private $_app;
-
- /**
- * The Horde registry.
- *
- * @var Horde_Registry
- */
- private $_registry;
-
- /**
- * The Horde preferences system
- *
- * @var Horde_Prefs
- */
- private $_prefs;
-
- /**
- * Constructor
- *
- * @param string $app The Horde application that is currently active.
- */
- public function __construct(
- Horde_Registry $registry,
- Horde_Prefs $prefs,
- $app
- ) {
- $this->_registry = $registry;
- $this->_prefs = $prefs;
- $this->_app = $app;
- }
-
- /**
- * Is the current session authenticated?
- *
- * @return boolean True if the user is authenticated, false otherwise.
- */
- public function isAuthenticated()
- {
- return (Horde_Auth::getAuth() !== false);
- }
-
- /**
- * Retrieve a cached tasklist if it exists.
- *
- * @return Horde_LoginTasks_Tasklist|boolean The cached task list or false
- * if no task list was cached.
- */
- public function getTasklistFromCache()
- {
- if (isset($_SESSION['horde_logintasks'][$this->_app])) {
- return @unserialize($_SESSION['horde_logintasks'][$this->_app]);
- }
- return false;
- }
-
- /**
- * Store a login tasklist in the cache.
- *
- * @param Horde_LoginTasks_Tasklist|boolean The tasklist to be stored.
- *
- * @return NULL
- */
- public function storeTasklistInCache($tasklist)
- {
- $_SESSION['horde_logintasks'][$this->_app] = serialize($tasklist);
- }
-
- /**
- * Register the shutdown handler.
- *
- * @param array The shutdown function
- *
- * @return NULL
- */
- public function registerShutdown($shutdown)
- {
- register_shutdown_function($shutdown);
- }
-
- /**
- * Get the class names of the task classes that need to be performed.
- *
- * @return array An array of class names.
- */
- public function getTasks()
- {
- /* Add Horde tasks here if not yet run. */
- $app_list = array($this->_app);
- if (($this->_app != 'horde') &&
- !isset($_SESSION['horde_logintasks']['horde'])) {
- array_unshift($app_list, 'horde');
- }
-
- $tasks = array();
-
- foreach ($app_list as $app) {
- foreach (array_merge($this->_registry->getAppDrivers($app, 'LoginTasks_SystemTask'), $this->_registry->getAppDrivers($app, 'LoginTasks_Task')) as $val) {
- $tasks[$val] = $app;
- }
- }
- return $tasks;
- }
-
- /**
- * Get the information about the last time the tasks were run. Array keys
- * are app names, values are last run timestamps. Special key '_once'
- * contains list of ONCE tasks previously run.
- *
- * @return array The information about the last time the tasks were run.
- */
- public function getLastRun()
- {
- $lasttask_pref = @unserialize($this->_prefs->getValue('last_logintasks'));
- if (!is_array($lasttask_pref)) {
- $lasttask_pref = array();
- }
- return $lasttask_pref;
- }
-
- /**
- * Store the information about the last time the tasks were run.
- *
- * @param array $last The information about the last time the tasks were run.
- *
- * @return NULL
- */
- public function setLastRun(array $last)
- {
- $this->_prefs->setValue('last_logintasks', serialize($last));
- }
-
- /**
- * Mark the current time as time the login tasks were run for the last time.
- *
- * @return NULL
- */
- public function markLastRun()
- {
- $lasttasks = $this->getLastRun();
- $lasttasks[$this->_app] = time();
- if (($this->_app != 'horde') &&
- !isset($_SESSION['horde_logintasks']['horde'])) {
- $lasttasks['horde'] = time();
- $_SESSION['horde_logintasks']['horde'] = true;
- }
- $this->_prefs->setValue('last_logintasks', serialize($lasttasks));
- }
-
- /**
- * Redirect to the given URL.
- *
- * @param string $url The URL to redirect to.
- *
- * @return NULL
- */
- public function redirect($url)
- {
- header('Location: ' . $url);
- exit;
- }
-
- /**
- * Return the URL of the login tasks view.
- *
- * @param array $tasks The tasks to be displayed next.
- *
- * @return string The URL of the login tasks view
- */
- public function getLoginTasksUrl(array $tasks = null)
- {
- return Horde::url(Horde_Util::addParameter($this->_registry->get('webroot', 'horde') . '/services/logintasks.php', array('app' => $this->_app)), true);
- }
-}
\ No newline at end of file
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
-* Added system tasks.
+ <notes>* Removed Core dependency.
+ * Added system tasks.
* Added ONCE interval.
* Renamed Maintenance:: -> Horde_LoginTasks::.
* Initial Horde 4 package.
<dir name="lib">
<dir name="Horde">
<dir name="LoginTasks">
- <dir name="Backend">
- <file name="Horde.php" role="php" />
- </dir> <!-- /lib/Horde/LoginTasks/Backend -->
<file name="Backend.php" role="php" />
<file name="SystemTask.php" role="php" />
<file name="Task.php" role="php" />
<channel>pear.horde.org</channel>
</package>
</required>
- <optional>
- <package>
- <name>Auth</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
- <name>Core</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
- <name>Prefs</name>
- <channel>pear.horde.org</channel>
- </package>
- </optional>
</dependencies>
<phprelease>
<filelist>
<install as="Horde/LoginTasks/SystemTask.php" name="lib/Horde/LoginTasks/SystemTask.php" />
<install as="Horde/LoginTasks/Task.php" name="lib/Horde/LoginTasks/Task.php" />
<install as="Horde/LoginTasks/Tasklist.php" name="lib/Horde/LoginTasks/Tasklist.php" />
- <install as="Horde/LoginTasks/Backend/Horde.php" name="lib/Horde/LoginTasks/Backend/Horde.php" />
<install as="Horde/LoginTasks/AllTests.php" name="test/Horde/LoginTasks/AllTests.php" />
<install as="Horde/LoginTasks/Autoload.php" name="test/Horde/LoginTasks/Autoload.php" />
<install as="Horde/LoginTasks/LoginTasksTest.php" name="test/Horde/LoginTasks/LoginTasksTest.php" />
$tasks = $this->_getLoginTasks(
array('Horde_LoginTasks_Stub_Year'), true, $date
);
- $tasks->runTasks();
$this->assertEquals(
array(),
Horde_LoginTasks_Stub_Task::$executed
public function testTasksThatRunOnceAreNotExecutedMoreThanOnce()
{
- $prefs = new Horde_LoginTasks_Stub_Prefs();
-
Horde_LoginTasks_Stub_Once::$executed = array();
$tasks = $this->_getLoginTasks(
- array('Horde_LoginTasks_Stub_Once'), true, false, $prefs
+ array('Horde_LoginTasks_Stub_Once'), true, false
);
$tasks->runTasks();
$this->assertEquals(
);
Horde_LoginTasks_Stub_Task::$executed = array();
- $date = getdate();
$tasks = $this->_getLoginTasks(
- array('Horde_LoginTasks_Stub_Once'), true, false, $prefs
+ array('Horde_LoginTasks_Stub_Once'), true, true
);
$tasks->runTasks();
$this->assertEquals(
public function testAllTasksGetRunIfNoTasksRequiresDisplay()
{
- $prefs = new Horde_LoginTasks_Stub_Prefs();
Horde_LoginTasks_Stub_Task::$executed = array();
$tasks = $this->_getLoginTasks(
array(
'Horde_LoginTasks_Stub_High',
),
true,
- false,
- $prefs
+ false
);
$tasks->runTasks();
- $v = $prefs->getValue('last_logintasks');
- $this->assertTrue(!empty($v));
+ $this->assertEquals(
+ array(
+ 'Horde_LoginTasks_Stub_High',
+ 'Horde_LoginTasks_Stub_Task'
+ ),
+ Horde_LoginTasks_Stub_Task::$executed
+ );
}
public function testTheLastTimeOfCompletingTheLoginTasksWillBeStoredOnceAllTasksWereExcecuted()
{
- $prefs = new Horde_LoginTasks_Stub_Prefs();
Horde_LoginTasks_Stub_Task::$executed = array();
$tasks = $this->_getLoginTasks(
array(
'Horde_LoginTasks_Stub_High',
),
true,
- false,
- $prefs
+ false
);
$tasks->runTasks();
- $v = unserialize($prefs->getValue('last_logintasks'));
- $this->assertTrue($v['horde'] > time() - 10);
+ $this->assertTrue(Horde_LoginTasks_Stub_Backend::$lastRun['test'] > time() - 10);
}
public function testAllTasksToBeRunBeforeTheFirstTaskRequiringDisplayGetExecutedInABatch()
true
);
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(false, null)
);
}
$tasks->runTasks(false, 'redirect');
$tasks->displayTasks();
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(true)
);
$this->assertNull(
);
$tasks->displayTasks();
$this->assertEquals(
- 'redirect', $tasks->runTasks(true)
+ 'redirect',
+ $tasks->runTasks(true)
);
}
true
);
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(false, 'redirect')
);
$this->assertEquals(
$_POST['logintasks_confirm_0'] = true;
$_POST['logintasks_confirm_1'] = true;
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(true)
);
$this->assertEquals(
$classes
);
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(true)
);
$this->assertEquals(
);
$_POST['logintasks_confirm_0'] = true;
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(true)
);
$this->assertEquals(
);
$_POST['logintasks_confirm_0'] = true;
$this->assertContains(
- 'http:///services/logintasks.php?app=test',
+ 'URL',
(string) $tasks->runTasks(true)
);
$this->assertEquals(
);
}
- private function _getLoginTasks(
- array $tasks = array(),
- $authenticated = false,
- $last_run = false,
- $prefs = false
- ) {
- if ($authenticated) {
- $_SESSION['horde_auth']['userId'] = 'test';
- }
- $last_time = false;
- if ($last_run) {
- $last_time = mktime(
- $last_run['hours'],
- $last_run['minutes'],
- $last_run['seconds'],
- $last_run['mon'],
- $last_run['mday'],
- $last_run['year']
- );
- $last_time = serialize(
- array(
- 'test' => $last_time
- )
+ private function _getLoginTasks(array $tasks = array(),
+ $authenticated = false, $last_run = false)
+ {
+ $last_time = $last_run;
+ if ($last_time && !is_bool($last_time)) {
+ $last_time = array(
+ 'test' => mktime(
+ $last_run['hours'],
+ $last_run['minutes'],
+ $last_run['seconds'],
+ $last_run['mon'],
+ $last_run['mday'],
+ $last_run['year']
+ )
);
}
- if (empty($prefs)) {
- $GLOBALS['prefs'] = $this->getMock('Horde_Prefs', array(), array(), '', false, false);
- $GLOBALS['prefs']->expects($this->any())
- ->method('getValue')
- ->will($this->returnValue($last_time));
- } else {
- $GLOBALS['prefs'] = $prefs;
+
+ $tasklist = array();
+ foreach ($tasks as $val) {
+ $tasklist[$val] = 'test';
}
- $GLOBALS['registry'] = $this->getMock('Horde_Registry', array(), array(), '', false, false);
- $GLOBALS['registry']->expects($this->any())
- ->method('getAppDrivers')
- ->will($this->returnValue($tasks));
+
return new Horde_LoginTasks(
- new Horde_LoginTasks_Stub_Backend(
- $GLOBALS['registry'],
- $GLOBALS['prefs'],
- 'test'
- )
+ new Horde_LoginTasks_Stub_Backend($tasklist, $authenticated, $last_time)
);
}
+
}
<?php
-if (!class_exists('Horde_Prefs')) {
- class Horde_Prefs {
- public function setValue($pref, $val, $convert = true)
- {
- }
+class Horde_LoginTasks_Stub_Backend extends Horde_LoginTasks_Backend
+{
+ static public $lastRun;
+
+ private $_authenticated;
+ private $_tasklist;
+ private $_tasklistCache = false;
- public function getValue($pref, $convert = true)
- {
+ public function __construct(array $tasks, $authenticated = false,
+ $last_run = false)
+ {
+ $this->_tasklist = $tasks;
+ $this->_authenticated = $authenticated;
+ if ($last_run !== true) {
+ self::$lastRun = $last_run;
}
}
-}
-if (!class_exists('Horde_Registry')) {
- class Horde_Registry {
- public function get($parameter, $app = null)
- {
- }
+ public function isAuthenticated()
+ {
+ return $this->_authenticated;
+ }
- public function getAppDrivers($app, $prefix)
- {
- }
+ public function getTasklistFromCache()
+ {
+ return $this->_tasklistCache;
}
-}
-if (!class_exists('Horde')) {
- class Horde {
- static public function url($url)
- {
- $url = new Horde_Url($url);
- return 'http://' . (string) $url;
- }
+ public function storeTasklistInCache($tasklist)
+ {
+ $this->_tasklistCache = $tasklist;
}
-}
-if (!class_exists('Horde_Auth')) {
- class Horde_Auth {
- static public function getAuth()
- {
- return empty($_SESSION['horde_auth']['userId'])
- ? false
- : $_SESSION['horde_auth']['userId'];
- }
+ public function registerShutdown($shutdown)
+ {
}
-}
-class Horde_LoginTasks_Stub_Prefs
-extends Horde_Prefs
-{
- private $_storage = array();
+ public function getTasks()
+ {
+ return $this->_tasklist;
+ }
+
+ public function getLastRun()
+ {
+ return self::$lastRun;
+ }
+
+ public function setLastRun(array $last)
+ {
+ self::$lastRun = $last;
+ }
- public function __construct()
+ public function markLastRun()
{
+ $lasttasks = $this->getLastRun();
+ $lasttasks['test'] = time();
+ self::$lastRun = $lasttasks;
}
- public function setValue($pref, $val, $convert = true)
+ public function redirect($url)
{
- $this->_storage[$pref] = $val;
+ return $url;
}
- public function getValue($pref, $convert = true)
+ public function getLoginTasksUrl(array $tasks = null)
{
- return isset($this->_storage[$pref]) ? $this->_storage[$pref] : null;
+ return 'URL';
}
}
static public $executed;
public $interval = Horde_LoginTasks::EVERY;
-
public $display = Horde_LoginTasks::DISPLAY_NONE;
-
public $priority = Horde_LoginTasks::PRIORITY_NORMAL;
public function execute()
}
}
-class Horde_LoginTasks_Stub_Backend
-extends Horde_LoginTasks_Backend_Horde
-{
- public function redirect($url)
- {
- return $url;
- }
-}
-
class Horde_LoginTasks_Stub_TaskTwo
extends Horde_LoginTasks_Stub_Task
{
extends Horde_LoginTasks_Stub_Task
{
public $interval = Horde_LoginTasks::YEARLY;
-}
\ No newline at end of file
+}
/* If no 'module' parameter passed in, die with an error. */
if (!($app = basename(Horde_Util::getFormData('app')))) {
- throw new Horde_Exception("Do not directly access logintasks.php");
+ throw new Horde_Exception('Do not directly access logintasks.php.');
}
$registry->pushApp($app, array('logintasks' => false));
-if (!($tasks = Horde_LoginTasks::singleton($app))) {
- throw new Horde_Exception("The Horde_LoginTasks:: class did not load successfully");
+if (!($tasks = $injector->getInstance('Horde_LoginTasks')->getOb($app))) {
+ throw new Horde_Exception('The Horde_LoginTasks:: class did not load successfully.');
}
/* If we are through with tasks, this call will redirect to application. */