From 984abba50d5cb107eee140f02614a6df018420d2 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Sat, 8 Feb 2020 15:26:18 +0800 Subject: [PATCH] optimization install --- app/Console/Commands/V2boardInstall.php | 27 ++++++++++++++++--- .../Controllers/Admin/ConfigController.php | 1 + app/Http/Requests/Admin/ConfigSave.php | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/V2boardInstall.php b/app/Console/Commands/V2boardInstall.php index d1e8613b..4109d96c 100644 --- a/app/Console/Commands/V2boardInstall.php +++ b/app/Console/Commands/V2boardInstall.php @@ -43,10 +43,23 @@ class V2boardInstall extends Command if (\File::exists(base_path() . '/.lock')) { abort(500, 'V2board 已安装,如需重新安装请删除目录下.lock文件'); } - \Artisan::call('key:generate'); - sleep(2); + if (!\File::exists(base_path() . '/.env')) { + if (!copy('/.env.example', '.env')) { + abort(500, '复制环境文件失败,请检查目录权限'); + } + } + $this->saveToEnv([ + 'APP_KEY' => 'base64:' . base64_encode(Encrypter::generateKey('AES-256-CBC')), + 'DB_HOST' => $this->ask('请输入数据库地址(默认:localhost)', 'localhost'), + 'DB_DATABASE' => $this->ask('请输入数据库名'), + 'DB_USERNAME' => $this->ask('请输入数据库用户名'), + 'DB_PASSWORD' => $this->ask('请输入数据库密码') + ]); + \Artisan::call('config:clear'); \Artisan::call('config:cache'); - DB::connection()->getPdo(); + if (!DB::connection()->getPdo()) { + abort(500, '数据库连接失败'); + } $file = \File::get(base_path() . '/database/install.sql'); if (!$file) { abort(500, '数据库文件不存在'); @@ -92,4 +105,12 @@ class V2boardInstall extends Command $user->is_admin = 1; return $user->save(); } + + private function saveToEnv($data = []) + { + foreach($data as $key => $value) { + set_env_var($key, $value); + } + return true; + } } diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index 467a2f48..1cb8129c 100755 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -24,6 +24,7 @@ class ConfigController extends Controller 'invite_never_expire' => config('v2board.invite_never_expire', 0) ], 'site' => [ + 'save_mode' => (int)config('v2board.save_mode', 0), 'stop_register' => (int)config('v2board.stop_register', 0), 'email_verify' => (int)config('v2board.email_verify', 0), 'app_name' => config('v2board.app_name', 'V2Board'), diff --git a/app/Http/Requests/Admin/ConfigSave.php b/app/Http/Requests/Admin/ConfigSave.php index 76fae1fd..0e7f8f27 100755 --- a/app/Http/Requests/Admin/ConfigSave.php +++ b/app/Http/Requests/Admin/ConfigSave.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Http\FormRequest; class ConfigSave extends FormRequest { CONST RULES = [ + 'save_mode' => 'in:0,1', 'invite_force' => 'in:0,1', 'invite_commission' => 'integer', 'invite_gen_limit' => 'integer',