From: Michael M Slusarz Date: Tue, 23 Nov 2010 22:34:54 +0000 (-0700) Subject: Add command-line script to flush horde themes cache X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=15ca64e7a50ceeda04369bb2f940ec17155324e1;p=horde.git Add command-line script to flush horde themes cache --- diff --git a/framework/Core/lib/Horde/Core/Factory/ThemesCache.php b/framework/Core/lib/Horde/Core/Factory/ThemesCache.php index d6bbab465..f1b0e8773 100644 --- a/framework/Core/lib/Horde/Core/Factory/ThemesCache.php +++ b/framework/Core/lib/Horde/Core/Factory/ThemesCache.php @@ -94,6 +94,30 @@ class Horde_Core_Factory_ThemesCache } /** + * Expire cache entry. + * + * @param string $app The application name. + * @param string $theme The theme name. + * + * @return boolean True if cache entry existed. + */ + public function expireCache($app, $theme) + { + $sig = implode('|', array($app, $theme)); + + $cache = $this->_injector->getInstance('Horde_Cache'); + + if ($cache->exists($sig, $GLOBALS['conf']['cachethemesparams']['lifetime'])) { + $cache->expire($sig); + unset($this->_instances[$sig]); + + return true; + } + + return false; + } + + /** * Store object in cache. */ public function shutdown() diff --git a/horde/bin/themes b/horde/bin/themes new file mode 100755 index 000000000..ad86c3cb9 --- /dev/null +++ b/horde/bin/themes @@ -0,0 +1,63 @@ +#!/usr/bin/env php + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + */ + +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('horde', array( + 'authentication' => 'none', + 'cli' => true +)); + +$c = new Console_Getopt(); +$argv = $c->readPHPArgv(); +array_shift($argv); +$options = $c->getopt2($argv, '', array('expirecache')); +if (PEAR::isError($options)) { + $cli->writeln($cli->red("ERROR: Invalid arguments.")); + $cli->writeln(); + _usage(); +} + +foreach ($options[0] as $val) { + switch ($val[0]) { + case '--expirecache': + if ($cli->prompt($cli->red('Are you sure you want to expire all cached themes?'), array('y' => 'Yes', 'n' => 'No'), 'n') == 'y') { + $tcache = $injector->getInstance('Horde_Core_Factory_ThemesCache'); + $tlist = array_keys(Horde_Themes::themeList()); + + foreach ($registry->listAllApps() as $app) { + foreach ($tlist as $theme) { + if ($tcache->expireCache($app, $theme)) { + $cli->message('Cache entry expired [APP: ' . $app . '; THEME: ' . $theme . ']'); + } + } + } + } + exit; + } +} + +_usage(); + + +function _usage() +{ + global $cli; + + $cli->writeln($cli->bold('Usage: themes.php [--expirecache]')); + $cli->writeln(); + $cli->writeln($cli->indent('--expirecache Expire all cache entries')); + + exit; +}