From: Michael M Slusarz Date: Thu, 7 Oct 2010 06:38:20 +0000 (-0600) Subject: Bug #9261: Allow SystemTasks to be skipped X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=95695d805d9824a0fb7ef63e539bf156bc5bf680;p=horde.git Bug #9261: Allow SystemTasks to be skipped If a system task requires auth, skip it until the user is authenticated. For bin/run_task, if a task is skipped output a warning message. Currently, no UI exists for allowing authentication from the command line. --- diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/SystemTask.php b/framework/LoginTasks/lib/Horde/LoginTasks/SystemTask.php index 44458e3cc..a4ceb3a66 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks/SystemTask.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks/SystemTask.php @@ -34,4 +34,15 @@ abstract class Horde_LoginTasks_SystemTask */ abstract public function execute(); + /** + * Skip the current task? If true, will not run on this access but + * will attempt to run on the next access. + * + * @return boolean Skip the current task? + */ + public function skip() + { + return false; + } + } diff --git a/framework/LoginTasks/lib/Horde/LoginTasks/Tasklist.php b/framework/LoginTasks/lib/Horde/LoginTasks/Tasklist.php index f06564ec5..303c13f38 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks/Tasklist.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks/Tasklist.php @@ -43,6 +43,15 @@ class Horde_LoginTasks_Tasklist protected $_tasks = array(); /** + * THe list of system tasks to run during this login. + * + * @see $_tasks + * + * @var array + */ + protected $_stasks = array(); + + /** * Current task location pointer. * * @var integer @@ -56,14 +65,18 @@ class Horde_LoginTasks_Tasklist */ public function addTask($task) { - switch ($task->priority) { - case Horde_LoginTasks::PRIORITY_HIGH: - array_unshift($this->_tasks, $task); - break; - - case Horde_LoginTasks::PRIORITY_NORMAL: - $this->_tasks[] = $task; - break; + if ($task instanceof Horde_LoginTasks_SystemTask) { + $this->_stasks[] = $task; + } else { + switch ($task->priority) { + case Horde_LoginTasks::PRIORITY_HIGH: + array_unshift($this->_tasks, $task); + break; + + case Horde_LoginTasks::PRIORITY_NORMAL: + $this->_tasks[] = $task; + break; + } } } @@ -78,6 +91,14 @@ class Horde_LoginTasks_Tasklist { $tmp = array(); + /* Always loop through system tasks first. */ + foreach ($this->_stasks as $key => $val) { + if (!$val->skip()) { + $tmp[] = $val; + unset($this->_stasks[$key]); + } + } + reset($this->_tasks); while (list($k, $v) = each($this->_tasks)) { if ($v->needsDisplay() && ($k >= $this->_ptr)) { @@ -130,7 +151,8 @@ class Horde_LoginTasks_Tasklist */ public function isDone() { - return ($this->_ptr == count($this->_tasks)); + return (empty($this->_stasks) && + ($this->_ptr == count($this->_tasks))); } } diff --git a/framework/LoginTasks/package.xml b/framework/LoginTasks/package.xml index 93c618f7a..e82feef04 100644 --- a/framework/LoginTasks/package.xml +++ b/framework/LoginTasks/package.xml @@ -21,7 +21,8 @@ beta LGPL - * Removed horde/Core and horde/Util dependency. + * Add ability to dynamically skip system tasks. + * Removed horde/Core and horde/Util dependency. * Added system tasks. * Added ONCE interval. * Renamed Maintenance:: -> Horde_LoginTasks::. diff --git a/horde/bin/run_task b/horde/bin/run_task index e6719cf03..c94e9ccdc 100755 --- a/horde/bin/run_task +++ b/horde/bin/run_task @@ -71,8 +71,10 @@ if (!class_exists($class)) { } } - $ob = new $class(); -$ob->execute(); - -$cli->message('Completed task.', 'cli.success'); +if (($ob instanceof Horde_LoginTasks_SystemTask) && $ob->skip()) { + $cli->message('System task was skipped.', 'cli.warning'); +} else { + $ob->execute(); + $cli->message('Completed task.', 'cli.success'); +} diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index fdf02c0fb..e79da1a01 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -27,7 +27,6 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT public function execute() { $this->_upgradeAbookPrefs(); - $this->_upgradeExpireImapCache(); $this->_upgradeForwardPrefs(); $this->_upgradeLoginTasksPrefs(); $this->_upgradeSortPrefs(); @@ -68,23 +67,6 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT } /** - * Expire existing IMAP cache. - */ - protected function _upgradeExpireImapCache() - { - try { - $ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->ob; - $ob->login(); - - $mboxes = $ob->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true)); - - foreach ($mboxes as $val) { - $ob->cache->deleteMailbox($val); - } - } catch (Exception $e) {} - } - - /** * Upgrade to the new forward preferences. */ protected function _upgradeForwardPrefs() diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php new file mode 100644 index 000000000..4c6920ede --- /dev/null +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4Auth.php @@ -0,0 +1,57 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package IMP + */ +class IMP_LoginTasks_SystemTask_UpgradeFromImp4Auth extends Horde_LoginTasks_SystemTask +{ + /** + */ + public $interval = Horde_LoginTasks::ONCE; + + /** + */ + public function execute() + { + $this->_upgradeExpireImapCache(); + } + + /** + */ + public function skip() + { + /* Skip task until we are authenticated. */ + return !$GLOBALS['registry']->isAuthenticated(array('app' => 'imp')); + } + + /** + * Expire existing IMAP cache. + */ + protected function _upgradeExpireImapCache() + { + try { + $ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create()->ob; + + if ($cache = $ob->getCache()) { + $ob->login(); + + $mboxes = $ob->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true)); + + foreach ($mboxes as $val) { + $ob->cache->deleteMailbox($val); + } + } + } catch (Exception $e) {} + } + +}