From 01b408fb6b569c99871465b3ff83e5bd2e34361f Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 27 Dec 2022 21:58:28 +0900 Subject: [PATCH] Move procAdminRecompileCacheFile() to its own class --- modules/admin/admin.admin.controller.php | 115 ++-------------------- modules/admin/admin.admin.view.php | 8 +- modules/admin/conf/module.xml | 1 + modules/admin/controllers/CacheReset.php | 119 +++++++++++++++++++++++ 4 files changed, 134 insertions(+), 109 deletions(-) create mode 100644 modules/admin/controllers/CacheReset.php diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index ccd13c492..37d0c3716 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -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('/(?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 diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index 55f73b627..9bb713999 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -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 */ diff --git a/modules/admin/conf/module.xml b/modules/admin/conf/module.xml index 7f6edd1ee..1c74f3978 100644 --- a/modules/admin/conf/module.xml +++ b/modules/admin/conf/module.xml @@ -5,6 +5,7 @@ + diff --git a/modules/admin/controllers/CacheReset.php b/modules/admin/controllers/CacheReset.php new file mode 100644 index 000000000..5452ccf10 --- /dev/null +++ b/modules/admin/controllers/CacheReset.php @@ -0,0 +1,119 @@ +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('/(?checkInstalled(); + + $this->setMessage('success_updated'); + } +}