From e7be978c5a664b5aa4738e7f5656357fdddbe34f Mon Sep 17 00:00:00 2001 From: Anyon Date: Fri, 1 Nov 2019 18:46:23 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E8=B0=83=E6=95=B4=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8C=87=E4=BB=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/api/Update.php | 11 ++-- composer.lock | 8 +-- vendor/autoload.php | 2 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_real.php | 14 ++--- vendor/composer/autoload_static.php | 9 +-- vendor/composer/installed.json | 8 +-- vendor/services.php | 2 +- .../think-library/src/ThinkLibrary.php | 2 +- .../think-library/src/extend/PlugsExtend.php | 57 +++++++++++-------- .../think-library/src/plugs/AdminPlugs.php | 35 ++++++++---- .../think-library/src/plugs/Plugs.php | 53 ++++++++++------- 12 files changed, 116 insertions(+), 86 deletions(-) diff --git a/app/admin/controller/api/Update.php b/app/admin/controller/api/Update.php index 3cde0b171..67e7756ca 100644 --- a/app/admin/controller/api/Update.php +++ b/app/admin/controller/api/Update.php @@ -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)); } /** diff --git a/composer.lock b/composer.lock index a581f7dab..341c498ed 100644 --- a/composer.lock +++ b/composer.lock @@ -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": [], diff --git a/vendor/autoload.php b/vendor/autoload.php index ba4d7d938..f9005ba94 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit66f83d66f674d4aec69a8b4e93085253::getLoader(); +return ComposerAutoloaderInit0b662654c649e6d1b22f688c84d1a1fb::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index d5d98652f..935306fc6 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -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', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index b41947cb1..25facc87b 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 03c19a595..22389b6ba 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index f5b883054..0b643c152 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -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": { diff --git a/vendor/services.php b/vendor/services.php index 44ce6dfbd..38d931d32 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/ThinkLibrary.php b/vendor/zoujingli/think-library/src/ThinkLibrary.php index 74f4d553d..68adcd255 100644 --- a/vendor/zoujingli/think-library/src/ThinkLibrary.php +++ b/vendor/zoujingli/think-library/src/ThinkLibrary.php @@ -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', ]); } diff --git a/vendor/zoujingli/think-library/src/extend/PlugsExtend.php b/vendor/zoujingli/think-library/src/extend/PlugsExtend.php index 42aa43bfc..d48fe9e46 100644 --- a/vendor/zoujingli/think-library/src/extend/PlugsExtend.php +++ b/vendor/zoujingli/think-library/src/extend/PlugsExtend.php @@ -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]; } /** diff --git a/vendor/zoujingli/think-library/src/plugs/AdminPlugs.php b/vendor/zoujingli/think-library/src/plugs/AdminPlugs.php index c1176cdb0..b1c0301e0 100644 --- a/vendor/zoujingli/think-library/src/plugs/AdminPlugs.php +++ b/vendor/zoujingli/think-library/src/plugs/AdminPlugs.php @@ -1,23 +1,36 @@ 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); - - } - } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/plugs/Plugs.php b/vendor/zoujingli/think-library/src/plugs/Plugs.php index b8c6fa1cc..061d8071f 100644 --- a/vendor/zoujingli/think-library/src/plugs/Plugs.php +++ b/vendor/zoujingli/think-library/src/plugs/Plugs.php @@ -1,5 +1,18 @@ 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 模块安装 + } } \ No newline at end of file