mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
[更新]调整更新指令代码
This commit is contained in:
parent
bf6efadd19
commit
e7be978c5a
@ -30,13 +30,10 @@ class Update extends Controller
|
||||
*/
|
||||
public function tree()
|
||||
{
|
||||
$modules = PlugsExtend::instance($this->app)->buildFileList([
|
||||
'think', 'app/admin', 'public/static',
|
||||
]);
|
||||
dump($modules);
|
||||
$this->success('获取当前文件列表成功!', $modules, [
|
||||
'public/static/self'
|
||||
]);
|
||||
$extend = PlugsExtend::instance($this->app);
|
||||
$this->rules = unserialize($this->request->post('rules', 'a:0:{}', ''));
|
||||
$this->ignore = unserialize($this->request->post('ignore', 'a:0:{}', ''));
|
||||
$this->success('获取当前文件列表成功!', $extend->buildFileList($this->rules, $this->ignore));
|
||||
}
|
||||
|
||||
/**
|
||||
|
8
composer.lock
generated
8
composer.lock
generated
@ -783,12 +783,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||
"reference": "807551211513e43997e343039ddc1bd19cffa49f"
|
||||
"reference": "0a9e2ada86bf3bf3b3828a82d0f27df5f929b55f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/807551211513e43997e343039ddc1bd19cffa49f",
|
||||
"reference": "807551211513e43997e343039ddc1bd19cffa49f",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0a9e2ada86bf3bf3b3828a82d0f27df5f929b55f",
|
||||
"reference": "0a9e2ada86bf3bf3b3828a82d0f27df5f929b55f",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@ -832,7 +832,7 @@
|
||||
],
|
||||
"description": "ThinkPHP v6.0 Development Library",
|
||||
"homepage": "http://framework.thinkadmin.top",
|
||||
"time": "2019-11-01T08:30:38+00:00"
|
||||
"time": "2019-11-01T10:39:55+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253::getLoader();
|
||||
return ComposerAutoloaderInit0b662654c649e6d1b22f688c84d1a1fb::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -150,6 +150,7 @@ return array(
|
||||
'think\\admin\\extend\\ExpressExtend' => $vendorDir . '/zoujingli/think-library/src/extend/ExpressExtend.php',
|
||||
'think\\admin\\extend\\HttpExtend' => $vendorDir . '/zoujingli/think-library/src/extend/HttpExtend.php',
|
||||
'think\\admin\\extend\\NodeExtend' => $vendorDir . '/zoujingli/think-library/src/extend/NodeExtend.php',
|
||||
'think\\admin\\extend\\PlugsExtend' => $vendorDir . '/zoujingli/think-library/src/extend/PlugsExtend.php',
|
||||
'think\\admin\\extend\\ProcessExtend' => $vendorDir . '/zoujingli/think-library/src/extend/ProcessExtend.php',
|
||||
'think\\admin\\extend\\TokenExtend' => $vendorDir . '/zoujingli/think-library/src/extend/TokenExtend.php',
|
||||
'think\\admin\\helper\\DeleteHelper' => $vendorDir . '/zoujingli/think-library/src/helper/DeleteHelper.php',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253
|
||||
class ComposerAutoloaderInit0b662654c649e6d1b22f688c84d1a1fb
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -19,15 +19,15 @@ class ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit0b662654c649e6d1b22f688c84d1a1fb', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit0b662654c649e6d1b22f688c84d1a1fb', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require_once __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit66f83d66f674d4aec69a8b4e93085253::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit0b662654c649e6d1b22f688c84d1a1fb::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
@ -48,19 +48,19 @@ class ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit66f83d66f674d4aec69a8b4e93085253::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit0b662654c649e6d1b22f688c84d1a1fb::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire66f83d66f674d4aec69a8b4e93085253($fileIdentifier, $file);
|
||||
composerRequire0b662654c649e6d1b22f688c84d1a1fb($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire66f83d66f674d4aec69a8b4e93085253($fileIdentifier, $file)
|
||||
function composerRequire0b662654c649e6d1b22f688c84d1a1fb($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit66f83d66f674d4aec69a8b4e93085253
|
||||
class ComposerStaticInit0b662654c649e6d1b22f688c84d1a1fb
|
||||
{
|
||||
public static $files = array (
|
||||
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
|
||||
@ -241,6 +241,7 @@ class ComposerStaticInit66f83d66f674d4aec69a8b4e93085253
|
||||
'think\\admin\\extend\\ExpressExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/ExpressExtend.php',
|
||||
'think\\admin\\extend\\HttpExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/HttpExtend.php',
|
||||
'think\\admin\\extend\\NodeExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/NodeExtend.php',
|
||||
'think\\admin\\extend\\PlugsExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/PlugsExtend.php',
|
||||
'think\\admin\\extend\\ProcessExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/ProcessExtend.php',
|
||||
'think\\admin\\extend\\TokenExtend' => __DIR__ . '/..' . '/zoujingli/think-library/src/extend/TokenExtend.php',
|
||||
'think\\admin\\helper\\DeleteHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/DeleteHelper.php',
|
||||
@ -468,9 +469,9 @@ class ComposerStaticInit66f83d66f674d4aec69a8b4e93085253
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit66f83d66f674d4aec69a8b4e93085253::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit66f83d66f674d4aec69a8b4e93085253::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit66f83d66f674d4aec69a8b4e93085253::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0b662654c649e6d1b22f688c84d1a1fb::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit0b662654c649e6d1b22f688c84d1a1fb::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit0b662654c649e6d1b22f688c84d1a1fb::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -805,12 +805,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||
"reference": "807551211513e43997e343039ddc1bd19cffa49f"
|
||||
"reference": "0a9e2ada86bf3bf3b3828a82d0f27df5f929b55f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/807551211513e43997e343039ddc1bd19cffa49f",
|
||||
"reference": "807551211513e43997e343039ddc1bd19cffa49f",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0a9e2ada86bf3bf3b3828a82d0f27df5f929b55f",
|
||||
"reference": "0a9e2ada86bf3bf3b3828a82d0f27df5f929b55f",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@ -826,7 +826,7 @@
|
||||
"ext-json": "*",
|
||||
"topthink/framework": "^6.0"
|
||||
},
|
||||
"time": "2019-11-01T08:30:38+00:00",
|
||||
"time": "2019-11-01T10:39:55+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"think": {
|
||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// This file is automatically generated at:2019-11-01 16:54:25
|
||||
// This file is automatically generated at:2019-11-01 18:45:39
|
||||
declare (strict_types = 1);
|
||||
return array (
|
||||
0 => 'think\\app\\Service',
|
||||
|
@ -66,7 +66,7 @@ class ThinkLibrary extends Service
|
||||
'think\admin\queue\StartQueue',
|
||||
'think\admin\queue\QueryQueue',
|
||||
'think\admin\queue\ListenQueue',
|
||||
'think\admin\plugs\AdminPlugs'
|
||||
'think\admin\plugs\AdminPlugs',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -48,10 +48,16 @@ class PlugsExtend
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* 指定文件规则
|
||||
* 文件规则
|
||||
* @var array
|
||||
*/
|
||||
protected $modules = [];
|
||||
protected $rules = [];
|
||||
|
||||
/**
|
||||
* 忽略规则
|
||||
* @var array
|
||||
*/
|
||||
protected $ignore = [];
|
||||
|
||||
/**
|
||||
* 当前实例
|
||||
@ -79,9 +85,12 @@ class PlugsExtend
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
// 应用框架版本号
|
||||
$this->version = $this->app->config->get('app.thinkadmin_ver');
|
||||
if (empty($this->version)) $this->version = 'v4';
|
||||
// 线上应用代码
|
||||
$this->uri = "https://{$this->version}.thinkadmin.top";
|
||||
// 当前应用根目录
|
||||
$this->path = strtr($this->app->getRootPath(), '\\', '/');
|
||||
}
|
||||
|
||||
@ -117,13 +126,12 @@ class PlugsExtend
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下载更新文件内容
|
||||
* @param string $encode
|
||||
* @return boolean|integer
|
||||
*/
|
||||
public function downloadFile($encode)
|
||||
private function downloadFile($encode)
|
||||
{
|
||||
$result = json_decode(http_get("{$this->uri}?s=admin/api.update/get/{$encode}"), true);
|
||||
if (empty($result['code'])) return false;
|
||||
@ -136,7 +144,7 @@ class PlugsExtend
|
||||
* 清理空目录
|
||||
* @param string $path
|
||||
*/
|
||||
public function removeEmptyDirectory($path)
|
||||
private function removeEmptyDirectory($path)
|
||||
{
|
||||
if (is_dir($path) && count(scandir($path)) === 2 && rmdir($path)) {
|
||||
$this->removeEmptyDirectory(dirname($path));
|
||||
@ -145,20 +153,21 @@ class PlugsExtend
|
||||
|
||||
/**
|
||||
* 获取文件差异数据
|
||||
* @param array $rules 文件规则
|
||||
* @param array $ignore 忽略规则
|
||||
* @return array
|
||||
*/
|
||||
public function grenerateDifference($modules = [], $data = [])
|
||||
public function grenerateDifference($rules = [], $ignore = [])
|
||||
{
|
||||
$this->modules = $modules;
|
||||
$result = json_decode(HttpExtend::get("{$this->uri}?s=/admin/api.update/tree"), true);
|
||||
if (empty($result['code'])) return [];
|
||||
$new = $this->buildFileList($result['data']['paths'], $result['data']['ignores']);
|
||||
foreach ($this->grenerateDifferenceContrast($result['data']['list'], $new['list']) as $file) {
|
||||
if (in_array($file['type'], ['add', 'del', 'mod'])) {
|
||||
foreach ($this->modules as $module) {
|
||||
if (stripos($file['name'], $module) === 0) {
|
||||
$data[] = $file;
|
||||
}
|
||||
list($this->rules, $this->ignore, $data) = [$rules, $ignore, []];
|
||||
$result = json_decode(HttpExtend::post("{$this->uri}?s=/admin/api.update/tree", [
|
||||
'rules' => serialize($this->rules), 'ignore' => serialize($this->ignore),
|
||||
]), true);
|
||||
if (!empty($result['code'])) {
|
||||
$new = $this->buildFileList($result['data']['rules'], $result['data']['ignore']);
|
||||
foreach ($this->grenerateDifferenceContrast($result['data']['list'], $new['list']) as $file) {
|
||||
if (in_array($file['type'], ['add', 'del', 'mod'])) foreach ($this->rules as $rule) {
|
||||
if (stripos($file['name'], $rule) === 0) $data[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,22 +203,22 @@ class PlugsExtend
|
||||
|
||||
/**
|
||||
* 获取文件信息列表
|
||||
* @param array $paths 需要扫描的目录
|
||||
* @param array $ignores 忽略扫描的文件
|
||||
* @param array $maps 扫描结果列表
|
||||
* @param array $rules 文件规则
|
||||
* @param array $ignore 忽略规则
|
||||
* @param array $data 扫描结果列表
|
||||
* @return array
|
||||
*/
|
||||
public function buildFileList(array $paths, array $ignores = [], array $data = [])
|
||||
public function buildFileList(array $rules, array $ignore = [], array $data = [])
|
||||
{
|
||||
// 扫描规则文件
|
||||
foreach ($paths as $key => $path) {
|
||||
$data = array_merge($data, $this->scanFileList(strtr("{$this->path}{$path}", '\\', '/')));
|
||||
foreach ($rules as $key => $rule) {
|
||||
$data = array_merge($data, $this->scanFileList(strtr("{$this->path}{$rule}", '\\', '/')));
|
||||
}
|
||||
// 清除忽略文件
|
||||
foreach ($data as $key => $map) foreach ($ignores as $ingore) {
|
||||
foreach ($data as $key => $map) foreach ($ignore as $ingore) {
|
||||
if (stripos($map['name'], $ingore) === 0) unset($data[$key]);
|
||||
}
|
||||
return ['paths' => $paths, 'ignores' => $ignores, 'list' => $data];
|
||||
return ['rules' => $rules, 'ignore' => $ignore, 'list' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,23 +1,36 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | Library for ThinkAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | 官方网站: http://demo.thinkadmin.top
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 ( https://mit-license.org )
|
||||
// +----------------------------------------------------------------------
|
||||
// | gitee 仓库地址 :https://gitee.com/zoujingli/ThinkLibrary
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\admin\plugs;
|
||||
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
/**
|
||||
* Class AdminPlugs
|
||||
* @package think\admin\plugs
|
||||
*/
|
||||
class AdminPlugs extends Plugs
|
||||
{
|
||||
/**
|
||||
* 文件规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rules = ['think', 'app/admin'];
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->modules = ['application/admin/', 'think'];
|
||||
$this->rules = ['application/admin/', 'think'];
|
||||
$this->setName('xplugs:admin')->setDescription('[同步]覆盖本地Admin模块代码');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->modules[] = 'admin';
|
||||
parent::execute($input, $output);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,18 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | Library for ThinkAdmin
|
||||
// +----------------------------------------------------------------------
|
||||
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | 官方网站: http://demo.thinkadmin.top
|
||||
// +----------------------------------------------------------------------
|
||||
// | 开源协议 ( https://mit-license.org )
|
||||
// +----------------------------------------------------------------------
|
||||
// | gitee 仓库地址 :https://gitee.com/zoujingli/ThinkLibrary
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\admin\plugs;
|
||||
|
||||
use think\admin\extend\PlugsExtend;
|
||||
@ -8,46 +21,42 @@ use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
/**
|
||||
* 插件基础指令类
|
||||
* Class Plugs
|
||||
* @package think\admin\plugs
|
||||
*/
|
||||
class Plugs extends Command
|
||||
{
|
||||
/**
|
||||
* 指定更新模块
|
||||
* 查询规则
|
||||
* @var array
|
||||
*/
|
||||
protected $modules = [];
|
||||
protected $rules = [];
|
||||
|
||||
/**
|
||||
* 忽略规则
|
||||
* @var array
|
||||
*/
|
||||
protected $ignore = [];
|
||||
|
||||
/**
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$data = [];
|
||||
$extend = PlugsExtend::instance($this->app);
|
||||
$output->comment("=== 准备从代码仓库下载更新{$extend->getVersion()}版本文件 ===");
|
||||
foreach ($extend->grenerateDifference($this->modules) as $file) {
|
||||
if (in_array($file['type'], ['add', 'del', 'mod'])) {
|
||||
foreach ($this->modules as $module) {
|
||||
if (stripos($file['name'], $module) === 0) {
|
||||
$data[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dump($data);
|
||||
if (empty($data)) {
|
||||
$output->info('--- 本地文件与线上文件一致,无需更新文件');
|
||||
} else {
|
||||
foreach ($data as $file) {
|
||||
$this->fileSynchronization($file);
|
||||
}
|
||||
}
|
||||
$data = $extend->grenerateDifference($this->rules, $this->ignore);
|
||||
if (empty($data)) $output->info('--- 本地文件与线上文件一致,无需更新文件');
|
||||
else foreach ($data as $file) $extend->fileSynchronization($file);
|
||||
$output->comment("=== 从代码仓库下载{$extend->getVersion()}版本同步更新成功 ===");
|
||||
$this->install();
|
||||
}
|
||||
|
||||
private function install()
|
||||
protected function install()
|
||||
{
|
||||
// #todo 模块安装
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user