put ClearCache into controller, add hooks when clearing the cache

This commit is contained in:
Uwe Steinmann 2020-08-21 10:03:22 +02:00
parent eebc1de5aa
commit 991268a18b
3 changed files with 64 additions and 13 deletions

View File

@ -0,0 +1,51 @@
<?php
/**
* Implementation of ClearCache controller
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Class which does the busines logic for clearing the cache
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Controller_ClearCache extends SeedDMS_Controller_Common {
public function run() {
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$post = $this->params['post'];
$ret = '';
if(!empty($post['preview'])) {
$cmd = 'rm -rf '.$settings->_cacheDir.'/[1-9]*';
system($cmd, $ret);
}
if(!empty($post['js'])) {
$cmd = 'rm -rf '.$settings->_cacheDir.'/js/*';
system($cmd, $ret);
}
if(false === $this->callHook('clear', $post)) {
if(empty($this->errormsg))
$this->errormsg = 'hook_clear_failed';
return false;
}
return true;
}
}

View File

@ -24,8 +24,12 @@ include("../inc/inc.Init.php");
include("../inc/inc.Extension.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassController.php");
include("../inc/inc.Authentication.php");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
/* Check if the form data comes from a trusted request */
if(!checkFormKey('clearcache')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
@ -38,19 +42,8 @@ if(!is_dir($settings->_cacheDir)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_cleared_cache"));
}
if(!empty($_POST['preview'])) {
$cmd = 'rm -rf '.$settings->_cacheDir.'/[1-9]*';
$ret = null;
system($cmd, $ret);
}
if(!empty($_POST['js'])) {
$cmd = 'rm -rf '.$settings->_cacheDir.'/js/*';
$ret = null;
system($cmd, $ret);
}
if($ret)
$controller->setParam('post', $_POST);
if(!$controller->run())
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('error_cleared_cache')));
else
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_cleared_cache')));

View File

@ -54,6 +54,13 @@ class SeedDMS_View_ClearCache extends SeedDMS_Bootstrap_Style {
</p>
<p>
<input type="checkbox" name="js" value="1" checked> <?php printMLText('temp_jscode'); ?>
<?php
$addcache = array();
if($addcache = $this->callHook('additionalCache', $addcache)) {
foreach($addcache as $c)
echo "<p><input type=\"checkbox\" name=\"".$c[0]."\" value=\"1\" checked> ".$c[1]."</p>";
}
?>
<p><button type="submit" class="btn"><i class="icon-remove"></i> <?php printMLText("clear_cache");?></button></p>
</form>
<?php