mirror of
https://github.com/v2board/v2board.git
synced 2024-11-14 07:29:13 +08:00
update: fix theme init
This commit is contained in:
parent
6d6ab5543a
commit
84f8089604
@ -45,5 +45,11 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$users = User::all();
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$user->token = Helper::guid();
|
||||||
|
$user->uuid = Helper::guid(true);
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Services\ThemeService;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -20,30 +21,6 @@ class ThemeController extends Controller
|
|||||||
}, glob($path . '*'));
|
}, 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()
|
public function getThemes()
|
||||||
{
|
{
|
||||||
$themeConfigs = [];
|
$themeConfigs = [];
|
||||||
@ -54,7 +31,8 @@ class ThemeController extends Controller
|
|||||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
|
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
|
||||||
$themeConfigs[$theme] = $themeConfig;
|
$themeConfigs[$theme] = $themeConfig;
|
||||||
if (config("theme.{$theme}")) continue;
|
if (config("theme.{$theme}")) continue;
|
||||||
$this->initTheme($theme, $themeConfig['configs']);
|
$themeService = new ThemeService($theme);
|
||||||
|
$themeService->init();
|
||||||
}
|
}
|
||||||
return response([
|
return response([
|
||||||
'data' => [
|
'data' => [
|
||||||
|
48
app/Services/ThemeService.php
Normal file
48
app/Services/ThemeService.php
Normal file
@ -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}初始化失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
public/assets/admin/umi.js
vendored
2
public/assets/admin/umi.js
vendored
File diff suppressed because one or more lines are too long
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Services\ThemeService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -27,6 +28,12 @@ Route::get('/', function (Request $request) {
|
|||||||
'description' => config('v2board.app_description', 'V2Board is best'),
|
'description' => config('v2board.app_description', 'V2Board is best'),
|
||||||
'logo' => config('v2board.logo')
|
'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'));
|
$renderParams['theme_config'] = config('theme.' . config('v2board.frontend_theme', 'v2board'));
|
||||||
return view('theme::' . config('v2board.frontend_theme', 'v2board') . '.dashboard', $renderParams);
|
return view('theme::' . config('v2board.frontend_theme', 'v2board') . '.dashboard', $renderParams);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user