改进更新功能

This commit is contained in:
WispX
2020-03-19 10:46:26 +08:00
parent cb5f2f8bce
commit bb7ebf1e81
3 changed files with 62 additions and 36 deletions
+15 -20
View File
@@ -92,10 +92,9 @@ class System extends Base
public function upgrade()
{
Db::startTrans();
$isBackup = $this->request->request('backup', true); // 是否备份原系统文件
$backup = 'backups/' . date('YmdHis') . '.zip';
$upgrade = null;
try {
$upgrade = new \Upgrade(app()->getRootPath(), $this->getConfig('system_version'));
$release = $upgrade->release(); // 获取最新版
// 判断是否已经是最新版
@@ -117,8 +116,6 @@ class System extends Base
throw new \Exception('SQL 文件获取失败');
}
$isBackup && $upgrade->backup($backup); // 备份原系统
// 创建安装锁文件
if (!@fopen($path . 'application/install.lock', 'w')) {
throw new \Exception('安装锁文件创建失败');
@@ -185,29 +182,27 @@ class System extends Base
$upgrade->rmdir($upgrade->getWorkspace());
$this->error($e->getMessage());
}
$this->success('升级完成, 文件已备份至: ' . $backup);
$this->success('升级完成');
}
public function check()
/**
* 备份系统
*/
public function backup()
{
$release = null;
$backup = 'backups/' . date('YmdHis') . '.zip';
try {
$upgrade = new \Upgrade(app()->getRootPath(), $this->getConfig('system_version'));
$release = $upgrade->release(); // 获取安装包列表
if (!$release) {
throw new \Exception('获取版本时遇到错误');
}
// 判断是否已经是最新版
if ($upgrade->check($release->version)) {
throw new \Exception('当前系统已经是最新版');
}
$upgrade->backup($backup);
} catch (\Exception $e) {
$this->error($e->getMessage());
} catch (\PDOException $e) {
$this->error($e->getMessage());
} catch (\HttpException $e) {
$this->error($e->getMessage());
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
$this->success('发现新版本', null, [
'version' => $release->version,
'info' => $release->info,
]);
$this->success('备份完成, ' . $backup);
}
}
+4 -2
View File
@@ -168,9 +168,11 @@ class Upgrade
*/
public function release()
{
$releases = $this->releases();
if (!$release = @file_get_contents(self::RELEASES_URL . '?version=last')) {
throw new \Exception('更新服务器异常, 请稍后重试!');
}
return current($releases);
return json_decode($release);
}
/**
+43 -14
View File
@@ -160,28 +160,57 @@ var app = {
});
$d.$dialog.css({'max-width': '300px'});
mdui.mutation();
setTimeout(function () {
var upgradeCallback = function () {
setTimeout(function () {
$.ajax({
url: '/admin/system/upgrade.html',
type: 'POST',
data: {backup: backup},
success: function (res) {
mdui.alert(res.msg, '系统提示', function () {
history.go(0);
}, {
modal: true,
closeOnEsc: true,
});
},
complete: function () {
$d.close();
loading = false;
},
error: function () {
mdui.alert('升级失败, 请稍后重试', '系统提示');
}
});
}, 1000)
};
if (backup) {
$.ajax({
url: '/admin/system/upgrade.html',
url: '/admin/system/backup.html',
type: 'POST',
data: {backup: backup},
success: function (res) {
mdui.alert(res.msg, '系统提示', function() {
history.go(0);
}, {
modal: true,
closeOnEsc: true,
});
if (res.code) {
upgradeCallback();
} else {
mdui.alert(res.msg, '系统提示', function () {
// history.go(0);
}, {
modal: true,
closeOnEsc: true,
});
}
},
complete: function () {
$d.close();
loading = false;
},
error: function () {
mdui.alert('升级失败, 请稍后重试', '系统提示');
mdui.alert('备份失败, 请稍后重试', '系统提示');
}
});
}, 1000)
} else {
upgradeCallback();
}
},
/**
* 检测版本更新
@@ -220,10 +249,10 @@ var app = {
mdui.confirm(
'将会在升级前备份原系统文件, 但不包括 runtime 和 public 目录以及数据库',
'⚠ 是否需要备份原系统?',
function() {
function () {
app.upgrade(true);
},
function() {
function () {
app.upgrade(false);
},
{