From aab40c27961aa7e196d1e2d14cc27434c413dd48 Mon Sep 17 00:00:00 2001 From: tianya Date: Thu, 24 Nov 2022 22:48:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9C=A8=E7=BA=BF=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/api.php | 64 ++++++++++++++++++++++++++++++++------ src/system/common.func.php | 5 ++- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/admin/api.php b/src/admin/api.php index 76dd1bcd..0fb4e669 100644 --- a/src/admin/api.php +++ b/src/admin/api.php @@ -1,4 +1,5 @@ $ver) { if ($ver->isdownload !== true) { - //TODO 从远程服务器下载 - $fileList = json_decode(file_get_contents(dirname(__FILE__) . '/../../../tools/patch-6.1.9/files.txt')); + $filesUrl = DEDEBIZCDN . '/update/' . $ver->ver . '/files.txt'; + $dhd = new DedeHttpDown(); + $dhd->OpenUrl($filesUrl); + $fileList = $dhd->GetJSON(); + $dhd->Close(); $backupVerPath = $backupPath . '/' . $ver->ver; RmRecurse($backupVerPath); mkdir($backupVerPath); @@ -143,21 +148,32 @@ if ($action === 'is_need_check_code') { //忽略src之外的目录 continue; } - $fData = file_get_contents(dirname(__FILE__) . '/../../../tools/patch-6.1.9/src' . $f->filename); + $fileUrl = DEDEBIZCDN . '/update/' . $ver->ver . '/src'.$f->filename; + $dhd = new DedeHttpDown(); + $dhd->OpenUrl($fileUrl); + $fData = $dhd->GetHtml(); + $dhd->Close(); + $f->filename = preg_replace('/^\/admin/', $curDir, $f->filename); $realFile = $backupVerPath . $f->filename; @mkdir(dirname($realFile), 0777, true); file_put_contents($realFile, $fData); } - $fData = file_get_contents(dirname(__FILE__) . '/../../../tools/patch-6.1.9/update.sql'); + $sqlUrl = DEDEBIZCDN . '/update/' . $ver->ver . '/update.sql'; + $dhd = new DedeHttpDown(); + $dhd->OpenUrl($sqlUrl); + $fData = $dhd->GetHtml(); + $dhd->Close(); $realFile = $backupVerPath . '/update.sql'; file_put_contents($realFile, $fData); + $realFile = $backupVerPath . '/files.txt'; + file_put_contents($realFile, json_encode($fileList)); $row[$k]->isdownload = true; SetCache('update', 'vers', $row); echo json_encode(array( "code" => 0, "msg" => "正在下载{$ver->ver}的版本更新文件", "data" => array( - "finish"=>false, + "finish" => false, ), )); exit; @@ -165,14 +181,43 @@ if ($action === 'is_need_check_code') { } foreach ($row as $k => $ver) { if ($ver->ispatched !== true) { - //TODO 补丁应用 + $backupVerPath = $backupPath . '/' . $ver->ver; + //执行更新SQL文件 + $sql = file_get_contents($backupVerPath . '/update.sql'); + if (!empty($sql)) { + $sql = preg_replace('#ENGINE=MyISAM#i', 'TYPE=MyISAM', $sql); + $sql41tmp = 'ENGINE=MyISAM DEFAULT CHARSET=' . $cfg_db_language; + $sql = preg_replace('#TYPE=MyISAM#i', $sql41tmp, $sql); + $sqls = explode(";\r\n", $sql); + foreach ($sqls as $sql) { + if (trim($sql) != '') { + $dsql->ExecuteNoneQuery(trim($sql)); + } + } + } + //复制文件 + $fileList = json_decode(file_get_contents($backupVerPath . '/files.txt')); + foreach ($fileList as $f) { + if (!preg_match("/^\//", $f->filename)) { + //忽略src之外的目录 + continue; + } + $f->filename = preg_replace('/^\/admin/', $curDir, $f->filename); + $srcFile = $backupVerPath . $f->filename; + $dstFile = str_replace(array("\\", "//"), '/', DEDEROOT . $f->filename); + var_dump_cli('files','srcFile',$srcFile,'dstFile',$dstFile); + // $rs = @copy($srcFile, $dstFile); + // if($rs) { + // unlink($srcFile); + // } + } $row[$k]->ispatched = true; SetCache('update', 'vers', $row); echo json_encode(array( "code" => 0, "msg" => "正在应用{$ver->ver}的版本补丁文件", "data" => array( - "finish"=>false, + "finish" => false, ), )); exit; @@ -182,9 +227,8 @@ if ($action === 'is_need_check_code') { "code" => 0, "msg" => "", "data" => array( - "finish"=>true, + "finish" => true, ), )); exit; - } diff --git a/src/system/common.func.php b/src/system/common.func.php index 724c3059..2107412d 100755 --- a/src/system/common.func.php +++ b/src/system/common.func.php @@ -82,10 +82,10 @@ if (version_compare(PHP_VERSION, '7.0.0', '>=')) { } } //一个支持在PHP Cli Server打印的方法 -function var_dump_cli($val) +function var_dump_cli($val,...$values) { ob_start(); - var_dump($val); + var_dump($val,$values); error_log(ob_get_clean(), 4); } function get_mime_type($filename) @@ -585,4 +585,3 @@ function CheckDedeVer() if (file_exists(DEDEINC.'/extend.func.php')) { require_once(DEDEINC.'/extend.func.php'); } -?> \ No newline at end of file