Clear.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\system;
  12. use app\admin\controller\AuthController;
  13. use service\CacheService;
  14. use service\JsonService as Json;
  15. use think\Log;
  16. use think\Cache;
  17. /**
  18. * 首页控制器
  19. * Class Clear
  20. * @package app\admin\controller
  21. *
  22. */
  23. class Clear extends AuthController
  24. {
  25. public function index()
  26. {
  27. return $this->fetch();
  28. }
  29. /**
  30. * 刷新数据缓存
  31. */
  32. public function refresh_cache()
  33. {
  34. `php think optimize:schema`;
  35. `php think optimize:autoload`;
  36. `php think optimize:route`;
  37. `php think optimize:config`;
  38. return Json::successful('数据缓存刷新成功!');
  39. }
  40. /**
  41. * 删除缓存
  42. */
  43. public function delete_cache()
  44. {
  45. Cache::clear();
  46. array_map('unlink', glob(TEMP_PATH . '/*.php'));
  47. return Json::successful('清除缓存成功!');
  48. }
  49. /**
  50. * 删除日志
  51. */
  52. public function delete_log()
  53. {
  54. array_map('unlink', glob(LOG_PATH . '/*.log'));
  55. $this->delDirAndFile(LOG_PATH);
  56. return Json::successful('清除日志成功!');
  57. }
  58. function delDirAndFile($dirName, $subdir = true)
  59. {
  60. if ($handle = opendir("$dirName")) {
  61. while (false !== ($item = readdir($handle))) {
  62. if ($item != "." && $item != "..") {
  63. if (is_dir("$dirName/$item"))
  64. $this->delDirAndFile("$dirName/$item", false);
  65. else
  66. @unlink("$dirName/$item");
  67. }
  68. }
  69. closedir($handle);
  70. if (!$subdir) @rmdir($dirName);
  71. }
  72. }
  73. }