diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index f9fa74b2..76363a20 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -32,6 +32,19 @@ class SetupController extends Controller public function info() { + $existingTables = static::checkTablesExist([], true); + + // Not installed completely + if (count($existingTables) > 0) { + Log::info('Remaining tables detected, exit setup wizard now', [$existingTables]); + + $existingTables = array_map(function ($item) { + return get_db_config()['prefix'].$item; + }, $existingTables); + + throw new PrettyPageException(trans('setup.database.table-already-exists', ['tables' => json_encode($existingTables)]), 1); + } + return view('setup.wizard.info'); } @@ -60,7 +73,7 @@ class SetupController extends Controller } } - // create tables + // Create tables Artisan::call('migrate', ['--force' => true]); Log::info("[SetupWizard] Tables migrated."); @@ -169,28 +182,24 @@ class SetupController extends Controller * Check if the given tables exist in current database. * * @param array $tables - * @return bool + * @param bool $returnExisting + * @return bool|array */ - public static function checkTablesExist($tables = null) { - $totalTables = 0; - + public static function checkTablesExist($tables = [], $returnExistingTables = false) { + $existingTables = []; $tables = $tables ?: ['users', 'closets', 'players', 'textures', 'options']; foreach ($tables as $tableName) { // Table prefix will be added automatically if (Schema::hasTable($tableName)) { - $totalTables++; + $existingTables[] = $tableName; } } - if ($totalTables == count($tables)) { + if (count($existingTables) == count($tables)) { return true; } else { - // Not installed completely - foreach (array_merge($tables, ['migrations']) as $tableName) { - Schema::dropIfExists($tableName); - } - return false; + return $returnExistingTables ? $existingTables : false; } } diff --git a/resources/lang/en/setup.yml b/resources/lang/en/setup.yml index ba0d21b8..0e63e196 100644 --- a/resources/lang/en/setup.yml +++ b/resources/lang/en/setup.yml @@ -1,6 +1,7 @@ database: connection-error: "Unable to connect to the target :type database, please check your configuration. The server replied with: :msg" connection-success: Connect to the target :type database [:server] successfully, just click NEXT to start installation. + table-already-exists: There are some tables already exist in target database, which names conflict with ones we are going to create. To avoid data loss, please manually delete these tables :tables, or set a different table prefix. file: permission-error: Unable to create textures folder, please check the directory permissions or place one manually. diff --git a/resources/lang/zh_CN/setup.yml b/resources/lang/zh_CN/setup.yml index 88b8cb85..aaa10f6e 100644 --- a/resources/lang/zh_CN/setup.yml +++ b/resources/lang/zh_CN/setup.yml @@ -1,6 +1,7 @@ database: connection-error: 无法连接至 :type 服务器,请检查你的配置。服务器返回的信息:「:msg」 connection-success: 成功连接至 :type 服务器 [:server] ,点击下一步以开始安装。 + table-already-exists: 检测到目标数据库中已存在如下数据表 :tables,它们与本程序即将创建的数据表名称冲突,为了避免原有数据被覆盖,请手动删除它们,或者为本程序选择一个不同的数据表前缀。 file: permission-error: textures 文件夹创建失败,请确认目录权限是否正确,或者手动放置一个。