Adding CacheClearAction
authorTim Düsterhus <timwolla@arcor.de>
Thu, 9 Feb 2012 17:49:14 +0000 (18:49 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Thu, 9 Feb 2012 17:49:14 +0000 (18:49 +0100)
This class was handcoded with nano!

wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php b/wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php
new file mode 100644 (file)
index 0000000..73f9bee
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+namespace wcf\acp\action;
+use wcf\action\AbstractAction;
+use wcf\system\cache\CacheHandler;
+use wcf\system\exception\SystemException;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\language\LanguageFactory;
+use wcf\system\package\PackageDependencyHandler;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+use wcf\util\FileUtil;
+use wcf\util\HeaderUtil;
+
+/**
+ * Clears the cache.
+ *
+ * @author     Tim Düsterhus
+ * @copyright  2012 Tim Düsterhus
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage acp.action
+ * @category   Community Framework
+ */
+class CacheClearAction extends AbstractAction {
+       /**
+        * @see wcf\action\IAction::execute()
+        */
+       public function execute() {
+               parent::execute();
+               WCF::getSession()->checkPermissions(array('admin.system.canViewLog'));
+               
+               // this will clean up the templates as well
+               LanguageFactory::getInstance()->deleteLanguageCache();
+               
+               $conditions = new PreparedStatementConditionBuilder();
+               $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies()));
+               $conditions->add("isApplication = ?", array(1));
+               
+               // get package dirs
+               $sql = "SELECT  packageDir
+                       FROM    wcf".WCF_N."_package
+                       ".$conditions;
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($conditions->getParameters());
+               while ($row = $statement->fetchArray()) {
+                       $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
+                       try {
+                               CacheHandler::getInstance()->clear($packageDir.'cache', '*.php');
+                       }
+                       catch (SystemException $e) {
+                       }
+               }
+               $this->executed();
+               HeaderUtil::redirect(LinkHandler::getInstance()->getLink('CacheList'));
+               exit;
+       }
+}