mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-24 14:04:07 +08:00
add auto-update
This commit is contained in:
parent
dd71272904
commit
6e726df521
@ -37,7 +37,9 @@ class AdminController extends BaseController
|
||||
|
||||
public function update()
|
||||
{
|
||||
if (Utils::getValue('action', $_GET) == "check") {
|
||||
$action = Utils::getValue('action', $_GET);
|
||||
|
||||
if ($action == "check") {
|
||||
$updater = new \Updater(\App::version());
|
||||
if ($updater->newVersionAvailable()) {
|
||||
View::json([
|
||||
@ -45,8 +47,12 @@ class AdminController extends BaseController
|
||||
'latest_version' => $updater->latest_version
|
||||
]);
|
||||
}
|
||||
} elseif ($action == "download") {
|
||||
View::show('admin.download');
|
||||
} else {
|
||||
View::show('admin.update');
|
||||
}
|
||||
View::show('admin.update');
|
||||
|
||||
}
|
||||
|
||||
public function users()
|
||||
|
@ -17,8 +17,8 @@ class Updater
|
||||
public function __construct($current_version)
|
||||
{
|
||||
$this->current_version = $current_version;
|
||||
$this->update_sources = require BASE_DIR."/config/update.php";
|
||||
$this->current_source = $this->update_sources[Option::get('update_source')];
|
||||
$this->update_sources = require BASE_DIR."/config/update.php";
|
||||
$this->current_source = $this->update_sources[\Option::get('update_source')];
|
||||
}
|
||||
|
||||
public function getUpdateInfo()
|
||||
@ -38,7 +38,7 @@ class Updater
|
||||
{
|
||||
$info = $this->getUpdateInfo();
|
||||
$this->latest_version = $info['latest_version'];
|
||||
$this->update_time = date('Y-m-d H:i:s', $info['update_time']);
|
||||
$this->update_time = date('Y-m-d H:i:s', $info['update_time']);
|
||||
}
|
||||
|
||||
public function downloadUpdate($silent = true)
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\E;
|
||||
use Blessing\Storage;
|
||||
|
||||
class Utils
|
||||
{
|
||||
|
67
resources/views/admin/download.tpl
Normal file
67
resources/views/admin/download.tpl
Normal file
@ -0,0 +1,67 @@
|
||||
@extends('admin.master')
|
||||
|
||||
@section('title', '下载更新')
|
||||
|
||||
@section('content')
|
||||
|
||||
<!-- Content Wrapper. Contains page content -->
|
||||
<div class="content-wrapper">
|
||||
<!-- Content Header (Page header) -->
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
下载更新
|
||||
<small>Download Updates</small>
|
||||
</h1>
|
||||
</section>
|
||||
|
||||
<!-- Main content -->
|
||||
<section class="content">
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">下载更新</h3>
|
||||
</div><!-- /.box-header -->
|
||||
<div class="box-body"> <?php
|
||||
$updater = new Updater(App::version());
|
||||
|
||||
if ($updater->newVersionAvailable()) {
|
||||
$zip_path = $updater->downloadUpdate(false);
|
||||
|
||||
if ($zip_path === false) {
|
||||
exit('<p>无法下载更新包。</p>');
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$extract_dir = BASE_DIR."/setup/update_cache/{$updater->latest_version}";
|
||||
$res = $zip->open($zip_path);
|
||||
|
||||
if ($res === true) {
|
||||
echo "<p>正在解压更新包</p>";
|
||||
$zip->extractTo($extract_dir);
|
||||
} else {
|
||||
exit('<p>更新包解压缩失败。错误代码:'.$res.'</p>');
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
if (Storage::copyDir($extract_dir, BASE_DIR) !== true) {
|
||||
Storage::removeDir(BASE_DIR.'/setup/update_cache/');
|
||||
exit('无法覆盖文件。');
|
||||
} else {
|
||||
echo "<p>正在覆盖文件</p>";
|
||||
Storage::removeDir(BASE_DIR.'/setup/update_cache/');
|
||||
echo "<p>正在清理</p>";
|
||||
}
|
||||
echo "<p>更新完成。</p>";
|
||||
} else {
|
||||
echo "<p>无可用更新。</p>";
|
||||
} ?>
|
||||
</div><!-- /.box-body -->
|
||||
|
||||
<div class="box-footer">
|
||||
<a href="../setup/update.php" class="btn btn-primary">下一步</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section><!-- /.content -->
|
||||
</div><!-- /.content-wrapper -->
|
||||
|
||||
@endsection
|
@ -82,7 +82,7 @@
|
||||
@endif
|
||||
</div><!-- /.box-body -->
|
||||
<div class="box-footer">
|
||||
<a <?php if (!$updater->newVersionAvailable()) echo "disabled='disabled'"; ?> href="update.php?action=download" class="btn btn-primary">马上升级</a>
|
||||
<a href="?action=download" class="btn btn-primary" {{ !$updater->newVersionAvailable() ? 'disabled="disabled"' : '' }} >马上升级</a>
|
||||
<a href="http://www.mcbbs.net/thread-552877-1-1.html" style="float: right;" class="btn btn-default">查看 MCBBS 发布贴</a>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user