Browse Source

完善更新

tags/6.2.0
tianya 1 year ago
parent
commit
d8a0d1ffb7
3 changed files with 173 additions and 34 deletions
  1. +1
    -0
      .gitignore
  2. +104
    -24
      src/admin/api.php
  3. +68
    -10
      src/admin/templets/index_body.htm

+ 1
- 0
.gitignore View File

@@ -51,3 +51,4 @@ src/static/flink/*.png
src/static/rss/*.xml
src/a/baidunews.xml
src/data/backupfile*
src/data/updatefile*

+ 104
- 24
src/admin/api.php View File

@@ -1,10 +1,20 @@
<?php
/**
* 用于后台的api接口
*
* @version $id:api.php 8:26 2022年11月20日 tianya $
* @package DedeBIZ.Administrator
* @copyright Copyright (c) 2022 DedeBIZ.COM
* @license https://www.dedebiz.com/license
* @link https://www.dedebiz.com
*/
define('AJAXLOGIN', TRUE);
define('DEDEADMIN', str_replace("\\", '/', dirname(__FILE__)));
require_once(DEDEADMIN.'/../system/common.inc.php');
require_once(DEDEINC.'/userlogin.class.php');
require_once(DEDEADMIN . '/../system/common.inc.php');
require_once(DEDEINC . '/userlogin.class.php');
AjaxHead();
$action = isset($action) && in_array($action, array('is_need_check_code','has_new_version','get_changed_files','update_backup','get_update_versions'))? $action : '';
helper('cache');
$action = isset($action) && in_array($action, array('is_need_check_code', 'has_new_version', 'get_changed_files', 'update_backup', 'get_update_versions', 'update')) ? $action : '';
/**
* 登录鉴权
*
@@ -33,27 +43,27 @@ if ($action === 'is_need_check_code') {
),
));
exit;
} else if ($action === 'has_new_version'){
require_once(DEDEINC.'/libraries/dedehttpdown.class.php');
} else if ($action === 'has_new_version') {
require_once(DEDEINC . '/libraries/dedehttpdown.class.php');
checkLogin();
//是否存在更新版本
$offUrl = DEDEBIZURL."/version?version={$cfg_version_detail}&formurl={$nurl}&phpver={$phpv}&os={$sp_os}&mysqlver={$mysql_ver}{$add_query}&json=1";
$offUrl = DEDEBIZURL . "/version?version={$cfg_version_detail}&formurl={$nurl}&phpver={$phpv}&os={$sp_os}&mysqlver={$mysql_ver}{$add_query}&json=1";
$dhd = new DedeHttpDown();
$dhd->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;

}
?>

+ 68
- 10
src/admin/templets/index_body.htm View File

@@ -212,7 +212,7 @@
</table>
<table id="stepArea3" class="table table-borderless w-100 stepArea">
<tr>
<td>软件发下以下版本的更新文件</td>
<td>软件发下以下版本的更新文件</td>
</tr>
<tr>
<td colspan="2">
@@ -220,6 +220,30 @@
</td>
</tr>
</table>
<table id="stepArea4" class="table table-borderless w-100 stepArea">
<tr>
<td>
<div class="text-center text-success">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
软件正在进行如下操作,请您耐心等待
</td>
</tr>
<tr>
<td colspan="2">
<div id="_updateMsg">...</div>
</td>
</tr>
</table>
<table id="stepArea5" class="table table-borderless w-100 stepArea">
<tr>
<td>
完成升级,恭喜您当前系统已是最新版本
</td>
</tr>
</table>
<div id="_msgInfo">
</div>
</div>
@@ -233,28 +257,50 @@
</div>
<div id="btnStep3" class="btnStep">
<button id="btnCancel" type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button id="btnGoStep3" type="button" class="btn btn-success">下载更新</button>
<button id="btnGoStep4" type="button" class="btn btn-success">下载更新</button>
</div>
<div id="btnStep5" class="btnStep">
<button id="btnOK" type="button" class="btn btn-success" data-dismiss="modal">完成</button>
</div>
</div>
</div>
</div>
</div>
<script>
var currentStep = 1; //步骤
function dedeAlter(msg, t = 'info', loading = false) {
let loadingStr = loading ? '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>' : '';
return `<div class="alert alert-${t}">${loadingStr}
${msg}
</div>`;
}
//显示步骤区域
function showStepArea(step) {
$(".stepArea").hide();
$(".btnStep").hide();
$("#stepArea" + step).show();
$("#btnStep" + step).show();
}
function update() {
$.get("api.php?action=update", function (data) {
let rs = JSON.parse(data);
if (rs.code === 0) {
$("#_updateMsg").html(rs.msg);
if (rs.data.finish === false) {
setTimeout(() => {
update();
}, 500);
} else {
currentStep++
$("#_msgInfo").html('');
$("#_msgInfo").hide();
showStepArea(currentStep);
}
}
})
}
$(document).ready(function () {
var currentStep = 1; //步骤
//显示步骤区域
function showStepArea(step) {
$(".stepArea").hide();
$(".btnStep").hide();
$("#stepArea" + step).show();
$("#btnStep" + step).show();
}
$.get("api.php?action=has_new_version", function (data) {
try {
let rs = JSON.parse(data);
@@ -313,6 +359,8 @@
})
$("#btnGoStep3").click(function () {
currentStep++
$("#_msgInfo").html('');
$("#_msgInfo").hide();
showStepArea(currentStep);
$.get("api.php?action=get_update_versions", function (data) {
let rs = JSON.parse(data);
@@ -328,6 +376,16 @@
}
})
})
$("#btnGoStep4").click(function () {
currentStep++
$("#_msgInfo").html('');
$("#_msgInfo").hide();
showStepArea(currentStep);
update();
})
$("#btnOK").click(function () {
location.reload();
})
})
</script>
</body>


Loading…
Cancel
Save