enhance installation checking at entrance
This commit is contained in:
parent
c0c0478472
commit
03da79e482
|
|
@ -5,6 +5,7 @@ namespace App\Services;
|
||||||
use \Illuminate\Database\Capsule\Manager as Capsule;
|
use \Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use \Pecee\SimpleRouter\SimpleRouter as Router;
|
use \Pecee\SimpleRouter\SimpleRouter as Router;
|
||||||
use App\Exceptions\ExceptionHandler;
|
use App\Exceptions\ExceptionHandler;
|
||||||
|
use App\Exceptions\E;
|
||||||
|
|
||||||
class Boot
|
class Boot
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +20,19 @@ class Boot
|
||||||
public static function checkRuntimeEnv()
|
public static function checkRuntimeEnv()
|
||||||
{
|
{
|
||||||
Config::checkPHPVersion();
|
Config::checkPHPVersion();
|
||||||
Config::checkFolderExist();
|
Config::checkCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function checkInstallation()
|
||||||
|
{
|
||||||
|
if (!Config::checkTableExist()) {
|
||||||
|
Http::redirect('../setup/index.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_dir(BASE_DIR.'/textures/')) {
|
||||||
|
throw new E("检测到 `textures` 文件夹已被删除,请重新运行 <a href='./setup'>安装程序</a>,或者手动放置一个。", -1, true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function loadServices()
|
public static function loadServices()
|
||||||
|
|
@ -49,10 +62,12 @@ class Boot
|
||||||
|
|
||||||
public static function bootEloquent(Array $config)
|
public static function bootEloquent(Array $config)
|
||||||
{
|
{
|
||||||
$capsule = new Capsule;
|
if (Config::checkDbConfig($config)) {
|
||||||
$capsule->addConnection($config);
|
$capsule = new Capsule;
|
||||||
$capsule->setAsGlobal();
|
$capsule->addConnection($config);
|
||||||
$capsule->bootEloquent();
|
$capsule->setAsGlobal();
|
||||||
|
$capsule->bootEloquent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function startSession()
|
public static function startSession()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class Config
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkTableExist(Array $config)
|
public static function checkTableExist()
|
||||||
{
|
{
|
||||||
$tables = ['users', 'closets', 'players', 'textures', 'options'];
|
$tables = ['users', 'closets', 'players', 'textures', 'options'];
|
||||||
|
|
||||||
|
|
@ -56,11 +56,8 @@ class Config
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkFolderExist()
|
public static function checkCache()
|
||||||
{
|
{
|
||||||
if (!is_dir(BASE_DIR."/textures/"))
|
|
||||||
throw new E("根目录下未发现 `textures` 文件夹,请先运行 <a href='./setup'>安装程序</a>,或者手动放置一个。", -1, true);
|
|
||||||
|
|
||||||
$view_config = self::getViewConfig();
|
$view_config = self::getViewConfig();
|
||||||
|
|
||||||
if (!is_dir($view_config['cache_path'])) {
|
if (!is_dir($view_config['cache_path'])) {
|
||||||
|
|
|
||||||
12
index.php
12
index.php
|
|
@ -21,17 +21,11 @@ Boot::loadDotEnv(BASE_DIR);
|
||||||
// Register Error Handler
|
// Register Error Handler
|
||||||
Boot::registerErrorHandler();
|
Boot::registerErrorHandler();
|
||||||
|
|
||||||
$db_config = Config::getDbConfig();
|
|
||||||
|
|
||||||
// Boot Eloquent ORM
|
// Boot Eloquent ORM
|
||||||
if (Config::checkDbConfig($db_config)) {
|
Boot::bootEloquent(Config::getDbConfig());
|
||||||
Boot::bootEloquent($db_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect to Setup Page
|
// Redirect if not installed
|
||||||
if (!Config::checkTableExist($db_config)) {
|
Boot::checkInstallation();
|
||||||
Http::redirect('../setup/index.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start Session
|
// Start Session
|
||||||
Boot::startSession();
|
Boot::startSession();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user