From d24bd761b88a85b95396b3ada1158b00dfac20f6 Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 29 Jul 2016 12:45:35 +0800 Subject: [PATCH] fix table prefix at installation --- app/Services/Config.php | 2 +- app/Services/Migration.php | 17 ++++++++++------ setup/index.php | 41 ++++++++++---------------------------- setup/options.php | 31 ++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 setup/options.php diff --git a/app/Services/Config.php b/app/Services/Config.php index f1c02af0..fea9182c 100644 --- a/app/Services/Config.php +++ b/app/Services/Config.php @@ -47,7 +47,7 @@ class Config $tables = ['users', 'closets', 'players', 'textures', 'options']; foreach ($tables as $table_name) { - $table_name = $config['prefix'].$table_name; + // prefix will be added automatically if (!Schema::hasTable($table_name)) { return false; } diff --git a/app/Services/Migration.php b/app/Services/Migration.php index 8f564e84..63537982 100644 --- a/app/Services/Migration.php +++ b/app/Services/Migration.php @@ -4,9 +4,14 @@ namespace App\Services; class Migration { - public static function creatTables($prefix = "") + /** + * Create tables, prefix will be added automatically + * + * @return void + */ + public static function creatTables() { - Schema::create($prefix.'users', function($table) { + Schema::create('users', function($table) { $table->increments('uid'); $table->string('email', 100); $table->string('nickname', 50); @@ -19,12 +24,12 @@ class Migration $table->dateTime('register_at'); }); - Schema::create($prefix.'closets', function($table) { + Schema::create('closets', function($table) { $table->increments('uid'); $table->longText('textures'); }); - Schema::create($prefix.'players', function($table) { + Schema::create('players', function($table) { $table->increments('pid'); $table->integer('uid'); $table->string('player_name', 50); @@ -35,7 +40,7 @@ class Migration $table->dateTime('last_modified'); }); - Schema::create($prefix.'textures', function($table) { + Schema::create('textures', function($table) { $table->increments('tid'); $table->string('name', 50); $table->string('type', 10); @@ -47,7 +52,7 @@ class Migration $table->dateTime('upload_at'); }); - Schema::create($prefix.'options', function($table) { + Schema::create('options', function($table) { $table->increments('id'); $table->string('option_name', 50); $table->longText('option_value'); diff --git a/setup/index.php b/setup/index.php index 16f96f20..7412fdaa 100644 --- a/setup/index.php +++ b/setup/index.php @@ -9,17 +9,12 @@ define('BASE_DIR', dirname(dirname(__FILE__))); // Register Composer Auto Loader require BASE_DIR.'/vendor/autoload.php'; -// Load Aliases +// Boot Services App\Services\Boot::loadServices(); - -// Check Runtime Environment Boot::checkRuntimeEnv(); - -// Load dotenv Configuration Boot::loadDotEnv(BASE_DIR); - -// Register Error Handler Boot::registerErrorHandler(); +Boot::startSession(); $db_config = Config::getDbConfig(); @@ -28,8 +23,6 @@ if (Config::checkDbConfig($db_config)) { Boot::bootEloquent($db_config); } -Boot::startSession(); - // If already installed if (Config::checkTableExist($db_config)) { View::show('setup.locked'); @@ -72,39 +65,27 @@ switch ($step) { } else { Http::redirect('index.php?step=2', '邮箱格式不正确。'); } - } else { + } + else { Http::redirect('index.php?step=2', '表单信息不完整。'); } + // create tables Migration::creatTables($db_config['prefix']); - $options = [ - 'site_url' => Http::getBaseUrl(), - 'site_name' => $_POST['sitename'], - 'site_description' => '开源的 PHP Minecraft 皮肤站', - 'user_can_register' => '1', - 'regs_per_ip' => '3', - 'api_type' => '0', - 'announcement' => '欢迎使用 Blessing Skin Server 3.0!', - 'color_scheme' => 'skin-blue', - 'home_pic_url' => './assets/images/bg.jpg', - 'current_version' => '3.0-beta', - 'custom_css' => '', - 'custom_js' => '', - 'update_url' => 'https://work.prinzeugen.net/update.json', - 'allow_chinese_playername' => '1', - 'show_footer_copyright' => '1', - 'comment_script' => '', - 'user_initial_score' => '1000', - 'sign_gap_time' => '24' - ]; + // import options + $options = require "options.php"; + $options['site_name'] = $_POST['sitename']; + $options['site_url'] = Http::getBaseUrl(); foreach ($options as $key => $value) { Option::add($key, $value); } + // register super admin $user = new App\Models\User($_POST['email']); $user->register($_POST['password'], Http::getRealIP()); + $user->setPermission('2'); if (!is_dir(BASE_DIR.'/textures/')) { if (!mkdir(BASE_DIR.'/textures/')) diff --git a/setup/options.php b/setup/options.php new file mode 100644 index 00000000..7730961e --- /dev/null +++ b/setup/options.php @@ -0,0 +1,31 @@ + '', + 'site_name' => 'Blessing Skin Server', + 'site_description' => '开源的 PHP Minecraft 皮肤站', + 'user_can_register' => '1', + 'regs_per_ip' => '3', + 'api_type' => '0', + 'announcement' => '欢迎使用 Blessing Skin Server 3.0!', + 'color_scheme' => 'skin-blue', + 'home_pic_url' => './assets/images/bg.jpg', + 'current_version' => '3.0-beta', + 'custom_css' => '', + 'custom_js' => '', + 'update_url' => 'https://work.prinzeugen.net/update.json', + 'allow_chinese_playername' => '1', + 'show_footer_copyright' => '1', + 'comment_script' => '', + 'user_initial_score' => '1000', + 'sign_gap_time' => '24', + 'sign_score' => '10,100', + 'score_per_storage' => '1', + 'score_per_player' => '100' +];