Move procAdminRecompileCacheFile() to its own class

This commit is contained in:
Kijin Sung 2022-12-27 21:58:28 +09:00
parent b9e55c05e6
commit 01b408fb6b
4 changed files with 134 additions and 109 deletions

View file

@ -55,111 +55,6 @@ class AdminAdminController extends Admin
$this->setRedirectUrl(Context::get('error_return_url'));
}
/**
* Regenerate all cache files
* @return void
*/
public function procAdminRecompileCacheFile()
{
// rename cache dir
$truncate_method = Rhymix\Framework\Config::get('cache.truncate_method');
if ($truncate_method === 'empty')
{
$tmp_basedir = \RX_BASEDIR . 'files/cache/truncate_' . time();
Rhymix\Framework\Storage::createDirectory($tmp_basedir);
$dirs = Rhymix\Framework\Storage::readDirectory(\RX_BASEDIR . 'files/cache', true, false, false);
if ($dirs)
{
foreach ($dirs as $dir)
{
Rhymix\Framework\Storage::moveDirectory($dir, $tmp_basedir . '/' . basename($dir));
}
}
}
else
{
Rhymix\Framework\Storage::move(\RX_BASEDIR . 'files/cache', \RX_BASEDIR . 'files/cache_' . time());
Rhymix\Framework\Storage::createDirectory(\RX_BASEDIR . 'files/cache');
}
// remove module extend cache
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/config/module_extend.php');
// remove debug files
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/_debug_message.php');
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/_debug_db_query.php');
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/_db_slow_query.php');
$oModuleModel = getModel('module');
$module_list = $oModuleModel->getModuleList();
// call recompileCache for each module
foreach($module_list as $module)
{
$oModule = NULL;
$oModule = getClass($module->module);
if($oModule && method_exists($oModule, 'recompileCache'))
{
$oModule->recompileCache();
}
}
// remove object cache
if (!in_array(Rhymix\Framework\Cache::getDriverName(), array('file', 'sqlite', 'dummy')))
{
Rhymix\Framework\Cache::clearAll();
}
// remove old cache dir
if ($truncate_method === 'empty')
{
$tmp_cache_list = FileHandler::readDir(\RX_BASEDIR . 'files/cache', '/^(truncate_[0-9]+)/');
$tmp_cache_prefix = \RX_BASEDIR . 'files/cache/';
}
else
{
$tmp_cache_list = FileHandler::readDir(\RX_BASEDIR . 'files', '/^(cache_[0-9]+)/');
$tmp_cache_prefix = \RX_BASEDIR . 'files/';
}
if($tmp_cache_list)
{
foreach($tmp_cache_list as $tmp_dir)
{
if(strval($tmp_dir) !== '')
{
$tmp_dir = $tmp_cache_prefix . $tmp_dir;
if (!Rhymix\Framework\Storage::isDirectory($tmp_dir))
{
continue;
}
// If possible, use system command to speed up recursive deletion
if (function_exists('exec') && !preg_match('/(?<!_)exec/', ini_get('disable_functions')))
{
if (strncasecmp(\PHP_OS, 'win', 3) == 0)
{
@exec('rmdir /S /Q ' . escapeshellarg($tmp_dir));
}
else
{
@exec('rm -rf ' . escapeshellarg($tmp_dir));
}
}
// If the directory still exists, delete using PHP.
Rhymix\Framework\Storage::deleteDirectory($tmp_dir);
}
}
}
// check autoinstall packages
$oAutoinstallAdminController = getAdminController('autoinstall');
$oAutoinstallAdminController->checkInstalled();
$this->setMessage('success_updated');
}
public function procAdminInsertDefaultDesignInfo()
{
$vars = Context::getRequestVars();
@ -410,6 +305,16 @@ class AdminAdminController extends Admin
$redirectUrl = getNotEncodedUrl('', 'module', 'admin');
$this->setRedirectUrl($redirectUrl);
}
/**
* Reset cache
*
* @deprecated
*/
public function procAdminRecompileCacheFile()
{
return Rhymix\Modules\Admin\Controllers\CacheReset::getInstance()->procAdminRecompileCacheFile();
}
/**
* Update admin module config

View file

@ -13,6 +13,8 @@ class AdminAdminView extends Admin
{
/**
* Make the admin menu.
*
* @deprecated
*/
public function makeGnbUrl($module = 'admin')
{
@ -21,7 +23,8 @@ class AdminAdminView extends Admin
/**
* Display FTP Configuration(settings) page
* @return void
*
* @deprecated
*/
public function dispAdminConfigFtp()
{
@ -30,7 +33,6 @@ class AdminAdminView extends Admin
/**
* Display Admin Menu Configuration(settings) page
* @return void
*/
public function dispAdminSetup()
{
@ -42,5 +44,3 @@ class AdminAdminView extends Admin
$this->setTemplateFile('admin_setup');
}
}
/* End of file admin.admin.view.php */
/* Location: ./modules/admin/admin.admin.view.php */

View file

@ -5,6 +5,7 @@
<!-- Dashboard -->
<action name="dispAdminIndex" class="Controllers\Dashboard" index="true" />
<action name="procAdminLogout" class="Controllers\Dashboard" method="GET|POST" />
<action name="procAdminRecompileCacheFile" class="Controllers\CacheReset" />
<!-- Server Env -->
<action name="dispAdminViewServerEnv" class="Controllers\ServerEnv" />
<action name="dispAdminRewriteTest" class="Controllers\ServerEnv" standalone="true" />

View file

@ -0,0 +1,119 @@
<?php
namespace Rhymix\Modules\Admin\Controllers;
use FileHandler;
use ModuleModel;
use ModuleObject;
use Rhymix\Framework\Cache;
use Rhymix\Framework\Config;
use Rhymix\Framework\Storage;
class CacheReset extends Base
{
/**
* Regenerate all cache files
*/
public function procAdminRecompileCacheFile()
{
// rename cache dir
$truncate_method = Config::get('cache.truncate_method');
if ($truncate_method === 'empty')
{
$tmp_basedir = \RX_BASEDIR . 'files/cache/truncate_' . time();
Storage::createDirectory($tmp_basedir);
$dirs = Storage::readDirectory(\RX_BASEDIR . 'files/cache', true, false, false);
if ($dirs)
{
foreach ($dirs as $dir)
{
Storage::moveDirectory($dir, $tmp_basedir . '/' . basename($dir));
}
}
}
else
{
Storage::move(\RX_BASEDIR . 'files/cache', \RX_BASEDIR . 'files/cache_' . time());
Storage::createDirectory(\RX_BASEDIR . 'files/cache');
}
// remove module extend cache
Storage::delete(RX_BASEDIR . 'files/config/module_extend.php');
// remove debug files
Storage::delete(RX_BASEDIR . 'files/_debug_message.php');
Storage::delete(RX_BASEDIR . 'files/_debug_db_query.php');
Storage::delete(RX_BASEDIR . 'files/_db_slow_query.php');
$module_list = ModuleModel::getModuleList();
// call recompileCache for each module
foreach($module_list as $module)
{
$oModule = getClass($module->module);
if (!$oModule)
{
$oModule = ModuleModel::getModuleInstallClass($module->module);
}
if ($oModule instanceof ModuleObject && method_exists($oModule, 'recompileCache'))
{
call_user_func([$oModule, 'recompileCache']);
}
}
// remove object cache
if (!in_array(Cache::getDriverName(), array('file', 'sqlite', 'dummy')))
{
Cache::clearAll();
}
// remove old cache dir
if ($truncate_method === 'empty')
{
$tmp_cache_list = FileHandler::readDir(\RX_BASEDIR . 'files/cache', '/^(truncate_[0-9]+)/');
$tmp_cache_prefix = \RX_BASEDIR . 'files/cache/';
}
else
{
$tmp_cache_list = FileHandler::readDir(\RX_BASEDIR . 'files', '/^(cache_[0-9]+)/');
$tmp_cache_prefix = \RX_BASEDIR . 'files/';
}
if($tmp_cache_list)
{
foreach($tmp_cache_list as $tmp_dir)
{
if(strval($tmp_dir) !== '')
{
$tmp_dir = $tmp_cache_prefix . $tmp_dir;
if (!Storage::isDirectory($tmp_dir))
{
continue;
}
// If possible, use system command to speed up recursive deletion
if (function_exists('exec') && !preg_match('/(?<!_)exec/', ini_get('disable_functions')))
{
if (strncasecmp(\PHP_OS, 'win', 3) == 0)
{
@exec('rmdir /S /Q ' . escapeshellarg($tmp_dir));
}
else
{
@exec('rm -rf ' . escapeshellarg($tmp_dir));
}
}
// If the directory still exists, delete using PHP.
Storage::deleteDirectory($tmp_dir);
}
}
}
// check autoinstall packages
$oAutoinstallAdminController = getAdminController('autoinstall');
$oAutoinstallAdminController->checkInstalled();
$this->setMessage('success_updated');
}
}