ComposerUpdate

This commit is contained in:
Anyon 2020-05-29 11:35:38 +08:00
parent 4b8d70d7b3
commit 49ddead85e
9 changed files with 88 additions and 57 deletions

View File

@ -46,9 +46,7 @@ class Plugs extends Controller
{ {
try { try {
if (AdminService::instance()->isSuper()) { if (AdminService::instance()->isSuper()) {
$dbname = $this->app->db->getConnection()->getConfig('database'); SystemService::instance()->pushRuntime();
$this->app->console->call("optimize:schema", ["--db={$dbname}"]);
$this->app->console->call('optimize:route');
$this->success('网站缓存加速成功!'); $this->success('网站缓存加速成功!');
} else { } else {
$this->error('只有超级管理员才能操作!'); $this->error('只有超级管理员才能操作!');
@ -68,10 +66,7 @@ class Plugs extends Controller
{ {
try { try {
if (AdminService::instance()->isSuper()) { if (AdminService::instance()->isSuper()) {
$data = SystemService::instance()->getRuntime(); SystemService::instance()->clearRuntime();
$path = strtr("{$this->app->getRootPath()}runtime/", '\\', '/');
$this->app->console->call('clear', ["--path={$path}"]);
SystemService::instance()->setRuntime($data['app_map'], $data['app_run']);
$this->success('清理网站缓存成功!'); $this->success('清理网站缓存成功!');
} else { } else {
$this->error('只有超级管理员才能操作!'); $this->error('只有超级管理员才能操作!');

8
composer.lock generated
View File

@ -915,12 +915,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "f654c159f0ecf03f34f8da433b98c40950696671" "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/f654c159f0ecf03f34f8da433b98c40950696671", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3",
"reference": "f654c159f0ecf03f34f8da433b98c40950696671", "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -964,7 +964,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top", "homepage": "http://framework.thinkadmin.top",
"time": "2020-05-21T09:42:50+00:00" "time": "2020-05-29T03:30:56+00:00"
}, },
{ {
"name": "zoujingli/wechat-developer", "name": "zoujingli/wechat-developer",

View File

@ -941,12 +941,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "f654c159f0ecf03f34f8da433b98c40950696671" "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/f654c159f0ecf03f34f8da433b98c40950696671", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3",
"reference": "f654c159f0ecf03f34f8da433b98c40950696671", "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -962,7 +962,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2020-05-21T09:42:50+00:00", "time": "2020-05-29T03:30:56+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-05-27 13:52:14 // This file is automatically generated at:2020-05-29 11:35:28
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',

View File

@ -41,10 +41,8 @@ class Database extends Command
*/ */
public function execute(Input $input, Output $output) public function execute(Input $input, Output $output)
{ {
$action = $input->getArgument('action'); $do = $input->getArgument('action');
if (in_array($action, ['repair', 'optimize'])) { if (in_array($do, ['repair', 'optimize'])) return $this->{"_{$do}"}();
return $this->{"_{$action}"}();
}
$this->output->error("Wrong operation, currently allow repair|optimize"); $this->output->error("Wrong operation, currently allow repair|optimize");
} }
@ -58,8 +56,7 @@ class Database extends Command
protected function _repair() protected function _repair()
{ {
$this->setQueueProgress("正在获取需要修复的数据表", 0); $this->setQueueProgress("正在获取需要修复的数据表", 0);
$tables = $this->getTables(); [$total, $used] = [count($tables = $this->getTables()), 0];
[$total, $used] = [count($tables), 0];
$this->setQueueProgress("总共需要修复 {$total} 张数据表", 0); $this->setQueueProgress("总共需要修复 {$total} 张数据表", 0);
foreach ($tables as $table) { foreach ($tables as $table) {
$stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}"; $stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}";
@ -78,8 +75,7 @@ class Database extends Command
protected function _optimize() protected function _optimize()
{ {
$this->setQueueProgress("正在获取需要优化的数据表", 0); $this->setQueueProgress("正在获取需要优化的数据表", 0);
$tables = $this->getTables(); [$total, $used] = [count($tables = $this->getTables()), 0];
[$total, $used] = [count($tables), 0];
$this->setQueueProgress("总共需要优化 {$total} 张数据表", 0); $this->setQueueProgress("总共需要优化 {$total} 张数据表", 0);
foreach ($tables as $table) { foreach ($tables as $table) {
$stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}"; $stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}";

View File

@ -295,7 +295,7 @@ class Queue extends Command
$this->updateQueue(3, $this->app->console->call(array_shift($attr), $attr)->fetch(), false); $this->updateQueue(3, $this->app->console->call(array_shift($attr), $attr)->fetch(), false);
} }
} }
} catch (\Exception|\Error $exception) { } catch (\Exception|\Error|\Throwable $exception) {
$code = $exception->getCode(); $code = $exception->getCode();
if (intval($code) !== 3) $code = 4; if (intval($code) !== 3) $code = 4;
$this->updateQueue($code, $exception->getMessage()); $this->updateQueue($code, $exception->getMessage());

View File

@ -55,7 +55,7 @@ class DeleteHelper extends Helper
{ {
$this->where = $where; $this->where = $where;
$this->query = $this->buildQuery($dbQuery); $this->query = $this->buildQuery($dbQuery);
$this->field = empty($field) ? $this->query->getPk() : $field; $this->field = $field ?: $this->query->getPk();
$this->value = $this->app->request->post($this->field, null); $this->value = $this->app->request->post($this->field, null);
// 主键限制处理 // 主键限制处理
if (!isset($this->where[$this->field]) && is_string($this->value)) { if (!isset($this->where[$this->field]) && is_string($this->value)) {

View File

@ -68,7 +68,23 @@ class NodeService extends Service
} }
/** /**
* 控制器方法扫描处理 * 获取应用列表
* @param array $data
* @return array
*/
public function getModules($data = [])
{
if ($handle = opendir($this->app->getBasePath())) {
while (false !== ($file = readdir($handle))) if ($file !== "." && $file !== "..") {
if (is_dir($this->app->getBasePath() . $file)) $data[] = $file;
}
closedir($handle);
}
return $data;
}
/**
* 获取所有控制器入口
* @param boolean $force * @param boolean $force
* @return array * @return array
* @throws \ReflectionException * @throws \ReflectionException
@ -84,7 +100,7 @@ class NodeService extends Service
$data = []; $data = [];
} }
$ignores = get_class_methods('\think\admin\Controller'); $ignores = get_class_methods('\think\admin\Controller');
foreach ($this->_scanDirectory(dirname($this->app->getAppPath())) as $file) { foreach ($this->_scanDirectory($this->app->getBasePath()) as $file) {
if (preg_match("|/(\w+)/(\w+)/controller/(.+)\.php$|i", $file, $matches)) { if (preg_match("|/(\w+)/(\w+)/controller/(.+)\.php$|i", $file, $matches)) {
list(, $namespace, $appname, $classname) = $matches; list(, $namespace, $appname, $classname) = $matches;
$class = new \ReflectionClass(strtr("{$namespace}/{$appname}/controller/{$classname}", '/', '\\')); $class = new \ReflectionClass(strtr("{$namespace}/{$appname}/controller/{$classname}", '/', '\\'));
@ -103,8 +119,8 @@ class NodeService extends Service
/** /**
* 解析硬节点属性 * 解析硬节点属性
* @param string $comment * @param string $comment 备注内容
* @param string $default * @param string $default 默认标题
* @return array * @return array
*/ */
private function _parseComment($comment, $default = '') private function _parseComment($comment, $default = '')
@ -115,7 +131,7 @@ class NodeService extends Service
$title = $default; $title = $default;
} }
return [ return [
'title' => $title ? $title : $default, 'title' => $title ?: $default,
'isauth' => intval(preg_match('/@auth\s*true/i', $text)), 'isauth' => intval(preg_match('/@auth\s*true/i', $text)),
'ismenu' => intval(preg_match('/@menu\s*true/i', $text)), 'ismenu' => intval(preg_match('/@menu\s*true/i', $text)),
'islogin' => intval(preg_match('/@login\s*true/i', $text)), 'islogin' => intval(preg_match('/@login\s*true/i', $text)),
@ -133,7 +149,7 @@ class NodeService extends Service
{ {
foreach (glob("{$path}*") as $item) { foreach (glob("{$path}*") as $item) {
if (is_dir($item)) { if (is_dir($item)) {
$data = array_merge($data, $this->_scanDirectory("{$item}/")); $data = array_merge($data, $this->_scanDirectory("{$item}" . DIRECTORY_SEPARATOR));
} elseif (is_file($item) && pathinfo($item, PATHINFO_EXTENSION) === $ext) { } elseif (is_file($item) && pathinfo($item, PATHINFO_EXTENSION) === $ext) {
$data[] = strtr($item, '\\', '/'); $data[] = strtr($item, '\\', '/');
} }

View File

@ -224,6 +224,15 @@ class SystemService extends Service
return true; return true;
} }
/**
* 判断实时运行模式
* @return boolean
*/
public function isDebug()
{
return $this->getRuntime('run') !== 'product';
}
/** /**
* 设置运行环境模式 * 设置运行环境模式
* @param null|boolean $state * @param null|boolean $state
@ -248,16 +257,16 @@ class SystemService extends Service
public function setRuntime($map = [], $run = null, $uri = []) public function setRuntime($map = [], $run = null, $uri = [])
{ {
$data = $this->getRuntime(); $data = $this->getRuntime();
if (is_array($map) && count($map) > 0 && count($data['app_map']) > 0) { if (is_array($map) && count($map) > 0 && count($data['map']) > 0) {
foreach ($data['app_map'] as $kk => $vv) if (in_array($vv, $map)) unset($data['app_map'][$kk]); foreach ($data['map'] as $kk => $vv) if (in_array($vv, $map)) unset($data['map'][$kk]);
} }
if (is_array($uri) && count($uri) > 0 && count($data['app_uri']) > 0) { if (is_array($uri) && count($uri) > 0 && count($data['uri']) > 0) {
foreach ($data['app_uri'] as $kk => $vv) if (in_array($vv, $uri)) unset($data['app_uri'][$kk]); foreach ($data['uri'] as $kk => $vv) if (in_array($vv, $uri)) unset($data['uri'][$kk]);
} }
$file = "{$this->app->getRootPath()}runtime/config.json"; $file = "{$this->app->getRootPath()}runtime/config.json";
$data['app_run'] = is_null($run) ? $data['app_run'] : $run; $data['run'] = is_null($run) ? $data['run'] : $run;
$data['app_map'] = is_null($map) ? [] : array_merge($data['app_map'], $map); $data['map'] = is_null($map) ? [] : array_merge($data['map'], $map);
$data['app_uri'] = is_null($uri) ? [] : array_merge($data['app_uri'], $uri); $data['uri'] = is_null($uri) ? [] : array_merge($data['uri'], $uri);
file_put_contents($file, json_encode($data, JSON_UNESCAPED_UNICODE)); file_put_contents($file, json_encode($data, JSON_UNESCAPED_UNICODE));
return $this->bindRuntime($data); return $this->bindRuntime($data);
} }
@ -272,9 +281,9 @@ class SystemService extends Service
$file = "{$this->app->getRootPath()}runtime/config.json"; $file = "{$this->app->getRootPath()}runtime/config.json";
$data = file_exists($file) ? json_decode(file_get_contents($file), true) : []; $data = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
if (empty($data) || !is_array($data)) $data = []; if (empty($data) || !is_array($data)) $data = [];
if (empty($data['app_map']) || !is_array($data['app_map'])) $data['app_map'] = []; if (empty($data['map']) || !is_array($data['map'])) $data['map'] = [];
if (empty($data['app_uri']) || !is_array($data['app_uri'])) $data['app_uri'] = []; if (empty($data['uri']) || !is_array($data['uri'])) $data['uri'] = [];
if (empty($data['app_run']) || !is_string($data['app_run'])) $data['app_run'] = 'developer'; if (empty($data['run']) || !is_string($data['run'])) $data['run'] = 'developer';
return is_null($key) ? $data : ($data[$key] ?? null); return is_null($key) ? $data : ($data[$key] ?? null);
} }
@ -286,33 +295,48 @@ class SystemService extends Service
public function bindRuntime($data = []) public function bindRuntime($data = [])
{ {
if (empty($data)) $data = $this->getRuntime(); if (empty($data)) $data = $this->getRuntime();
// 动态绑定应用 // 动态设置应用绑定
if (!empty($data['app_map'])) { if (!empty($data['map'])) {
$maps = $this->app->config->get('app.app_map', []); $maps = $this->app->config->get('app.app_map', []);
if (is_array($maps) && count($maps) > 0 && count($data['app_map']) > 0) { if (is_array($maps) && count($maps) > 0 && count($data['map']) > 0) {
foreach ($maps as $kk => $vv) if (in_array($vv, $data['app_map'])) unset($maps[$kk]); foreach ($maps as $kk => $vv) if (in_array($vv, $data['map'])) unset($maps[$kk]);
} }
$this->app->config->set(['app_map' => array_merge($maps, $data['app_map'])], 'app'); $this->app->config->set(['app_map' => array_merge($maps, $data['map'])], 'app');
} }
// 动态绑定域名 // 动态设置域名绑定
if (!empty($data['app_uri'])) { if (!empty($data['uri'])) {
$uris = $this->app->config->get('app.domain_bind', []); $uris = $this->app->config->get('app.domain_bind', []);
if (is_array($uris) && count($uris) > 0 && count($data['app_uri']) > 0) { if (is_array($uris) && count($uris) > 0 && count($data['uri']) > 0) {
foreach ($uris as $kk => $vv) if (in_array($vv, $data['app_uri'])) unset($uris[$kk]); foreach ($uris as $kk => $vv) if (in_array($vv, $data['uri'])) unset($uris[$kk]);
} }
$this->app->config->set(['domain_bind' => array_merge($uris, $data['app_uri'])], 'app'); $this->app->config->set(['domain_bind' => array_merge($uris, $data['uri'])], 'app');
} }
// 动态设置运行模式 // 动态设置运行模式
return $this->app->debug($data['app_run'] !== 'product')->isDebug(); return $this->app->debug($data['run'] !== 'product')->isDebug();
} }
/** /**
* 判断实时运行模式 * 压缩发布项目
* @return boolean
*/ */
public function isDebug() public function pushRuntime()
{ {
return $this->getRuntime('app_run') !== 'product'; $dbname = $this->app->db->getConnection()->getConfig('database');
$this->app->console->call("optimize:schema", ["--db={$dbname}"]);
foreach (NodeService::instance()->getModules() as $module) {
$path = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . $module;
file_exists($path) && is_dir($path) or mkdir($path, 0755, true);
$this->app->console->call("optimize:route {$module}");
}
}
/**
* 清理运行缓存
*/
public function clearRuntime()
{
$data = $this->getRuntime();
$this->app->console->call('clear');
$this->setRuntime($data['map'], $data['run']);
} }
/** /**