Move registry calls (returning the tasks and the URL of the login tasks view) into...
authorGunnar Wrobel <p@rdus.de>
Wed, 3 Mar 2010 11:02:21 +0000 (12:02 +0100)
committerGunnar Wrobel <p@rdus.de>
Wed, 3 Mar 2010 11:02:21 +0000 (12:02 +0100)
framework/LoginTasks/lib/Horde/LoginTasks.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend.php
framework/LoginTasks/lib/Horde/LoginTasks/Backend/Horde.php

index 3dacf2f..a932983 100644 (file)
@@ -78,7 +78,11 @@ class Horde_LoginTasks
     {
         if (empty(self::$_instances[$app])) {
             self::$_instances[$app] = new self(
-                new Horde_LoginTasks_Backend_Horde($app), $app
+                new Horde_LoginTasks_Backend_Horde(
+                    $GLOBALS['registry'],
+                    $app
+                ),
+                $app
             );
         }
 
@@ -139,29 +143,10 @@ class Horde_LoginTasks
             $lasttask_pref = array();
         }
 
-        /* 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;
-            }
-        }
-
-        if (empty($tasks)) {
-            return;
-        }
-
         /* Create time objects for today's date and last task run date. */
         $cur_date = getdate();
 
-        foreach ($tasks as $classname => $app) {
+        foreach ($this->_backend->getTasks() as $classname => $app) {
             $ob = new $classname();
 
             /* If marked inactive, skip the task. */
@@ -298,13 +283,13 @@ class Horde_LoginTasks
     }
 
     /**
-     * Generated the login tasks URL.
+     * Generate the login tasks URL.
      *
      * @return string  The login tasks URL.
      */
     public function getLoginTasksUrl()
     {
-        return Horde::url(Horde_Util::addParameter($GLOBALS['registry']->get('webroot', 'horde') . '/services/logintasks.php', array('app' => $this->_app)), true);
+        return $this->_backend->getLoginTasksUrl();
     }
 
     /**
index 44a9395..b4b6bd3 100644 (file)
@@ -47,4 +47,18 @@ abstract class Horde_LoginTasks_Backend
      * @return NULL
      */
     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.
+     */
+    abstract public function getTasks();
+
+    /**
+     * Return the URL of the login tasks view.
+     *
+     * @return string The URL of the login tasks view
+     */
+    abstract public function getLoginTasksUrl();
 }
\ No newline at end of file
index 2ae4660..ae032ed 100644 (file)
@@ -27,9 +27,12 @@ extends Horde_LoginTasks_Backend
      *
      * @param string $app The Horde application that is currently active.
      */
-    public function __construct($app)
-    {
-        $this->_app = $app;
+    public function __construct(
+        Horde_Registry $registry,
+        $app
+    ) {
+        $this->_registry = $registry;
+        $this->_app      = $app;
     }
     
     /**
@@ -79,4 +82,38 @@ extends Horde_LoginTasks_Backend
     {
         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;
+    }
+
+    /**
+     * Return the URL of the login tasks view.
+     *
+     * @return string The URL of the login tasks view
+     */
+    public function getLoginTasksUrl()
+    {
+        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