From 233f2767d06cc53d8325f5d72d49ad2602ef18d3 Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Fri, 28 Sep 2018 15:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98=E5=8D=87?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/system/Clear.php | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/application/admin/controller/system/Clear.php b/application/admin/controller/system/Clear.php index c035d4c8..b90fc4fc 100644 --- a/application/admin/controller/system/Clear.php +++ b/application/admin/controller/system/Clear.php @@ -5,6 +5,8 @@ namespace app\admin\controller\system; use app\admin\controller\AuthController; use service\CacheService; use service\JsonService as Json; +use think\Log; +use think\Cache; /** * 首页控制器 @@ -18,29 +20,36 @@ class Clear extends AuthController { return $this->fetch(); } + + /** + * 刷新数据缓存 + */ public function refresh_cache(){ - if(function_exists('shell_exec')){ - `php think optimize:schema`; - `php think optimize:autoload`; - `php think optimize:route`; - `php think optimize:config`; - }else if(function_exists('exec')){ - exec('php think optimize:schema'); - exec('php think optimize:autoload'); - exec('php think optimize:route'); - exec('php think optimize:config'); - } + `php think optimize:schema`; + `php think optimize:autoload`; + `php think optimize:route`; + `php think optimize:config`; return Json::successful('数据缓存刷新成功!'); } + + /** + * 删除缓存 + */ public function delete_cache(){ - $this->delDirAndFile("./runtime/temp"); - $this->delDirAndFile("./runtime/cache"); + Cache::clear(); + array_map('unlink', glob(TEMP_PATH . '/*.php')); return Json::successful('清除缓存成功!'); } + + /** + * 删除日志 + */ public function delete_log(){ - $this->delDirAndFile("./runtime/log"); + array_map('unlink', glob(LOG_PATH . '/*.log')); + $this->delDirAndFile(LOG_PATH); return Json::successful('清除日志成功!'); } + function delDirAndFile($dirName,$subdir=true){ if ($handle = opendir("$dirName")){ while(false !== ($item = readdir($handle))){