optimization install

This commit is contained in:
Tokumeikoi 2020-02-08 15:26:18 +08:00
parent 62f7d5b3e8
commit 984abba50d
3 changed files with 26 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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'),

View File

@ -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',