更新程序版本1优化
This commit is contained in:
parent
3264e4b42c
commit
378ef5f3ab
@ -21,6 +21,8 @@ use think\facade\Db;
|
|||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
use app\admin\controller\Uzip;
|
use app\admin\controller\Uzip;
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
|
use taoler\com\Api;
|
||||||
|
use think\facade\Config;
|
||||||
|
|
||||||
class Upgrade extends AdminController
|
class Upgrade extends AdminController
|
||||||
{
|
{
|
||||||
@ -34,11 +36,11 @@ class Upgrade extends AdminController
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->sys_version_num = Db::name('system')->where('id',1)->value('sys_version_num');
|
$this->sys_version = Config::get('taoler.version');
|
||||||
|
$this->sys = Db::name('system')->where('id',1)->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** 升级界面 */
|
/** 升级界面 */
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
@ -88,63 +90,56 @@ class Upgrade extends AdminController
|
|||||||
//升级前的版本检测
|
//升级前的版本检测
|
||||||
public function check($url)
|
public function check($url)
|
||||||
{
|
{
|
||||||
$url = $url.'?ver='.$this->sys_version_num;
|
$url = $url.'?ver='.$this->sys_version;
|
||||||
$ch =curl_init ();
|
//$versions = json_decode(Api::urlGet($url));
|
||||||
curl_setopt($ch,CURLOPT_URL, $url);
|
$versions = Api::urlGet($url);
|
||||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
//var_dump($versions);
|
||||||
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
|
||||||
curl_setopt($ch,CURLOPT_POST, 1);
|
//判断服务器状态
|
||||||
$data = curl_exec($ch);
|
|
||||||
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($ch);
|
|
||||||
if($httpCode != '200'){
|
|
||||||
return json(['code'=>0,'msg'=>'连接服务器失败,稍后重试...']);
|
|
||||||
}
|
|
||||||
$versions = json_decode($data);
|
|
||||||
//判断状态
|
|
||||||
$version_code = $versions->code;
|
$version_code = $versions->code;
|
||||||
if($version_code == 0){
|
if($version_code == -1){
|
||||||
return json(['code'=>$version_code,'msg'=>$versions->msg]);
|
return json(['code'=>$version_code,'msg'=>$versions->msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($version_code == 1){
|
||||||
|
return json(['code'=>$versions->code,'msg'=>$versions->msg,'version'=>$versions->version,'upnum'=>$versions->up_num]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($version_code == 0){
|
||||||
|
return json(['code'=>$versions->code,'msg'=>$versions->msg]);
|
||||||
|
}
|
||||||
|
|
||||||
//版本比较
|
//版本比较
|
||||||
$version_num = $versions->version;
|
/*
|
||||||
$up_num =$versions->up_num;
|
$version_num = $versions->version; //最新版本
|
||||||
|
$up_num =$versions->up_num; //可更新版本数
|
||||||
$res = version_compare($version_num,$this->sys_version_num,'>');
|
$res = version_compare($version_num,$this->sys_version_num,'>');
|
||||||
if($res){
|
if($res){
|
||||||
return json(['code'=>1,'msg'=>'发现新版本','version'=>$version_num,'upnum'=>$up_num]);
|
return json(['code'=>1,'msg'=>'发现新版本','version'=>$version_num,'upnum'=>$up_num]);
|
||||||
} else {
|
} else {
|
||||||
return json(['code'=>0,'msg'=>'暂时还没更新哦! ==8']);
|
return json(['code'=>0,'msg'=>'暂时还没更新哦! ==8']);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动更新
|
* 在线更新
|
||||||
*/
|
*/
|
||||||
public function upload()
|
public function upload()
|
||||||
{
|
{
|
||||||
$data = Request::param();
|
$data = Request::only(['url','key']);
|
||||||
|
|
||||||
if(empty($data['key'])){
|
if(empty($data['key'])){
|
||||||
return json(["code"=>0,"msg"=>"请配置正确升级key"]);
|
return json(["code"=>0,"msg"=>"请配置正确升级key"]);
|
||||||
}
|
}
|
||||||
$url = $data['url'].'?domain='.Request::domain().'&key='.$data['key'].'&ver='.$this->sys_version_num;
|
$url = $data['url'].'?url='.$this->sys['domain'].'&key='.$data['key'].'&ver='.$this->sys_version;
|
||||||
|
//var_dump($url);
|
||||||
|
$versions = Api::urlGet($url);
|
||||||
|
|
||||||
$ch =curl_init ();
|
//判断服务器状态
|
||||||
curl_setopt($ch,CURLOPT_URL, $url);
|
|
||||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
|
||||||
curl_setopt($ch,CURLOPT_POST, 1);
|
|
||||||
$data = curl_exec($ch);
|
|
||||||
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
|
||||||
curl_close($ch);
|
|
||||||
if($httpCode != '200'){
|
|
||||||
return json(['code'=>0,'msg'=>'连接服务器失败,稍后重试...']);
|
|
||||||
}
|
|
||||||
//获取远程文件
|
|
||||||
$versions = json_decode($data);
|
|
||||||
//判断状态
|
|
||||||
$version_code = $versions->code;
|
$version_code = $versions->code;
|
||||||
if($version_code == 0){
|
if($version_code == -1){
|
||||||
return json(['code'=>$version_code,'msg'=>$versions->msg]);
|
return json(['code'=>$version_code,'msg'=>$versions->msg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +149,7 @@ class Upgrade extends AdminController
|
|||||||
//判断远程文件是否可用存在
|
//判断远程文件是否可用存在
|
||||||
$header = get_headers($file_url, true);
|
$header = get_headers($file_url, true);
|
||||||
if(!isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'))){
|
if(!isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'))){
|
||||||
return json(["code"=>0,"msg"=>"获取远程文件失败"]);
|
return json(["code"=>-1,"msg"=>"获取远程文件失败"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_dir($this->upload_dir)){
|
if(!is_dir($this->upload_dir)){
|
||||||
@ -165,7 +160,7 @@ class Upgrade extends AdminController
|
|||||||
$cpfile = copy($file_url,$package_file);
|
$cpfile = copy($file_url,$package_file);
|
||||||
if(!$cpfile)
|
if(!$cpfile)
|
||||||
{
|
{
|
||||||
return json(["code"=>0,"msg"=>"下载升级文件失败"]);
|
return json(["code"=>-1,"msg"=>"下载升级文件失败"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//记录下日志
|
//记录下日志
|
||||||
@ -185,10 +180,12 @@ class Upgrade extends AdminController
|
|||||||
$upres = $this->execute_update($package_file);
|
$upres = $this->execute_update($package_file);
|
||||||
//更新版本
|
//更新版本
|
||||||
Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
|
Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
|
||||||
|
//$res = Config::set(['version' => $version_num,'salt' => 'taoler'], 'taoler');
|
||||||
|
//var_dump($res);
|
||||||
if($upres){
|
if($upres){
|
||||||
return json(["code"=>1,"msg"=>"升级成功"]);
|
return json(["code"=>0,"msg"=>"升级成功"]);
|
||||||
}else {
|
}else {
|
||||||
return json(["code"=>0,"msg"=>"升级失败"]);
|
return json(["code"=>-1,"msg"=>"升级失败"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,6 +259,7 @@ class Upgrade extends AdminController
|
|||||||
|
|
||||||
//更新版本
|
//更新版本
|
||||||
Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
|
Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
|
||||||
|
//Config::set(['version' => $version_num], 'taoler');
|
||||||
if($upres){
|
if($upres){
|
||||||
return json(["code"=>1,"msg"=>"升级成功"]);
|
return json(["code"=>1,"msg"=>"升级成功"]);
|
||||||
}else {
|
}else {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">网站域名</label>
|
<label class="layui-form-label">网站域名</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="text" name="domain" lay-verify="url" value="{$sysInfo.domain}" class="layui-input">
|
<input type="text" name="" lay-verify="url" value="{$sysInfo.domain}" readonly class="layui-input layui-disabled">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">在线升级</label>
|
<label class="layui-form-label">在线升级</label>
|
||||||
<div class="layui-input-inline layui-input-company" id="ver_nums" >当前版本:Taole v_{$ver_num.sys_version_num}</div>
|
<div class="layui-input-inline layui-input-company" id="ver_nums" >当前版本:Taole v_{:config('taoler.version')}</div>
|
||||||
<div class="layui-upload">
|
<div class="layui-upload">
|
||||||
{if condition="checkRuleButton('admin/Upgrade/check')"}
|
{if condition="checkRuleButton('admin/Upgrade/check')"}
|
||||||
<button type="button" class="layui-btn layui-btn-sm" data-url="{$ver_num.upcheck_url}" id="upload-check">检查更新</button>
|
<button type="button" class="layui-btn layui-btn-sm" data-url="{$ver_num.upcheck_url}" id="upload-check">检查更新</button>
|
||||||
@ -122,12 +122,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//检测更新
|
//检测并更新系统
|
||||||
$('#upload-check').on('click',function(){
|
$('#upload-check').on('click',function(){
|
||||||
var url = $(this).attr('data-url'),
|
var url = $(this).attr('data-url'),
|
||||||
loading = layer.load(2, {
|
loading = layer.load(2, {
|
||||||
shade: [0.2, '#000'],
|
shade: [0.2, '#000'],
|
||||||
time: 2000,
|
//time: 2000,
|
||||||
});
|
});
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:"post",
|
type:"post",
|
||||||
@ -135,17 +135,31 @@
|
|||||||
data:{"url":url},
|
data:{"url":url},
|
||||||
daType:"json",
|
daType:"json",
|
||||||
success:function (data){
|
success:function (data){
|
||||||
if (data.code == 1) {
|
if (data.code == 0) {
|
||||||
|
//已件最新版本
|
||||||
layer.close(loading);
|
layer.close(loading);
|
||||||
$('div#ver_nums').after('<div class="layui-input-inline layui-input-company">发现<span style="color:red">'+data.upnum+'</span>个新版本:<span style="color:red">可更新至v'+data.version+'</span></div> <button class="layui-btn layui-btn-sm" lay-submit lay-filter="update_system" data-url="{$ver_num.upgrade_url}" id="update_system">确认升级</button>');
|
|
||||||
$('button#upload-check').hide();
|
|
||||||
layer.msg(data.msg,{
|
layer.msg(data.msg,{
|
||||||
icon:6,
|
icon:6,
|
||||||
time:2000
|
time:2000
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else if (data.code == 1) {
|
||||||
|
//可升级
|
||||||
|
layer.close(loading);
|
||||||
|
$('div#ver_nums').after('<div class="layui-input-inline layui-input-company">发现<span style="color:red">'+data.upnum+'</span>个新版本:<span style="color:red">可更新至v'+data.version+'</span></div>');
|
||||||
|
//$('div#ver_nums').after('<div class="layui-input-inline layui-input-company">发现<span style="color:red">'+data.upnum+'</span>个新版本:<span style="color:red">可更新至v'+data.version+'</span></div> <button class="layui-btn layui-btn-sm" lay-submit lay-filter="update_system" data-url="{$ver_num.upgrade_url}" id="update_system">确认升级</button>');
|
||||||
|
$('button#upload-check').hide();
|
||||||
|
|
||||||
|
//更新系统
|
||||||
|
layer.confirm('可更新至v'+data.version+' 确定升级?',{icon: 3, title:'升级系统'}, function(index){
|
||||||
|
uploads(); //更新
|
||||||
|
layer.close(index); //关闭load加载层
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
//服务器错误
|
||||||
|
layer.close(loading);
|
||||||
layer.open({
|
layer.open({
|
||||||
title:'添加失败',
|
title:'服务错误',
|
||||||
content:data.msg,
|
content:data.msg,
|
||||||
icon:5,
|
icon:5,
|
||||||
anim:6
|
anim:6
|
||||||
@ -156,22 +170,19 @@
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//更新
|
||||||
//确定升级操作
|
function uploads(){
|
||||||
$(document).on('click','#update_system',function(){
|
var url = "{$ver_num.upgrade_url}",
|
||||||
var url = $(this).attr('data-url'),
|
|
||||||
key = $('input[name=key]').attr("value"),
|
key = $('input[name=key]').attr("value"),
|
||||||
loading = layer.load(2, {
|
load = layer.load(); //loading
|
||||||
shade: [0.2, '#000'],
|
|
||||||
});
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:"post",
|
type:"post",
|
||||||
url:"{:url('admin/upgrade/upload')}",
|
url:"{:url('admin/upgrade/upload')}",
|
||||||
data:{"url":url,"key":key},
|
data:{"url":url,"key":key},
|
||||||
daType:"json",
|
daType:"json",
|
||||||
success:function (data){
|
success:function (data){
|
||||||
if (data.code == 1) {
|
if (data.code == 0) {
|
||||||
layer.close(loading);
|
layer.close(load);
|
||||||
layer.msg(data.msg,{
|
layer.msg(data.msg,{
|
||||||
icon:6,
|
icon:6,
|
||||||
time:2000
|
time:2000
|
||||||
@ -179,7 +190,7 @@
|
|||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
layer.close(loading);
|
layer.close(load);
|
||||||
layer.open({
|
layer.open({
|
||||||
title:'升级失败',
|
title:'升级失败',
|
||||||
content:data.msg,
|
content:data.msg,
|
||||||
@ -189,8 +200,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//确定升级操作
|
||||||
|
$(document).on('click','#update_system',function(){
|
||||||
|
//var url = $(this).attr('data-url'),
|
||||||
|
// key = $('input[name=key]').attr("value"),
|
||||||
|
uploads();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
//设置key
|
//设置key
|
||||||
$('#upgrade-key').on('click',function(){
|
$('#upgrade-key').on('click',function(){
|
||||||
var key = $('input[name=key]').val();
|
var key = $('input[name=key]').val();
|
||||||
|
@ -74,7 +74,7 @@ class Index extends BaseController
|
|||||||
$pass = md5(substr_replace(md5($data['admin_pass']),$salt,0,6));
|
$pass = md5(substr_replace(md5($data['admin_pass']),$salt,0,6));
|
||||||
$webname = $data['webname'];
|
$webname = $data['webname'];
|
||||||
$webtitle = $data['webtitle'];
|
$webtitle = $data['webtitle'];
|
||||||
$web = Request::domain();
|
$web = Request::host();
|
||||||
//数据库配置
|
//数据库配置
|
||||||
$dbhost = $data['DB_HOST'];
|
$dbhost = $data['DB_HOST'];
|
||||||
$dbuser = $data['DB_USER'];
|
$dbuser = $data['DB_USER'];
|
||||||
|
@ -21,7 +21,7 @@ class Api
|
|||||||
if($httpCode == '200'){
|
if($httpCode == '200'){
|
||||||
return json_decode($res);
|
return json_decode($res);
|
||||||
} else {
|
} else {
|
||||||
return json(['code'=>-1,'msg'=>'远程服务器失败']);
|
return json_decode('{"code":-1,"msg":"远程服务器失败,稍后重试"}'); //转换为对象
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,17 +29,17 @@ class Api
|
|||||||
{
|
{
|
||||||
$ch =curl_init ();
|
$ch =curl_init ();
|
||||||
curl_setopt($ch,CURLOPT_URL, $url);
|
curl_setopt($ch,CURLOPT_URL, $url);
|
||||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); //将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。 1表示传输数据,为0表示直接输出显示。
|
||||||
//curl_setopt($ch, CURLOPT_HEADER, 0); //启用时会将头文件的信息作为数据流输出。 参数为1表示输出信息头,为0表示不输出
|
//curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
|
||||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
|
curl_setopt($ch, CURLOPT_HEADER, false); //启用时会将头文件的信息作为数据流输出。 参数为1表示输出信息头,为0表示不输出
|
||||||
$data = curl_exec($ch);
|
$data = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
if($httpCode == '200'){
|
if($httpCode == '200'){
|
||||||
return json_decode($data);
|
return json_decode($data);
|
||||||
} else {
|
} else {
|
||||||
//return json(['code'=>-1,'msg'=>'远程服务器失败']);
|
//$status ='{"code":-1,"msg":"远程服务器失败"}'; //字符串
|
||||||
return false;
|
return json_decode('{"code":-1,"msg":"远程服务器失败,稍后重试"}'); //转换为对象
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user