mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
f2477f437b
Remove Utils::versionCompare method.
103 lines
2.7 KiB
PHP
103 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use DB;
|
|
use View;
|
|
use Utils;
|
|
use Illuminate\Http\Request;
|
|
use Composer\Semver\Comparator;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use App\Exceptions\PrettyPageException;
|
|
use App\Http\Controllers\SetupController;
|
|
use App\Services\Repositories\OptionRepository;
|
|
|
|
class BootServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot(Request $request)
|
|
{
|
|
// Detect current locale
|
|
$this->app->call('App\Http\Middleware\DetectLanguagePrefer@detect');
|
|
|
|
$this->checkFilePermissions();
|
|
$this->checkDatabaseConnection();
|
|
|
|
// Skip the installation check when setup or under CLI
|
|
if (! $request->is('setup*') && PHP_SAPI != "cli") {
|
|
$this->checkInstallation();
|
|
}
|
|
}
|
|
|
|
protected function checkFilePermissions()
|
|
{
|
|
// Check dotenv file
|
|
if (! file_exists(app()->environmentFile())) {
|
|
throw new PrettyPageException(trans('setup.file.no-dot-env'), -1);
|
|
}
|
|
|
|
// Check permissions of storage path
|
|
if (! is_writable(storage_path())) {
|
|
throw new PrettyPageException(trans('setup.permissions.storage'), -1);
|
|
}
|
|
|
|
if (! SetupController::checkDirectories()) {
|
|
throw new PrettyPageException(trans('setup.file.permission-error'), -1);
|
|
}
|
|
}
|
|
|
|
protected function checkDatabaseConnection()
|
|
{
|
|
try {
|
|
DB::connection()->getPdo();
|
|
} catch (\Exception $e) {
|
|
if ($this->app->runningInConsole()) {
|
|
// Dump some useful information for debugging
|
|
dump([
|
|
'APP_ENV' => app()->environment(),
|
|
'DOTENV_FILE' => app()->environmentFile(),
|
|
'DB_CONNECTION' => get_db_config()
|
|
]);
|
|
}
|
|
|
|
$msg = iconv('gbk', 'utf-8', $e->getMessage());
|
|
$type = get_db_type();
|
|
|
|
throw new PrettyPageException(
|
|
trans('setup.database.connection-error', compact('msg', 'type')),
|
|
$e->getCode()
|
|
);
|
|
}
|
|
}
|
|
|
|
protected function checkInstallation()
|
|
{
|
|
// Redirect to setup wizard
|
|
if (! SetupController::checkTablesExist()) {
|
|
return redirect('/setup')->send();
|
|
}
|
|
|
|
if (Comparator::greaterThan(config('app.version'), option('version'))) {
|
|
return redirect('/setup/update')->send();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
View::addExtension('tpl', 'blade');
|
|
|
|
$this->app->singleton('options', OptionRepository::class);
|
|
}
|
|
}
|