From 2b0bf6cbb707fbc415159346cda9ae81b10584a4 Mon Sep 17 00:00:00 2001 From: xboard Date: Fri, 24 May 2024 13:06:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 10 ---- app/Console/Commands/XboardInstall.php | 48 ++++++++++++++----- ...n_and_is_obfs_to_server_hysteria_table.php | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index 9ce2626..2bffe56 100755 --- a/.env.example +++ b/.env.example @@ -5,16 +5,6 @@ APP_DEBUG=false APP_URL=http://localhost ADMIN_SETTING_CACHE=60 #设置缓存时间(单位秒) -#LaravelS配置 -LARAVELS_LISTEN_IP=0.0.0.0 -LARAVELS_LISTEN_PORT=80 -LARAVELS_HANDLE_STATIC=true -LARAVELS_MAX_REQUEST=1000 -LARAVELS_WORKER_NUM=2 -LARAVELS_TIMER=true - -APP_RUNNING_IN_CONSOLE=true - LOG_CHANNEL=stack DB_CONNECTION=mysql diff --git a/app/Console/Commands/XboardInstall.php b/app/Console/Commands/XboardInstall.php index 5d7cd77..3cc6d7f 100644 --- a/app/Console/Commands/XboardInstall.php +++ b/app/Console/Commands/XboardInstall.php @@ -45,7 +45,6 @@ class XboardInstall extends Command public function handle() { try { - // \Artisan::call('config:clear'); $isDocker = env('docker', false); $this->info("__ __ ____ _ "); $this->info("\ \ / /| __ ) ___ __ _ _ __ __| | "); @@ -73,9 +72,7 @@ class XboardInstall extends Command if (!file_exists(base_path($sqliteFile))) { // 创建空文件 if (!touch(base_path($sqliteFile))) { - echo "sqlite创建成功: $sqliteFile"; - } else { - echo "sqlite创建失败"; + $this->info("sqlite创建成功: $sqliteFile"); } } $envConfig = [ @@ -85,6 +82,24 @@ class XboardInstall extends Command 'DB_USERNAME' => '', 'DB_PASSWORD' => '', ]; + try { + \Config::set("database.default", 'sqlite'); + \Config::set("database.connections.sqlite.database", base_path($envConfig['DB_DATABASE'])); + \DB::purge('sqlite'); + \DB::connection('sqlite')->getPdo(); + if (!blank(\DB::connection('sqlite')->getPdo()->query("SELECT name FROM sqlite_master WHERE type='table'")->fetchAll(\PDO::FETCH_COLUMN))) { + if (confirm(label: '检测到数据库中已经存在数据,是否要清空数据库以便安装新的数据?', default: false, yes: '清空', no: '退出安装')) { + $this->info('正在清空数据库请稍等'); + $this->call('db:wipe', ['--force' => true]); + $this->info('数据库清空完成'); + } else { + return; + } + } + } catch (\Exception $e) { + // 连接失败,输出错误消息 + $this->error("数据库连接失败:" . $e->getMessage()); + } } else { $isMysqlValid = false; while (!$isMysqlValid) { @@ -93,10 +108,11 @@ class XboardInstall extends Command 'DB_HOST' => text(label: "请输入数据库地址", default: '127.0.0.1', required: true), 'DB_PORT' => text(label: '请输入数据库端口', default: '3306', required: true), 'DB_DATABASE' => text(label: '请输入数据库名', default: 'xboard', required: true), - 'DB_USERNAME' => text(label: '请输入数据库用户名', required: true), + 'DB_USERNAME' => text(label: '请输入数据库用户名', default: 'root', required: true), 'DB_PASSWORD' => text(label: '请输入数据库密码', required: false), ]; try { + \Config::set("database.default", 'mysql'); \Config::set("database.connections.mysql.host", $envConfig['DB_HOST']); \Config::set("database.connections.mysql.port", $envConfig['DB_PORT']); \Config::set("database.connections.mysql.database", $envConfig['DB_DATABASE']); @@ -105,6 +121,15 @@ class XboardInstall extends Command \DB::purge('mysql'); \DB::connection('mysql')->getPdo(); $isMysqlValid = true; + if (!blank(\DB::connection('mysql')->select('SHOW TABLES'))) { + if (confirm(label: '检测到数据库中已经存在数据,是否要清空数据库以便安装新的数据?', default: false, yes: '清空', no: '不清空')) { + $this->info('正在清空数据库请稍等'); + $this->call('db:wipe', ['--force' => true]); + $this->info('数据库清空完成'); + } else { + $isMysqlValid = false; + } + } } catch (\Exception $e) { // 连接失败,输出错误消息 $this->error("数据库连接失败:" . $e->getMessage()); @@ -127,7 +152,7 @@ class XboardInstall extends Command $envConfig['REDIS_PASSWORD'] = text(label: '请输入redis密码(默认: null)', default: ''); } $redisConfig = [ - 'client' => 'phpredis', // 或 'phpredis' + 'client' => 'phpredis', 'default' => [ 'host' => $envConfig['REDIS_HOST'], 'password' => $envConfig['REDIS_PASSWORD'], @@ -152,6 +177,7 @@ class XboardInstall extends Command ; $email = text( label: '请输入管理员账号', + default: 'admin@demo.com', required: true, validate: fn(string $email): ?string => match (true) { !filter_var($email, FILTER_VALIDATE_EMAIL) => '请输入有效的邮箱地址.', @@ -161,14 +187,10 @@ class XboardInstall extends Command $password = Helper::guid(false); $this->saveToEnv($envConfig); - \Artisan::call('config:clear'); - \Artisan::call('config:cache'); - \Artisan::call('cache:clear'); - $this->info('正在清空数据库请稍等'); - \Artisan::call('db:wipe'); - $this->info('数据库清空完成'); + $this->call('config:cache'); + $this->call('cache:clear'); $this->info('正在导入数据库请稍等...'); - \Artisan::call("migrate"); + \Artisan::call("migrate", ['--force' => true]); $this->info(\Artisan::output()); $this->info('数据库导入完成'); $this->info('开始注册管理员账号'); diff --git a/database/migrations/2023_09_29_044957_add_column_version_and_is_obfs_to_server_hysteria_table.php b/database/migrations/2023_09_29_044957_add_column_version_and_is_obfs_to_server_hysteria_table.php index c8b69ae..c2f7762 100644 --- a/database/migrations/2023_09_29_044957_add_column_version_and_is_obfs_to_server_hysteria_table.php +++ b/database/migrations/2023_09_29_044957_add_column_version_and_is_obfs_to_server_hysteria_table.php @@ -27,7 +27,7 @@ class AddColumnVersionAndIsObfsToServerHysteriaTable extends Migration public function down() { Schema::table('v2_server_hysteria', function (Blueprint $table) { - $table->dropColumn('alversionpn','is_obfs'); + $table->dropColumn('version','is_obfs'); }); } }