Add support for SQLite database

This commit is contained in:
printempw 2018-02-22 21:26:23 +08:00
parent 5889df5b63
commit 6a977b6de4
7 changed files with 46 additions and 11 deletions

View File

@ -18,9 +18,16 @@ class SetupController extends Controller
{
public function welcome()
{
$config = config('database.connections.mysql');
$type = get_db_type();
return view('setup.wizard.welcome')->with('server', "{$config['username']}@{$config['host']}");
if ($type === 'SQLite') {
$server = get_db_config()['database'];
} else {
$config = get_db_config();
$server = "{$config['username']}@{$config['host']}";
}
return view('setup.wizard.welcome')->with(compact('type', 'server'));
}
public function info()

View File

@ -115,7 +115,8 @@ class User extends Model
// Pass the user instance to the callback
call_user_func($callback, $user);
// Save to get uid
// Save once to get uid
$user->password = '';
$user->save();
// Save again with password

View File

@ -59,14 +59,15 @@ class BootServiceProvider extends ServiceProvider
dump([
'APP_ENV' => app()->environment(),
'DOTENV_FILE' => app()->environmentFile(),
'DB_CONNECTION' => config('database.connections.mysql')
'DB_CONNECTION' => get_db_config()
]);
}
$gbkErrorMsg = iconv('gbk', 'utf-8', $e->getMessage());
$msg = iconv('gbk', 'utf-8', $e->getMessage());
$type = get_db_type();
throw new PrettyPageException(
trans('setup.database.connection-error', ['msg' => $gbkErrorMsg]),
trans('setup.database.connection-error', compact('msg', 'type')),
$e->getCode()
);
}

View File

@ -387,3 +387,29 @@ if (! function_exists('runtime_check')) {
}
}
}
if (! function_exists('get_db_type')) {
function get_db_type($type = null)
{
$map = [
'mysql' => 'MySQL',
'sqlite' => 'SQLite',
'pgsql' => 'PostgreSQL'
];
$type = $type ?: config('database.default');
return Arr::get($map, $type, '');
}
}
if (! function_exists('get_db_config')) {
function get_db_config($type = null)
{
$type = $type ?: config('database.default');
return config("database.connections.$type");
}
}

View File

@ -1,6 +1,6 @@
database:
connection-error: "Unable to connect to the target database, please check your configuration. The server replied with: :msg"
connection-success: Connect to the target database [:server] successfully, just click NEXT to start installation.
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.
file:
permission-error: Unable to create textures folder, please check the directory permissions or place one manually.

View File

@ -1,6 +1,6 @@
database:
connection-error: 无法连接至 MySQL 服务器,请检查你的配置。服务器返回的信息: :msg
connection-success: 成功连接至 MySQL 服务器 [:server] ,点击下一步以开始安装。
connection-error: 无法连接至 :type 服务器,请检查你的配置。服务器返回的信息:「:msg」
connection-success: 成功连接至 :type 服务器 [:server] ,点击下一步以开始安装。
file:
permission-error: textures 文件夹创建失败,请确认目录权限是否正确,或者手动放置一个。

View File

@ -6,7 +6,7 @@
</h1>
<p>{{ trans('setup.wizard.welcome.text', ['version' => config('app.version')]) }}</p>
<p>{{ trans('setup.database.connection-success', ['server' => $server]) }}</p>
<p>{{ trans('setup.database.connection-success', ['server' => $server, 'type' => $type]) }}</p>
<p class="step">
<a href="{{ url('setup/info') }}" class="button button-large">{{ trans('setup.wizard.welcome.button') }}</a>