Переглянути джерело

更新命令行同步文件管理

evoxwht 2 роки тому
батько
коміт
6d58ab996e

+ 52 - 0
crmeb/app/services/system/log/SystemFileInfoServices.php

@@ -21,4 +21,56 @@ class SystemFileInfoServices extends BaseServices
     {
     {
         $this->dao = $dao;
         $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;
+    }
 }
 }

+ 5 - 1
crmeb/crmeb/command/Util.php

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