diff --git a/.gitignore b/.gitignore index 6fe772bf..6b1048ff 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ src/static/flink/*.png src/static/rss/*.xml src/a/baidunews.xml src/data/backupfile* +src/data/updatefile* diff --git a/src/admin/api.php b/src/admin/api.php index 63388931..76dd1bcd 100644 --- a/src/admin/api.php +++ b/src/admin/api.php @@ -1,10 +1,20 @@ OpenUrl($offUrl); $data = $dhd->GetHtml(); echo $data; -} else if ($action === 'get_changed_files'){ - require_once(DEDEINC.'/libraries/dedehttpdown.class.php'); +} else if ($action === 'get_changed_files') { + require_once(DEDEINC . '/libraries/dedehttpdown.class.php'); checkLogin(); // 获取本地更改过的文件 - $hashUrl = DEDEBIZCDN.'/release/'.$cfg_version_detail.'.json'; + $hashUrl = DEDEBIZCDN . '/release/' . $cfg_version_detail . '.json'; $dhd = new DedeHttpDown(); $dhd->OpenUrl($hashUrl); $data = $dhd->GetJSON(); $changedFiles = array(); foreach ($data as $file) { - $realFile = DEDEROOT. str_replace("\\", '/', $file->filename); - if ( file_exists($realFile) && md5_file($realFile) !== $file->hash) { + $realFile = DEDEROOT . str_replace("\\", '/', $file->filename); + if (file_exists($realFile) && md5_file($realFile) !== $file->hash) { $changedFiles[] = $file; continue; } @@ -66,25 +76,25 @@ if ($action === 'is_need_check_code') { ), )); exit; -} else if($action === 'update_backup'){ - require_once(DEDEINC.'/libraries/dedehttpdown.class.php'); +} else if ($action === 'update_backup') { + require_once(DEDEINC . '/libraries/dedehttpdown.class.php'); checkLogin(); // 获取本地更改过的文件 - $hashUrl = DEDEBIZCDN.'/release/'.$cfg_version_detail.'.json'; + $hashUrl = DEDEBIZCDN . '/release/' . $cfg_version_detail . '.json'; $dhd = new DedeHttpDown(); $dhd->OpenUrl($hashUrl); $data = $dhd->GetJSON(); $changedFiles = array(); $enkey = substr(md5(substr($cfg_cookie_encode, 0, 5)), 0, 10); - $backupPath = DEDEDATA."/backupfile_{$enkey}"; + $backupPath = DEDEDATA . "/backupfile_{$enkey}"; RmRecurse($backupPath); mkdir($backupPath); foreach ($data as $file) { - $realFile = DEDEROOT. str_replace("\\", '/', $file->filename); - if ( file_exists($realFile) && md5_file($realFile) !== $file->hash) { + $realFile = DEDEROOT . str_replace("\\", '/', $file->filename); + if (file_exists($realFile) && md5_file($realFile) !== $file->hash) { // 备份文件 - $dstFile = $backupPath.'/'.str_replace("\\", '/', $file->filename); - @MkdirAll(dirname($dstFile),777); + $dstFile = $backupPath . '/' . str_replace("\\", '/', $file->filename); + @mkdir(dirname($dstFile), 0777, true); copy($realFile, $dstFile); } } @@ -96,15 +106,85 @@ if ($action === 'is_need_check_code') { ), )); exit; -} else if($action === 'get_update_versions'){ - require_once(DEDEINC.'/libraries/dedehttpdown.class.php'); +} else if ($action === 'get_update_versions') { + require_once(DEDEINC . '/libraries/dedehttpdown.class.php'); checkLogin(); - // 获取本地更改过的文件 - $offUrl = DEDEBIZURL."/versions?version={$cfg_version_detail}"; + //获取本地更改过的文件 + $offUrl = DEDEBIZURL . "/versions?version={$cfg_version_detail}"; $dhd = new DedeHttpDown(); $dhd->OpenUrl($offUrl); $data = $dhd->GetHtml(); + $arr = json_decode($data); + SetCache('update', 'vers', $arr->result->Versions); echo $data; exit; +} else if ($action === 'update') { + $row = GetCache('update', 'vers'); + if (count($row) === 0) { + echo json_encode(array( + "code" => -1, + "msg" => "请先获取版本更新记录", + "data" => null, + )); + exit; + } + $enkey = substr(md5(substr($cfg_cookie_encode, 0, 5)), 0, 10); + $backupPath = DEDEDATA . "/updatefile_{$enkey}"; + mkdir($backupPath); + foreach ($row as $k => $ver) { + if ($ver->isdownload !== true) { + //TODO 从远程服务器下载 + $fileList = json_decode(file_get_contents(dirname(__FILE__) . '/../../../tools/patch-6.1.9/files.txt')); + $backupVerPath = $backupPath . '/' . $ver->ver; + RmRecurse($backupVerPath); + mkdir($backupVerPath); + foreach ($fileList as $f) { + if (!preg_match("/^\//", $f->filename)) { + //忽略src之外的目录 + continue; + } + $fData = file_get_contents(dirname(__FILE__) . '/../../../tools/patch-6.1.9/src' . $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'); + $realFile = $backupVerPath . '/update.sql'; + file_put_contents($realFile, $fData); + $row[$k]->isdownload = true; + SetCache('update', 'vers', $row); + echo json_encode(array( + "code" => 0, + "msg" => "正在下载{$ver->ver}的版本更新文件", + "data" => array( + "finish"=>false, + ), + )); + exit; + } + } + foreach ($row as $k => $ver) { + if ($ver->ispatched !== true) { + //TODO 补丁应用 + $row[$k]->ispatched = true; + SetCache('update', 'vers', $row); + echo json_encode(array( + "code" => 0, + "msg" => "正在应用{$ver->ver}的版本补丁文件", + "data" => array( + "finish"=>false, + ), + )); + exit; + } + } + echo json_encode(array( + "code" => 0, + "msg" => "", + "data" => array( + "finish"=>true, + ), + )); + exit; + } -?> \ No newline at end of file diff --git a/src/admin/templets/index_body.htm b/src/admin/templets/index_body.htm index cf7995b2..50f4ac8d 100644 --- a/src/admin/templets/index_body.htm +++ b/src/admin/templets/index_body.htm @@ -212,7 +212,7 @@ - +
软件发下以下版本的更新文件。软件发下以下版本的更新文件:
@@ -220,6 +220,30 @@
+ + + + + + + +
+
+
+ Loading... +
+
+ 软件正在进行如下操作,请您耐心等待 +
+
...
+
+ + + + +
+ 完成升级,恭喜您当前系统已是最新版本 +
@@ -233,28 +257,50 @@
- + +
+
+