From 655b4ab74ccfb0192e4644e1bff016d717b6928e Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 3 Mar 2010 13:58:25 +0100 Subject: [PATCH] Move the first preferences based task into the backend. --- framework/LoginTasks/lib/Horde/LoginTasks.php | 6 ++-- .../LoginTasks/lib/Horde/LoginTasks/Backend.php | 9 ++++++ .../lib/Horde/LoginTasks/Backend/Horde.php | 32 ++++++++++++++++++++++ framework/LoginTasks/package.xml | 6 ++++ .../LoginTasks/test/Horde/LoginTasks/Stubs.php | 13 ++++++--- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/framework/LoginTasks/lib/Horde/LoginTasks.php b/framework/LoginTasks/lib/Horde/LoginTasks.php index a93298310..43270ed89 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks.php @@ -80,6 +80,7 @@ class Horde_LoginTasks self::$_instances[$app] = new self( new Horde_LoginTasks_Backend_Horde( $GLOBALS['registry'], + $GLOBALS['prefs'], $app ), $app @@ -138,10 +139,7 @@ class Horde_LoginTasks /* Get last task run date(s). Array keys are app names, values are * last run timestamps. Special key '_once' contains list of * ONCE tasks previously run. */ - $lasttask_pref = @unserialize($GLOBALS['prefs']->getValue('last_logintasks')); - if (!is_array($lasttask_pref)) { - $lasttask_pref = array(); - } + $lasttask_pref = $this->_backend->getLastTasks(); /* Create time objects for today's date and last task run date. */ $cur_date = getdate(); diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php b/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php index b4b6bd3b8..b4c5483c8 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks/Backend.php @@ -56,6 +56,15 @@ abstract class Horde_LoginTasks_Backend abstract public function getTasks(); /** + * 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. + */ + abstract public function getLastTasks(); + + /** * Return the URL of the login tasks view. * * @return string The URL of the login tasks view diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php b/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php index ae032ed3b..0c951827f 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php @@ -23,15 +23,31 @@ extends Horde_LoginTasks_Backend 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; } @@ -108,6 +124,22 @@ extends Horde_LoginTasks_Backend } /** + * 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 getLastTasks() + { + $lasttask_pref = @unserialize($this->_prefs->getValue('last_logintasks')); + if (!is_array($lasttask_pref)) { + $lasttask_pref = array(); + } + return $lasttask_pref; + } + + /** * Return the URL of the login tasks view. * * @return string The URL of the login tasks view diff --git a/framework/LoginTasks/package.xml b/framework/LoginTasks/package.xml index 68c721a2d..8e6f0c2be 100644 --- a/framework/LoginTasks/package.xml +++ b/framework/LoginTasks/package.xml @@ -63,6 +63,12 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org + + + Prefs + pear.horde.org + + diff --git a/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php b/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php index 02f256e35..73e034e90 100644 --- a/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php +++ b/framework/LoginTasks/test/Horde/LoginTasks/Stubs.php @@ -1,17 +1,22 @@ _storage[$key] = $value; } - public function getValue($key) + public function setValue($pref, $val, $convert = true) { - return isset($this->_storage[$key]) ? $this->_storage[$key] : null; + $this->_storage[$pref] = $val; + } + + public function getValue($pref, $convert = true) + { + return isset($this->_storage[$pref]) ? $this->_storage[$pref] : null; } } -- 2.11.0