From f52ffac078002f26c93fa5560591699f0ef5957a Mon Sep 17 00:00:00 2001 From: WispX <1591788658@qq.com> Date: Sun, 15 Mar 2020 10:39:02 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/admin/System.php | 12 ++++++------ extend/Upgrade.php | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/application/index/controller/admin/System.php b/application/index/controller/admin/System.php index 77641de1..80f16159 100644 --- a/application/index/controller/admin/System.php +++ b/application/index/controller/admin/System.php @@ -92,7 +92,7 @@ class System extends Base public function upgrade() { Db::startTrans(); - $backup = 'backup-' . date('YmdHis') . '.zip'; + $backup = 'backups/backup-' . date('YmdHis') . '.zip'; try { $upgrade = new \Upgrade(app()->getRootPath(), $this->config['system_version']); $release = $upgrade->release(); // 获取最新版 @@ -107,15 +107,14 @@ class System extends Base // 校验 MD5 if (md5_file($file) !== $release->md5) { - @unlink(app()->getRootPath() . $backup); - throw new \Exception('安装包损坏, 请稍后重试'); + throw new \Exception('安装包损坏, 请稍后重试', 500); } $dir = $upgrade->unzip($file, $upgrade->getWorkspace()); // 解压安装包到工作区目录 - $path = rtrim($dir . $release->path, '/') . '/'; // 新版本程序根目录 + $path = rtrim($dir . $release->path, '/') . '/'; // 新版本程序解压后的根目录 $updateSql = $path . $release->sql; // 更新数据库结构 sql 文件路径 if (!$sql = @file_get_contents($updateSql)) { - throw new \Exception('SQL 文件获取失败'); + throw new \Exception('SQL 文件获取失败', 500); } // 复制 env 文件 @@ -134,7 +133,7 @@ class System extends Base $config['hostport'], ], @file_get_contents($path . '.env.example')); if (!@file_put_contents($path . '.env', $env)) { - throw new \Exception('配置文件写入失败'); + throw new \Exception('配置文件写入失败', 500); } // 创建安装锁文件 @@ -188,6 +187,7 @@ class System extends Base Db::commit(); } catch (\Exception $e) { Db::rollback(); + if ($e->getCode() === 500) @unlink(app()->getRootPath() . $backup); $this->result([], 0, $e->getMessage()); } catch (\PDOException $e) { Db::rollback(); diff --git a/extend/Upgrade.php b/extend/Upgrade.php index 122f51da..e1dcce4b 100644 --- a/extend/Upgrade.php +++ b/extend/Upgrade.php @@ -99,7 +99,7 @@ class Upgrade curl_close($curl); if ($statusCode !== 200) { - throw new \Exception('增量包下载失败, 请稍后重试!'); + throw new \Exception('安装包下载失败, 请稍后重试!'); } if (!@file_put_contents($pathname, $contents)) { @@ -226,6 +226,8 @@ class Upgrade public function backup($pathname) { $pathname = $this->rootPath . $pathname; + $dirname = dirname($pathname); + if (!is_dir($dirname)) mkdir($dirname); $zip = new \ZipArchive; $zip->open($pathname, \ZipArchive::CREATE); $files = new RecursiveIteratorIterator(