Add command-line script to flush horde themes cache
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 23 Nov 2010 22:34:54 +0000 (15:34 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 23 Nov 2010 22:47:19 +0000 (15:47 -0700)
framework/Core/lib/Horde/Core/Factory/ThemesCache.php
horde/bin/themes [new file with mode: 0755]

index d6bbab4..f1b0e87 100644 (file)
@@ -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 (executable)
index 0000000..ad86c3c
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/env php
+<?php
+/**
+ * This script manages themes.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @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;
+}