enhance installation checking at entrance

This commit is contained in:
printempw 2016-08-07 16:27:55 +08:00
parent c0c0478472
commit 03da79e482
3 changed files with 25 additions and 19 deletions

View File

@ -5,6 +5,7 @@ namespace App\Services;
use \Illuminate\Database\Capsule\Manager as Capsule;
use \Pecee\SimpleRouter\SimpleRouter as Router;
use App\Exceptions\ExceptionHandler;
use App\Exceptions\E;
class Boot
{
@ -19,7 +20,19 @@ class Boot
public static function checkRuntimeEnv()
{
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()
@ -49,10 +62,12 @@ class Boot
public static function bootEloquent(Array $config)
{
$capsule = new Capsule;
$capsule->addConnection($config);
$capsule->setAsGlobal();
$capsule->bootEloquent();
if (Config::checkDbConfig($config)) {
$capsule = new Capsule;
$capsule->addConnection($config);
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
}
public static function startSession()

View File

@ -42,7 +42,7 @@ class Config
return true;
}
public static function checkTableExist(Array $config)
public static function checkTableExist()
{
$tables = ['users', 'closets', 'players', 'textures', 'options'];
@ -56,11 +56,8 @@ class Config
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();
if (!is_dir($view_config['cache_path'])) {

View File

@ -21,17 +21,11 @@ Boot::loadDotEnv(BASE_DIR);
// Register Error Handler
Boot::registerErrorHandler();
$db_config = Config::getDbConfig();
// Boot Eloquent ORM
if (Config::checkDbConfig($db_config)) {
Boot::bootEloquent($db_config);
}
Boot::bootEloquent(Config::getDbConfig());
// Redirect to Setup Page
if (!Config::checkTableExist($db_config)) {
Http::redirect('../setup/index.php');
}
// Redirect if not installed
Boot::checkInstallation();
// Start Session
Boot::startSession();