Skip to content

Commit

Permalink
[mms] Add method to allow any code to register tasks to run on logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jul 25, 2014
1 parent edac7f5 commit 553e6c9
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 5 deletions.
7 changes: 6 additions & 1 deletion framework/Core/lib/Horde/Registry.php
Expand Up @@ -2041,13 +2041,18 @@ public function clearAuth($destroy = true)
{
global $session;

/* Do logout tasks. */
/* Do application logout tasks. */
/* @todo: Replace with exclusively registered logout tasks. */
foreach ($this->getAuthApps() as $app) {
try {
$this->callAppMethod($app, 'logout');
} catch (Horde_Exception $e) {}
}

/* Do registered logout tasks. */
$logout = new Horde_Registry_Logout();
$logout->run();

$session->remove('horde', 'auth');
$session->remove('horde', 'auth_app/');

Expand Down
99 changes: 99 additions & 0 deletions framework/Core/lib/Horde/Registry/Logout.php
@@ -0,0 +1,99 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/

/**
* Manage the logout tasks registered with Horde_Registry.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
* @since 2.13.0
*/
class Horde_Registry_Logout
{
/** Session storage key. */
const SESSION_KEY = 'registry_logout';

/**
* Add a class to the logout queue.
*
* @param mixed $classname The classname to add (or an object of that
* class). The class must be able to be
* instantiated via Horde_Injector and must
* implement the Horde_Registry_Logout_Task
* interface.
*/
public function add($classname)
{
$classname = is_object($classname)
? get_class($classname)
: strval($classname);

$queue = $this->_getTasks();

if (!in_array($classname, $queue)) {
$queue[] = $classname;
$this->_setTasks($queue);
}
}

/**
* Runs the list of logout tasks and clears the queue.
*/
public function run()
{
global $injector;

foreach ($this->_getTasks() as $val) {
try {
$ob = $injector->getInstance($val);
if ($ob instanceof Horde_Registry_Logout_Task) {
$ob->logoutTask();
}
} catch (Exception $e) {}
}

$this->_setTasks(array());
}

/**
* Return the list of logout tasks.
*/
private function _getTasks()
{
global $session;

return $session->get(
'horde',
self::SESSION_KEY,
$session::TYPE_ARRAY
);
}

/**
* Set the list of logout tasks.
*
* @param array $queue List of classnames.
*/
private function _setTasks($queue)
{
$GLOBALS['session']->set(
'horde',
self::SESSION_KEY,
$queue
);
}

}
31 changes: 31 additions & 0 deletions framework/Core/lib/Horde/Registry/Logout/Task.php
@@ -0,0 +1,31 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/

/**
* Interface to register a logout task.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
* @since 2.13.0
*/
interface Horde_Registry_Logout_Task
{
/**
* Function to run on logout.
*/
public function logoutTask();

}
15 changes: 11 additions & 4 deletions framework/Core/package.xml
Expand Up @@ -30,15 +30,16 @@
</developer>
<date>2014-07-12</date>
<version>
<release>2.12.7</release>
<api>2.12.0</api>
<release>2.13.0</release>
<api>2.13.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Add method to allow any code to register tasks to run on logout.
* [mjr] Ensure EAS client created collections are requested to be added to the application&apos;s sync preference (Bug #13359).
* [mjr] Fix fatal error when executing a FOLDERDELETE command on certain collections.
</notes>
Expand Down Expand Up @@ -641,11 +642,15 @@
<dir name="Hordeconfig">
<file name="Merged.php" role="php" />
</dir> <!-- /lib/Horde/Registry/Hordeconfig -->
<dir name="Logout">
<file name="Task.php" role="php" />
</dir> <!-- /lib/Horde/Registry/Logout -->
<file name="Api.php" role="php" />
<file name="Application.php" role="php" />
<file name="Caller.php" role="php" />
<file name="Hordeconfig.php" role="php" />
<file name="Loadconfig.php" role="php" />
<file name="Logout.php" role="php" />
<file name="Nlsconfig.php" role="php" />
<file name="Registryconfig.php" role="php" />
</dir> <!-- /lib/Horde/Registry -->
Expand Down Expand Up @@ -1941,9 +1946,11 @@
<install as="Horde/Registry/Caller.php" name="lib/Horde/Registry/Caller.php" />
<install as="Horde/Registry/Hordeconfig.php" name="lib/Horde/Registry/Hordeconfig.php" />
<install as="Horde/Registry/Loadconfig.php" name="lib/Horde/Registry/Loadconfig.php" />
<install as="Horde/Registry/Logout.php" name="lib/Horde/Registry/Logout.php" />
<install as="Horde/Registry/Nlsconfig.php" name="lib/Horde/Registry/Nlsconfig.php" />
<install as="Horde/Registry/Registryconfig.php" name="lib/Horde/Registry/Registryconfig.php" />
<install as="Horde/Registry/Hordeconfig/Merged.php" name="lib/Horde/Registry/Hordeconfig/Merged.php" />
<install as="Horde/Registry/Logout/Task.php" name="lib/Horde/Registry/Logout/Task.php" />
<install as="Horde/Script/Cache.php" name="lib/Horde/Script/Cache.php" />
<install as="Horde/Script/Compress.php" name="lib/Horde/Script/Compress.php" />
<install as="Horde/Script/File.php" name="lib/Horde/Script/File.php" />
Expand Down Expand Up @@ -3561,8 +3568,8 @@
</release>
<release>
<version>
<release>2.12.7</release>
<api>2.12.0</api></version>
<release>2.13.0</release>
<api>2.13.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
Expand Down

0 comments on commit 553e6c9

Please sign in to comment.