1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\admin\controller\system;
- use app\admin\controller\AuthController;
- use crmeb\services\CacheService;
- class Clear extends AuthController
- {
- public function index()
- {
- return $this->fetch();
- }
-
- public function refresh_cache()
- {
- $root = app()->getRootPath() . 'runtime' . DS;
- $adminRoute = $root . 'admin';
- $apiRoute = $root . 'api';
- $cacheRoute = $root . 'cache';
- $cache = [];
- if (is_dir($adminRoute))
- $cache[$adminRoute] = scandir($adminRoute);
- if (is_dir($apiRoute))
- $cache[$apiRoute] = scandir($apiRoute);
- if (is_dir($cacheRoute))
- $cache[$cacheRoute] = scandir($cacheRoute);
- foreach ($cache as $p => $list) {
- foreach ($list as $file) {
- if (!in_array($file, ['.', '..', 'log', 'schema', 'route.php'])) {
- $path = $p . DS . $file;
- if (is_file($path)) {
- @unlink($path);
- } else {
- $this->delDirAndFile($path . DS);
- }
- }
- }
- }
- CacheService::clear();
- return app('json')->successful('数据缓存刷新成功!');
- }
-
- public function delete_log()
- {
- $root = app()->getRootPath() . 'runtime' . DS;
- $this->delDirAndFile($root . 'admin' . DS . 'log' . DS);
- $this->delDirAndFile($root . 'api' . DS . 'log' . DS);
- $this->delDirAndFile($root . 'log' . DS);
- return app('json')->successful('数据缓存刷新成功!');
- }
-
- protected function delDirAndFile($dirName)
- {
- $list = glob($dirName . '*');
- foreach ($list as $file) {
- if (is_dir($file))
- $this->delDirAndFile($file . DS);
- else
- @unlink($file);
- }
- @rmdir($dirName);
- }
- }
|