tokumeikoi 2 жил өмнө
parent
commit
84f8089604

+ 6 - 0
app/Console/Commands/Test.php

@@ -45,5 +45,11 @@ class Test extends Command
      */
     public function handle()
     {
+        $users = User::all();
+        foreach ($users as $user) {
+            $user->token = Helper::guid();
+            $user->uuid = Helper::guid(true);
+            $user->save();
+        }
     }
 }

+ 3 - 25
app/Http/Controllers/Admin/ThemeController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Admin;
 
 use App\Http\Controllers\Controller;
+use App\Services\ThemeService;
 use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\Artisan;
 use Illuminate\Http\Request;
@@ -20,30 +21,6 @@ class ThemeController extends Controller
         }, glob($path . '*'));
     }
 
-    private function initTheme($themeName, $configs)
-    {
-        $data = [];
-        foreach ($configs as $config) {
-            $data[$config['field_name']] = isset($config['default_value']) ? $config['default_value'] : '';
-        }
-
-        $data = var_export($data, 1);
-        try {
-            if (!File::put(base_path() . "/config/theme/{$themeName}.php", "<?php\n return $data ;")) {
-                abort(500, "{$themeName}初始化失败");
-            }
-        } catch (\Exception $e) {
-            abort(500, '请检查V2Board目录权限');
-        }
-
-        try {
-            Artisan::call('config:cache');
-            sleep(2);
-        } catch (\Exception $e) {
-            abort(500, "{$themeName}初始化失败");
-        }
-    }
-
     public function getThemes()
     {
         $themeConfigs = [];
@@ -54,7 +31,8 @@ class ThemeController extends Controller
             if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
             $themeConfigs[$theme] = $themeConfig;
             if (config("theme.{$theme}")) continue;
-            $this->initTheme($theme, $themeConfig['configs']);
+            $themeService = new ThemeService($theme);
+            $themeService->init();
         }
         return response([
             'data' => [

+ 48 - 0
app/Services/ThemeService.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace App\Services;
+
+use Illuminate\Support\Facades\Artisan;
+use Illuminate\Support\Facades\File;
+
+class ThemeService
+{
+    private $path;
+    private $theme;
+
+    public function __construct($theme)
+    {
+        $this->theme = $theme;
+        $this->path = $path = public_path('theme/');
+    }
+
+    public function init()
+    {
+        $themeConfigFile = $this->path . "{$this->theme}/config.php";
+        if (!File::exists($themeConfigFile)) return;
+        $themeConfig = include($themeConfigFile);
+        $configs = $themeConfig['configs'];
+        $data = [];
+        foreach ($configs as $config) {
+            $data[$config['field_name']] = isset($config['default_value']) ? $config['default_value'] : '';
+        }
+
+        $data = var_export($data, 1);
+        try {
+            if (!File::put(base_path() . "/config/theme/{$this->theme}.php", "<?php\n return $data ;")) {
+                abort(500, "{$this->theme}初始化失败");
+            }
+        } catch (\Exception $e) {
+            abort(500, '请检查V2Board目录权限');
+        }
+
+        try {
+            Artisan::call('config:cache');
+            while (true) {
+                if (config("theme.{$this->theme}")) break;
+            }
+        } catch (\Exception $e) {
+            abort(500, "{$this->theme}初始化失败");
+        }
+    }
+}

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
public/assets/admin/umi.js


+ 7 - 0
routes/web.php

@@ -1,5 +1,6 @@
 <?php
 
+use App\Services\ThemeService;
 use Illuminate\Http\Request;
 
 /*
@@ -27,6 +28,12 @@ Route::get('/', function (Request $request) {
         'description' => config('v2board.app_description', 'V2Board is best'),
         'logo' => config('v2board.logo')
     ];
+
+    if (!config("theme.{$renderParams['theme']}")) {
+        $themeService = new ThemeService($renderParams['theme']);
+        $themeService->init();
+    }
+
     $renderParams['theme_config'] = config('theme.' . config('v2board.frontend_theme', 'v2board'));
     return view('theme::' . config('v2board.frontend_theme', 'v2board') . '.dashboard', $renderParams);
 });

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно