blessing-skin-server/setup/update.php
2016-09-28 22:56:21 +08:00

68 lines
1.7 KiB
PHP

<?php
/**
* Update Bootstrap of Blessing Skin Server
*/
require __DIR__."/includes/bootstrap.php";
// If no update is available
if (config('app.version') == Option::get('version', '')) {
View::show('setup.locked');
exit;
}
$step = isset($_GET['step']) ? $_GET['step'] : '1';
switch ($step) {
case '1':
View::show('setup.updates.welcome');
break;
case '2':
$resource = opendir(BASE_DIR."/setup/update_scripts/");
$update_script_exist = false;
$tips = [];
while($filename = @readdir($resource)) {
if ($filename != "." && $filename != "..") {
preg_match('/update-(.*)-to-(.*).php/', $filename, $matches);
if (isset($matches[2])) {
$update_script_exist = ($matches[2] == config('app.version'));
} else {
continue;
}
$result = require BASE_DIR."/setup/update_scripts/$filename";
if (is_array($result)) {
// push tip to array
foreach ($result as $tip) {
$tips[] = $tip;
}
}
}
}
closedir($resource);
foreach (config('options') as $key => $value) {
if (!Option::has($key))
Option::set($key, $value);
}
if (!$update_script_exist) {
// if update script is not given
Option::set('version', config('app.version'));
}
View::show('setup.updates.success', ['tips' => $tips]);
break;
default:
throw new App\Exceptions\PrettyPageException('非法参数', 1, true);
break;
}