ComposerUpdate

This commit is contained in:
Anyon 2020-08-03 17:36:44 +08:00
parent fc6b18b94f
commit 794a2777a7
6 changed files with 70 additions and 57 deletions

8
composer.lock generated
View File

@ -879,12 +879,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "3241ffefd6697d1bedcc9721e3275a24055bb77b" "reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/3241ffefd6697d1bedcc9721e3275a24055bb77b", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0cf2b63422aff3efe9ad200b21af1ef88339726a",
"reference": "3241ffefd6697d1bedcc9721e3275a24055bb77b", "reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -928,7 +928,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://thinkadmin.top", "homepage": "http://thinkadmin.top",
"time": "2020-08-03T09:00:42+00:00" "time": "2020-08-03T09:30:04+00:00"
}, },
{ {
"name": "zoujingli/wechat-developer", "name": "zoujingli/wechat-developer",

View File

@ -903,12 +903,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "3241ffefd6697d1bedcc9721e3275a24055bb77b" "reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/3241ffefd6697d1bedcc9721e3275a24055bb77b", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/0cf2b63422aff3efe9ad200b21af1ef88339726a",
"reference": "3241ffefd6697d1bedcc9721e3275a24055bb77b", "reference": "0cf2b63422aff3efe9ad200b21af1ef88339726a",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -924,7 +924,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2020-08-03T09:00:42+00:00", "time": "2020-08-03T09:30:04+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"think": { "think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2020-08-03 17:05:42 // This file is automatically generated at:2020-08-03 17:36:09
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\admin\\Library', 0 => 'think\\admin\\Library',

View File

@ -117,7 +117,7 @@ class Install extends Command
$data = InstallService::instance()->grenerateDifference($this->rules, $this->ignore); $data = InstallService::instance()->grenerateDifference($this->rules, $this->ignore);
if (empty($data)) $this->output->writeln('No need to update the file if the file comparison is consistent'); if (empty($data)) $this->output->writeln('No need to update the file if the file comparison is consistent');
else foreach ($data as $file) { else foreach ($data as $file) {
list($state, $mode, $name) = InstallService::instance()->fileSynchronization($file); [$state, $mode, $name] = InstallService::instance()->fileSynchronization($file);
if ($state) { if ($state) {
if ($mode === 'add') $this->output->writeln("--- {$name} add successfully"); if ($mode === 'add') $this->output->writeln("--- {$name} add successfully");
if ($mode === 'mod') $this->output->writeln("--- {$name} update successfully"); if ($mode === 'mod') $this->output->writeln("--- {$name} update successfully");

View File

@ -25,26 +25,26 @@ use think\admin\Service;
*/ */
class InstallService extends Service class InstallService extends Service
{ {
/**
* 代码地址
* @var string
*/
protected $uri;
/** /**
* 项目根目录 * 项目根目录
* @var string * @var string
*/ */
protected $path; protected $root;
/** /**
* 当前版本号 * 线上服务器地址
* @var string
*/
protected $server;
/**
* 当前大版本号
* @var string * @var string
*/ */
protected $version; protected $version;
/** /**
* 文件规则 * 更新规则
* @var array * @var array
*/ */
protected $rules = []; protected $rules = [];
@ -57,18 +57,24 @@ class InstallService extends Service
/** /**
* 初始化服务 * 初始化服务
* @return $this
*/ */
protected function initialize() protected function initialize()
{ {
// 应用根目录
$this->root = strtr($this->app->getRootPath(), '\\', '/');
// 应用框架版本 // 应用框架版本
$this->version = $this->app->config->get('app.thinkadmin_ver'); $this->version = $this->app->config->get('app.thinkadmin_ver') ?: 'v4';
if (empty($this->version)) $this->version = 'v4';
// 线上应用代码 // 线上应用代码
$this->uri = "https://{$this->version}.thinkadmin.top"; $this->server = "https://{$this->version}.thinkadmin.top";
// 当前应用根目录 }
$this->path = strtr($this->app->getRootPath(), '\\', '/');
return $this; /**
* 获取线上接口
* @return string
*/
public function getServer()
{
return $this->server;
} }
/** /**
@ -94,7 +100,7 @@ class InstallService extends Service
return [false, $file['type'], $file['name']]; return [false, $file['type'], $file['name']];
} }
} elseif (in_array($file['type'], ['del'])) { } elseif (in_array($file['type'], ['del'])) {
$real = $this->path . $file['name']; $real = $this->root . $file['name'];
if (is_file($real) && unlink($real)) { if (is_file($real) && unlink($real)) {
$this->removeEmptyDirectory(dirname($real)); $this->removeEmptyDirectory(dirname($real));
return [true, $file['type'], $file['name']]; return [true, $file['type'], $file['name']];
@ -111,9 +117,9 @@ class InstallService extends Service
*/ */
private function downloadFile($encode) private function downloadFile($encode)
{ {
$result = json_decode(HttpExtend::get("{$this->uri}?s=admin/api.update/get&encode={$encode}"), true); $result = json_decode(HttpExtend::get("{$this->server}?s=admin/api.update/get&encode={$encode}"), true);
if (empty($result['code'])) return false; if (empty($result['code'])) return false;
$filename = $this->path . decode($encode); $filename = $this->root . decode($encode);
file_exists(dirname($filename)) || mkdir(dirname($filename), 0755, true); file_exists(dirname($filename)) || mkdir(dirname($filename), 0755, true);
return file_put_contents($filename, base64_decode($result['data']['content'])); return file_put_contents($filename, base64_decode($result['data']['content']));
} }
@ -137,8 +143,8 @@ class InstallService extends Service
*/ */
public function grenerateDifference($rules = [], $ignore = []) public function grenerateDifference($rules = [], $ignore = [])
{ {
list($this->rules, $this->ignore, $data) = [$rules, $ignore, []]; [$this->rules, $this->ignore, $data] = [$rules, $ignore, []];
$result = json_decode(HttpExtend::post("{$this->uri}?s=/admin/api.update/node", [ $result = json_decode(HttpExtend::post("{$this->server}?s=/admin/api.update/node", [
'rules' => json_encode($this->rules), 'ignore' => json_encode($this->ignore), 'rules' => json_encode($this->rules), 'ignore' => json_encode($this->ignore),
]), true); ]), true);
if (!empty($result['code'])) { if (!empty($result['code'])) {
@ -161,7 +167,7 @@ class InstallService extends Service
private function grenerateDifferenceContrast(array $serve = [], array $local = []) private function grenerateDifferenceContrast(array $serve = [], array $local = [])
{ {
// 数据扁平化 // 数据扁平化
list($_serve, $_local, $_new) = [[], [], []]; [$_serve, $_local, $_new] = [[], [], []];
foreach ($serve as $t) $_serve[$t['name']] = $t; foreach ($serve as $t) $_serve[$t['name']] = $t;
foreach ($local as $t) $_local[$t['name']] = $t; foreach ($local as $t) $_local[$t['name']] = $t;
unset($serve, $local); unset($serve, $local);
@ -190,7 +196,7 @@ class InstallService extends Service
// 扫描规则文件 // 扫描规则文件
foreach ($rules as $key => $rule) { foreach ($rules as $key => $rule) {
$name = strtr(trim($rule, '\\/'), '\\', '/'); $name = strtr(trim($rule, '\\/'), '\\', '/');
$data = array_merge($data, $this->scanList("{$this->path}{$name}")); $data = array_merge($data, $this->scanList("{$this->root}{$name}"));
} }
// 清除忽略文件 // 清除忽略文件
foreach ($data as $key => $item) foreach ($ignore as $ingore) { foreach ($data as $key => $item) foreach ($ignore as $ingore) {
@ -227,7 +233,7 @@ class InstallService extends Service
private function getInfo($filename) private function getInfo($filename)
{ {
return [ return [
'name' => str_replace($this->path, '', $filename), 'name' => str_replace($this->root, '', $filename),
'hash' => md5(preg_replace('/\s+/', '', file_get_contents($filename))), 'hash' => md5(preg_replace('/\s+/', '', file_get_contents($filename))),
]; ];
} }

View File

@ -29,7 +29,7 @@ class ModuleService extends Service
* 获取模块变更 * 获取模块变更
* @return array * @return array
*/ */
public function change() public function change(): array
{ {
[$online, $locals] = [$this->online(), $this->getModules()]; [$online, $locals] = [$this->online(), $this->getModules()];
foreach ($online as &$item) if (isset($locals[$item['name']])) { foreach ($online as &$item) if (isset($locals[$item['name']])) {
@ -50,28 +50,31 @@ class ModuleService extends Service
/** /**
* 安装或更新模块 * 安装或更新模块
* @param string $name * @param string $name 模块名称
* @return array * @return array
*/ */
public function install($name): array public function install($name): array
{ {
$install = InstallService::instance(); $this->app->cache->set('module-online-data', []);
$data = $install->grenerateDifference(["app/{$name}"]); $data = InstallService::instance()->grenerateDifference(["app/{$name}"]);
if (empty($data)) return [0, '没有需要安装的文件', []]; if (empty($data)) {
$lines = []; return [0, '没有需要安装的文件', []];
foreach ($data as $file) { } else {
[$state, $mode, $name] = $install->fileSynchronization($file); $lines = [];
if ($state) { foreach ($data as $file) {
if ($mode === 'add') $lines[] = "add {$name} successed"; [$state, $mode, $name] = InstallService::instance()->fileSynchronization($file);
if ($mode === 'mod') $lines[] = "modify {$name} successed"; if ($state) {
if ($mode === 'del') $lines[] = "delete {$name} successed"; if ($mode === 'add') $lines[] = "add {$name} successed";
} else { if ($mode === 'mod') $lines[] = "modify {$name} successed";
if ($mode === 'add') $lines[] = "add {$name} failed"; if ($mode === 'del') $lines[] = "deleted {$name} successed";
if ($mode === 'mod') $lines[] = "modify {$name} failed"; } else {
if ($mode === 'del') $lines[] = "delete {$name} failed"; if ($mode === 'add') $lines[] = "add {$name} failed";
if ($mode === 'mod') $lines[] = "modify {$name} failed";
if ($mode === 'del') $lines[] = "deleted {$name} failed";
}
} }
return [1, '模块安装成功', $lines];
} }
return [1, '模块安装成功', $lines];
} }
/** /**
@ -82,11 +85,11 @@ class ModuleService extends Service
{ {
$data = $this->app->cache->get('module-online-data', []); $data = $this->app->cache->get('module-online-data', []);
if (!empty($data)) return $data; if (!empty($data)) return $data;
$result = json_decode(HttpExtend::get('https://v6.thinkadmin.top/admin/api.update/version'), true); $server = InstallService::instance()->getServer();
$result = json_decode(HttpExtend::get("{$server}/admin/api.update/version"), true);
if (isset($result['code']) && $result['code'] > 0 && isset($result['data']) && is_array($result['data'])) { if (isset($result['code']) && $result['code'] > 0 && isset($result['data']) && is_array($result['data'])) {
foreach ($result['data'] as $item) $data[$item['name']] = $item; $this->app->cache->set('module-online-data', $result['data'], 1800);
$this->app->cache->set('module-online-data', $data, 1800); return $result['data'];
return $data;
} else { } else {
return []; return [];
} }
@ -100,7 +103,11 @@ class ModuleService extends Service
{ {
$data = []; $data = [];
foreach (NodeService::instance()->getModules() as $name) { foreach (NodeService::instance()->getModules() as $name) {
if (is_array($ver = $this->__getVersion($name))) $data[$name] = $ver; if (is_array($ver = $this->getModuleVersion($name))) {
if (preg_match('|^\d{4}\.\d{2}\.\d{2}\.\d{2}$|', $ver['version'])) {
$data[$name] = $ver;
}
}
} }
return $data; return $data;
} }
@ -110,7 +117,7 @@ class ModuleService extends Service
* @param string $name 模块名称 * @param string $name 模块名称
* @return bool|array|null * @return bool|array|null
*/ */
private function __getVersion($name) private function getModuleVersion($name)
{ {
$file = $this->app->getBasePath() . $name . DIRECTORY_SEPARATOR . 'ver.php'; $file = $this->app->getBasePath() . $name . DIRECTORY_SEPARATOR . 'ver.php';
if (file_exists($file) && is_file($file) && is_array($vars = @include $file)) { if (file_exists($file) && is_file($file) && is_array($vars = @include $file)) {