Files
huangjingfen/pro_v3.5.1/app/services/system/log/ClearServices.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

76 lines
2.0 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\services\system\log;
use app\services\BaseServices;
/**
* Class ClearServices
* @package app\services\system\log
*/
class ClearServices extends BaseServices
{
/** 递归删除文件
* @param $dirName
* @param bool $subdir
*/
protected function delDirAndFile($dirName)
{
$list = glob($dirName . '*');
foreach ($list as $file) {
if (is_dir($file))
$this->delDirAndFile($file . DS);
else
@unlink($file);
}
@rmdir($dirName);
}
/**
* 删除日志
*/
public function deleteLog()
{
$root = app()->getRootPath() . 'runtime' . DS;
$this->delDirAndFile($root . 'admin' . DS . 'log' . DS);
$this->delDirAndFile($root . 'api' . DS . 'log' . DS);
$this->delDirAndFile($root . 'log' . DS);
}
/**
* 刷新数据缓存
*/
public function refresCache()
{
$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', 'admin.php'])) {
$path = $p . DS . $file;
if (is_file($path)) {
@unlink($path);
} else {
$this->delDirAndFile($path . DS);
}
}
}
}
}
}