blessing-skin-server/app/Http/Middleware/RedirectToSetup.php

34 lines
934 B
PHP
Raw Normal View History

2019-09-06 23:53:47 +08:00
<?php
namespace App\Http\Middleware;
use Closure;
use Composer\Semver\Comparator;
use Illuminate\Filesystem\Filesystem;
2020-06-24 10:49:53 +08:00
use Illuminate\Support\Facades\Artisan;
2019-09-06 23:53:47 +08:00
class RedirectToSetup
{
public function handle($request, Closure $next)
{
$version = config('app.version');
2019-11-13 14:27:22 +08:00
$hasLock = resolve(Filesystem::class)->exists(storage_path('install.lock'));
// If lock isn't existed, it means that BS isn't installed.
// Database is unavailable at this time, so we should disable the loader.
2019-12-14 11:10:37 +08:00
if (!$hasLock) {
2019-11-13 14:27:22 +08:00
config(['translation-loader.translation_loaders' => []]);
}
2019-12-14 11:10:37 +08:00
if ($hasLock && !$request->is('setup*') && Comparator::greaterThan($version, option('version', $version))) {
2020-06-24 10:49:53 +08:00
Artisan::call('update');
2019-09-06 23:53:47 +08:00
}
if ($hasLock || $request->is('setup*')) {
return $next($request);
}
return redirect('/setup');
}
}