mirror of
https://github.com/v2board/v2board.git
synced 2025-02-11 16:00:27 +08:00
optimization install
This commit is contained in:
parent
3f4e3d46fb
commit
ec73224671
@ -41,6 +41,7 @@ class V2boardInstall extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$this->info("
|
$this->info("
|
||||||
__ ______ ____ _
|
__ ______ ____ _
|
||||||
\ \ / /___ \| __ ) ___ __ _ _ __ __| |
|
\ \ / /___ \| __ ) ___ __ _ _ __ __| |
|
||||||
@ -49,11 +50,11 @@ class V2boardInstall extends Command
|
|||||||
\_/ |_____|____/ \___/ \__,_|_| \__,_|
|
\_/ |_____|____/ \___/ \__,_|_| \__,_|
|
||||||
");
|
");
|
||||||
if (\File::exists(base_path() . '/.lock')) {
|
if (\File::exists(base_path() . '/.lock')) {
|
||||||
$this->error('V2board 已安装,如需重新安装请删除目录下.lock文件');
|
abort(500, 'V2board 已安装,如需重新安装请删除目录下.lock文件');
|
||||||
}
|
}
|
||||||
if (!\File::exists(base_path() . '/.env')) {
|
if (!\File::exists(base_path() . '/.env')) {
|
||||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||||
$this->error('复制环境文件失败,请检查目录权限');
|
abort(500, '复制环境文件失败,请检查目录权限');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->saveToEnv([
|
$this->saveToEnv([
|
||||||
@ -68,16 +69,16 @@ class V2boardInstall extends Command
|
|||||||
try {
|
try {
|
||||||
DB::connection()->getPdo();
|
DB::connection()->getPdo();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error('数据库连接失败');
|
abort(500, '数据库连接失败');
|
||||||
}
|
}
|
||||||
$file = \File::get(base_path() . '/database/install.sql');
|
$file = \File::get(base_path() . '/database/install.sql');
|
||||||
if (!$file) {
|
if (!$file) {
|
||||||
$this->error('数据库文件不存在');
|
abort(500, '数据库文件不存在');
|
||||||
}
|
}
|
||||||
$sql = str_replace("\n", "", $file);
|
$sql = str_replace("\n", "", $file);
|
||||||
$sql = preg_split("/;/", $sql);
|
$sql = preg_split("/;/", $sql);
|
||||||
if (!is_array($sql)) {
|
if (!is_array($sql)) {
|
||||||
$this->error('数据库文件格式有误');
|
abort(500, '数据库文件格式有误');
|
||||||
}
|
}
|
||||||
$this->info('正在导入数据库请稍等...');
|
$this->info('正在导入数据库请稍等...');
|
||||||
foreach ($sql as $item) {
|
foreach ($sql as $item) {
|
||||||
@ -96,11 +97,14 @@ class V2boardInstall extends Command
|
|||||||
$password = $this->ask('请输入管理员密码?');
|
$password = $this->ask('请输入管理员密码?');
|
||||||
}
|
}
|
||||||
if (!$this->registerAdmin($email, $password)) {
|
if (!$this->registerAdmin($email, $password)) {
|
||||||
$this->error('管理员账号注册失败,请重试');
|
abort(500, '管理员账号注册失败,请重试');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('一切就绪');
|
$this->info('一切就绪');
|
||||||
\File::put(base_path() . '/.lock', time());
|
\File::put(base_path() . '/.lock', time());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerAdmin($email, $password)
|
private function registerAdmin($email, $password)
|
||||||
@ -108,7 +112,7 @@ class V2boardInstall extends Command
|
|||||||
$user = new User();
|
$user = new User();
|
||||||
$user->email = $email;
|
$user->email = $email;
|
||||||
if (strlen($password) < 8) {
|
if (strlen($password) < 8) {
|
||||||
$this->error('管理员密码长度最小为8位字符');
|
abort(500, '管理员密码长度最小为8位字符');
|
||||||
}
|
}
|
||||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$user->v2ray_uuid = Helper::guid(true);
|
$user->v2ray_uuid = Helper::guid(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user