From 6d58ab996e95ec5e55ee536dd2ee677bcf4c5782 Mon Sep 17 00:00:00 2001 From: evoxwht <442384644@qq.com> Date: Wed, 26 Apr 2023 11:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/log/SystemFileInfoServices.php | 52 +++++++++++++++++++ crmeb/crmeb/command/Util.php | 6 ++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/crmeb/app/services/system/log/SystemFileInfoServices.php b/crmeb/app/services/system/log/SystemFileInfoServices.php index 80f8d19c7..abb876cc6 100644 --- a/crmeb/app/services/system/log/SystemFileInfoServices.php +++ b/crmeb/app/services/system/log/SystemFileInfoServices.php @@ -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; + } } \ No newline at end of file diff --git a/crmeb/crmeb/command/Util.php b/crmeb/crmeb/command/Util.php index 44b044ed9..992ef053b 100644 --- a/crmeb/crmeb/command/Util.php +++ b/crmeb/crmeb/command/Util.php @@ -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('执行成功');