From bb7ebf1e818fb393193f65652771bc9135cb58ea Mon Sep 17 00:00:00 2001 From: WispX <1591788658@qq.com> Date: Thu, 19 Mar 2020 10:46:26 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=B9=E8=BF=9B=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/admin/System.php | 35 +++++------- extend/Upgrade.php | 6 +- public/static/app/js/app.js | 57 ++++++++++++++----- 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/application/index/controller/admin/System.php b/application/index/controller/admin/System.php index f36cbfa4..237ca626 100644 --- a/application/index/controller/admin/System.php +++ b/application/index/controller/admin/System.php @@ -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); } } diff --git a/extend/Upgrade.php b/extend/Upgrade.php index 9bf84907..778d9813 100644 --- a/extend/Upgrade.php +++ b/extend/Upgrade.php @@ -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); } /** diff --git a/public/static/app/js/app.js b/public/static/app/js/app.js index 493b81db..f417040d 100644 --- a/public/static/app/js/app.js +++ b/public/static/app/js/app.js @@ -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); }, {