更新命令行同步文件管理

This commit is contained in:
evoxwht 2023-04-26 11:04:58 +08:00
parent 1469ce5c90
commit 6d58ab996e
2 changed files with 57 additions and 1 deletions

View File

@ -21,4 +21,56 @@ class SystemFileInfoServices extends BaseServices
{
$this->dao = $dao;
}
public function syncfile()
{
$list = $this->flattenArray($this->scanDirectory());
// $this->dao->saveAll($list);
}
public function scanDirectory($dir = '')
{
if ($dir == '') $dir = root_path();
$result = array();
$files = scandir($dir);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
$path = $dir . '/' . $file;
$fileInfo = array(
'name' => $file,
'update_time' => date('Y-m-d H:i:s', filemtime($path)),
'create_time' => date('Y-m-d H:i:s', filectime($path)),
'path' => str_replace(root_path(), '', $dir),
'full_path' => str_replace(root_path(), '', $path),
);
if (is_dir($path)) {
$fileInfo['type'] = 'dir';
$fileInfo['contents'] = $this->scanDirectory($path);
} else {
$fileInfo['type'] = 'file';
}
$result[] = $fileInfo;
}
}
return $result;
}
public function flattenArray($arr)
{
$result = array();
foreach ($arr as $item) {
$result[] = array(
'name' => $item['name'],
'type' => $item['type'],
'update_time' => $item['update_time'],
'create_time' => $item['create_time'],
'path' => $item['path'],
'full_path' => $item['full_path'],
);
if (isset($item['contents'])) {
$result = array_merge($result, $this->flattenArray($item['contents']));
}
}
return $result;
}
}

View File

@ -3,6 +3,7 @@
namespace crmeb\command;
use app\services\system\log\SystemFileInfoServices;
use app\services\system\SystemRouteServices;
use crmeb\exceptions\AdminException;
use think\console\Command;
@ -18,7 +19,7 @@ class Util extends Command
protected function configure()
{
$this->setName('util')
->addArgument('type', Argument::REQUIRED, '类型replace/route')
->addArgument('type', Argument::REQUIRED, '类型replace/route/file')
->addOption('h', null, Option::VALUE_REQUIRED, '替换成当前域名')
->addOption('u', null, Option::VALUE_REQUIRED, '替换的域名')
->addOption('a', null, Option::VALUE_REQUIRED, '应用名')
@ -48,6 +49,9 @@ class Util extends Command
}
app()->make(SystemRouteServices::class)->syncRoute($appName);
break;
case 'file':
app()->make(SystemFileInfoServices::class)->syncfile();
break;
}
$output->info('执行成功');