替换update中的System_config为_ENV

dev
laurieryayoi 7 years ago
parent d747eedadd
commit ed70ab3ed8

@ -8,7 +8,7 @@ class Update
{
public static function update($xcat)
{
global $System_Config;
global $_ENV;
$copy_result = copy(BASE_PATH . '/config/.config.php', BASE_PATH . '/config/.config.php.bak');
if ($copy_result == true) {
echo('备份成功' . PHP_EOL);
@ -33,17 +33,17 @@ class Update
$config_new = file_get_contents(BASE_PATH . '/config/.config.example.php');
//执行版本升级
$version_old = $System_Config['version'] ?? 0;
$version_old = $_ENV['version'] ?? 0;
self::old_to_new($version_old);
//将旧config迁移到新config上
$migrated = array();
foreach ($System_Config as $key => $value_reserve) {
foreach ($_ENV as $key => $value_reserve) {
if ($key == 'config_migrate_notice' || $key == 'version') {
continue;
}
$regex = '/System_Config\[\'' . $key . '\'\].*?;/s';
$regex = '/_ENV\[\'' . $key . '\'\].*?;/s';
$matches_new = array();
preg_match($regex, $config_new, $matches_new);
if (isset($matches_new[0]) == false) {
@ -55,18 +55,18 @@ class Update
preg_match($regex, $config_old, $matches_old);
$config_new = str_replace($matches_new[0], $matches_old[0], $config_new);
$migrated[] = 'System_Config[\'' . $key . '\']';
$migrated[] = '_ENV[\'' . $key . '\']';
}
echo(PHP_EOL);
//检查新增了哪些config
$regex_new = '/System_Config\[\'.*?\'\]/s';
$regex_new = '/_ENV\[\'.*?\'\]/s';
$matches_new_all = array();
preg_match_all($regex_new, $config_new, $matches_new_all);
$differences = array_diff($matches_new_all[0], $migrated);
foreach ($differences as $difference) {
if ($difference == 'System_Config[\'config_migrate_notice\']' ||
$difference == 'System_Config[\'version\']') {
if ($difference == '_ENV[\'config_migrate_notice\']' ||
$difference == '_ENV[\'version\']') {
continue;
}
//匹配注释
@ -95,7 +95,7 @@ class Update
echo('新增配置项通常带有默认值,因此通常即使不作任何改动网站也可以正常运行' . PHP_EOL);
//输出notice
$regex_notice = '/System_Config\[\'config_migrate_notice\'\].*?(?=\';)/s';
$regex_notice = '/_ENV\[\'config_migrate_notice\'\].*?(?=\';)/s';
$matches_notice = array();
preg_match($regex_notice, $config_new, $matches_notice);
$notice_new = $matches_notice[0];
@ -108,8 +108,8 @@ class Update
) + 1
);
echo('以下是迁移附注:');
if (isset($System_Config['config_migrate_notice'])) {
if ($System_Config['config_migrate_notice'] != $notice_new) {
if (isset($_ENV['config_migrate_notice'])) {
if ($_ENV['config_migrate_notice'] != $notice_new) {
echo($notice_new);
}
} else {

Loading…
Cancel
Save