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.
*/
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;
+ }
+
}
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
*/
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;
+ }
}
}
{
$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)) {
*/
public function isDone()
{
- return ($this->_ptr == count($this->_tasks));
+ return (empty($this->_stasks) &&
+ ($this->_ptr == count($this->_tasks)));
}
}
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Removed horde/Core and horde/Util dependency.
+ <notes>* Add ability to dynamically skip system tasks.
+ * Removed horde/Core and horde/Util dependency.
* Added system tasks.
* Added ONCE interval.
* Renamed Maintenance:: -> Horde_LoginTasks::.
}
}
-
$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');
+}
public function execute()
{
$this->_upgradeAbookPrefs();
- $this->_upgradeExpireImapCache();
$this->_upgradeForwardPrefs();
$this->_upgradeLoginTasksPrefs();
$this->_upgradeSortPrefs();
}
/**
- * 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()
--- /dev/null
+<?php
+/**
+ * Login system task for automated upgrade tasks.
+ * These tasks DO require IMP authentication.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @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) {}
+ }
+
+}