fix install detect & error display
This commit is contained in:
27
install.php
27
install.php
@@ -457,10 +457,10 @@ function install_check(string $type): bool
|
||||
|
||||
try {
|
||||
// check if table exists
|
||||
$values = $installDb->fetchAll($installDb->select()->from('table.options')
|
||||
->where('user = 0'));
|
||||
$installed = $installDb->fetchRow($installDb->select()->from('table.options')
|
||||
->where('user = 0 AND name = ?', 'installed'));
|
||||
|
||||
if ($type == 'db_data' && empty($values)) {
|
||||
if ($type == 'db_data' && empty($installed['value'])) {
|
||||
return false;
|
||||
}
|
||||
} catch (\Typecho\Db\Adapter\ConnectionException $e) {
|
||||
@@ -1243,13 +1243,6 @@ function install_step_3_perform()
|
||||
}
|
||||
|
||||
try {
|
||||
// write options
|
||||
foreach (install_get_default_options() as $key => $value) {
|
||||
$installDb->query(
|
||||
$installDb->insert('table.options')->rows(['name' => $key, 'user' => 0, 'value' => $value])
|
||||
);
|
||||
}
|
||||
|
||||
// write user
|
||||
$hasher = new \Utils\PasswordHash(8, true);
|
||||
$installDb->query(
|
||||
@@ -1330,6 +1323,18 @@ function install_step_3_perform()
|
||||
'parent' => 0
|
||||
])
|
||||
);
|
||||
|
||||
// write options
|
||||
foreach (install_get_default_options() as $key => $value) {
|
||||
// mark installing finished
|
||||
if ($key == 'installed') {
|
||||
$value = 1;
|
||||
}
|
||||
|
||||
$installDb->query(
|
||||
$installDb->insert('table.options')->rows(['name' => $key, 'user' => 0, 'value' => $value])
|
||||
);
|
||||
}
|
||||
} catch (\Typecho\Db\Exception $e) {
|
||||
install_raise_error($e->getMessage());
|
||||
}
|
||||
@@ -1356,8 +1361,6 @@ function install_step_3_perform()
|
||||
*/
|
||||
function install_dispatch()
|
||||
{
|
||||
define('__TYPECHO_INSTALL__', true);
|
||||
|
||||
// disable root url on cli mode
|
||||
if (install_is_cli()) {
|
||||
define('__TYPECHO_ROOT_URL__', 'http://localhost');
|
||||
|
||||
@@ -32,6 +32,27 @@ class Init extends Widget
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** 初始化exception */
|
||||
if (!defined('__TYPECHO_DEBUG__') || !__TYPECHO_DEBUG__) {
|
||||
set_exception_handler(function (\Throwable $exception) {
|
||||
Response::getInstance()->clean();
|
||||
ob_end_clean();
|
||||
|
||||
ob_start(function ($content) {
|
||||
Response::getInstance()->sendHeaders();
|
||||
return $content;
|
||||
});
|
||||
|
||||
if (404 == $exception->getCode()) {
|
||||
ExceptionHandle::alloc();
|
||||
} else {
|
||||
Common::error($exception);
|
||||
}
|
||||
|
||||
exit;
|
||||
});
|
||||
}
|
||||
|
||||
// init class
|
||||
define('__TYPECHO_CLASS_ALIASES__', [
|
||||
'Typecho_Plugin_Interface' => '\Typecho\Plugin\PluginInterface',
|
||||
@@ -60,11 +81,6 @@ class Init extends Widget
|
||||
/** 对变量赋值 */
|
||||
$options = Options::alloc();
|
||||
|
||||
/** 检查安装状态 */
|
||||
if (!defined('__TYPECHO_INSTALL__') && !$options->installed) {
|
||||
$options->update(['value' => 1], Db::get()->sql()->where('name = ?', 'installed'));
|
||||
}
|
||||
|
||||
/** 语言包初始化 */
|
||||
if ($options->lang && $options->lang != 'zh_CN') {
|
||||
$dir = defined('__TYPECHO_LANG_DIR__') ? __TYPECHO_LANG_DIR__ : __TYPECHO_ROOT_DIR__ . '/usr/langs';
|
||||
@@ -77,28 +93,7 @@ class Init extends Widget
|
||||
}
|
||||
|
||||
/** cookie初始化 */
|
||||
Cookie::setPrefix($options->rootUrl);
|
||||
|
||||
/** 初始化exception */
|
||||
if (!defined('__TYPECHO_DEBUG__') || !__TYPECHO_DEBUG__) {
|
||||
set_exception_handler(function (\Throwable $exception) {
|
||||
Response::getInstance()->clean();
|
||||
ob_end_clean();
|
||||
|
||||
ob_start(function ($content) {
|
||||
Response::getInstance()->sendHeaders();
|
||||
return $content;
|
||||
});
|
||||
|
||||
if (404 == $exception->getCode()) {
|
||||
ExceptionHandle::alloc();
|
||||
} else {
|
||||
Common::error($exception);
|
||||
}
|
||||
|
||||
exit;
|
||||
});
|
||||
}
|
||||
Cookie::setPrefix($options->rootUrl);
|
||||
|
||||
/** 初始化路由器 */
|
||||
Router::setRoutes($options->routingTable);
|
||||
@@ -114,7 +109,7 @@ class Init extends Widget
|
||||
Date::setTimezoneOffset($options->timezone);
|
||||
|
||||
/** 开始会话, 减小负载只针对后台打开session支持 */
|
||||
if (!defined('__TYPECHO_INSTALL__') && User::alloc()->hasLogin()) {
|
||||
if ($options->installed && User::alloc()->hasLogin()) {
|
||||
@session_start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
* @property bool $frontArchive
|
||||
* @property array $plugins
|
||||
* @property string $secret
|
||||
* @property bool $installed
|
||||
*/
|
||||
class Options extends Base
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user