mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-31 15:00:52 +00:00
更新命令行同步文件管理
This commit is contained in:
parent
1469ce5c90
commit
6d58ab996e
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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('执行成功');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user