From 49ddead85e217f7c35297a0f77edf9c6fe122258 Mon Sep 17 00:00:00 2001 From: Anyon Date: Fri, 29 May 2020 11:35:38 +0800 Subject: [PATCH] ComposerUpdate --- app/admin/controller/api/Plugs.php | 9 +-- composer.lock | 8 +- vendor/composer/installed.json | 8 +- vendor/services.php | 2 +- .../think-library/src/command/Database.php | 12 +-- .../think-library/src/command/Queue.php | 2 +- .../think-library/src/helper/DeleteHelper.php | 2 +- .../think-library/src/service/NodeService.php | 28 +++++-- .../src/service/SystemService.php | 74 ++++++++++++------- 9 files changed, 88 insertions(+), 57 deletions(-) diff --git a/app/admin/controller/api/Plugs.php b/app/admin/controller/api/Plugs.php index 2bc12477b..cde5c34be 100644 --- a/app/admin/controller/api/Plugs.php +++ b/app/admin/controller/api/Plugs.php @@ -46,9 +46,7 @@ class Plugs extends Controller { try { if (AdminService::instance()->isSuper()) { - $dbname = $this->app->db->getConnection()->getConfig('database'); - $this->app->console->call("optimize:schema", ["--db={$dbname}"]); - $this->app->console->call('optimize:route'); + SystemService::instance()->pushRuntime(); $this->success('网站缓存加速成功!'); } else { $this->error('只有超级管理员才能操作!'); @@ -68,10 +66,7 @@ class Plugs extends Controller { try { if (AdminService::instance()->isSuper()) { - $data = SystemService::instance()->getRuntime(); - $path = strtr("{$this->app->getRootPath()}runtime/", '\\', '/'); - $this->app->console->call('clear', ["--path={$path}"]); - SystemService::instance()->setRuntime($data['app_map'], $data['app_run']); + SystemService::instance()->clearRuntime(); $this->success('清理网站缓存成功!'); } else { $this->error('只有超级管理员才能操作!'); diff --git a/composer.lock b/composer.lock index 8874c4b96..8ee43e143 100644 --- a/composer.lock +++ b/composer.lock @@ -915,12 +915,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "f654c159f0ecf03f34f8da433b98c40950696671" + "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/f654c159f0ecf03f34f8da433b98c40950696671", - "reference": "f654c159f0ecf03f34f8da433b98c40950696671", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3", + "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3", "shasum": "", "mirrors": [ { @@ -964,7 +964,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "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", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index ecf8f0a95..69e62a54c 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -941,12 +941,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "f654c159f0ecf03f34f8da433b98c40950696671" + "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/f654c159f0ecf03f34f8da433b98c40950696671", - "reference": "f654c159f0ecf03f34f8da433b98c40950696671", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3", + "reference": "be3dbd6eb7a91e62d3cca09d20b3b29e6cd76fe3", "shasum": "", "mirrors": [ { @@ -962,7 +962,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2020-05-21T09:42:50+00:00", + "time": "2020-05-29T03:30:56+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index 86cac1846..b77e9e39d 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/command/Database.php b/vendor/zoujingli/think-library/src/command/Database.php index 9ad4fb639..78c053dc8 100644 --- a/vendor/zoujingli/think-library/src/command/Database.php +++ b/vendor/zoujingli/think-library/src/command/Database.php @@ -41,10 +41,8 @@ class Database extends Command */ public function execute(Input $input, Output $output) { - $action = $input->getArgument('action'); - if (in_array($action, ['repair', 'optimize'])) { - return $this->{"_{$action}"}(); - } + $do = $input->getArgument('action'); + if (in_array($do, ['repair', 'optimize'])) return $this->{"_{$do}"}(); $this->output->error("Wrong operation, currently allow repair|optimize"); } @@ -58,8 +56,7 @@ class Database extends Command protected function _repair() { $this->setQueueProgress("正在获取需要修复的数据表", 0); - $tables = $this->getTables(); - [$total, $used] = [count($tables), 0]; + [$total, $used] = [count($tables = $this->getTables()), 0]; $this->setQueueProgress("总共需要修复 {$total} 张数据表", 0); foreach ($tables as $table) { $stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}"; @@ -78,8 +75,7 @@ class Database extends Command protected function _optimize() { $this->setQueueProgress("正在获取需要优化的数据表", 0); - $tables = $this->getTables(); - [$total, $used] = [count($tables), 0]; + [$total, $used] = [count($tables = $this->getTables()), 0]; $this->setQueueProgress("总共需要优化 {$total} 张数据表", 0); foreach ($tables as $table) { $stridx = str_pad(++$used, strlen("{$total}"), '0', STR_PAD_LEFT) . "/{$total}"; diff --git a/vendor/zoujingli/think-library/src/command/Queue.php b/vendor/zoujingli/think-library/src/command/Queue.php index be09968e7..9e6245b92 100644 --- a/vendor/zoujingli/think-library/src/command/Queue.php +++ b/vendor/zoujingli/think-library/src/command/Queue.php @@ -295,7 +295,7 @@ class Queue extends Command $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(); if (intval($code) !== 3) $code = 4; $this->updateQueue($code, $exception->getMessage()); diff --git a/vendor/zoujingli/think-library/src/helper/DeleteHelper.php b/vendor/zoujingli/think-library/src/helper/DeleteHelper.php index bf84ac6d9..d1d620b9f 100644 --- a/vendor/zoujingli/think-library/src/helper/DeleteHelper.php +++ b/vendor/zoujingli/think-library/src/helper/DeleteHelper.php @@ -55,7 +55,7 @@ class DeleteHelper extends Helper { $this->where = $where; $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); // 主键限制处理 if (!isset($this->where[$this->field]) && is_string($this->value)) { diff --git a/vendor/zoujingli/think-library/src/service/NodeService.php b/vendor/zoujingli/think-library/src/service/NodeService.php index c2d34e0a3..7cad7d218 100644 --- a/vendor/zoujingli/think-library/src/service/NodeService.php +++ b/vendor/zoujingli/think-library/src/service/NodeService.php @@ -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 * @return array * @throws \ReflectionException @@ -84,7 +100,7 @@ class NodeService extends Service $data = []; } $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)) { list(, $namespace, $appname, $classname) = $matches; $class = new \ReflectionClass(strtr("{$namespace}/{$appname}/controller/{$classname}", '/', '\\')); @@ -103,8 +119,8 @@ class NodeService extends Service /** * 解析硬节点属性 - * @param string $comment - * @param string $default + * @param string $comment 备注内容 + * @param string $default 默认标题 * @return array */ private function _parseComment($comment, $default = '') @@ -115,7 +131,7 @@ class NodeService extends Service $title = $default; } return [ - 'title' => $title ? $title : $default, + 'title' => $title ?: $default, 'isauth' => intval(preg_match('/@auth\s*true/i', $text)), 'ismenu' => intval(preg_match('/@menu\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) { 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) { $data[] = strtr($item, '\\', '/'); } diff --git a/vendor/zoujingli/think-library/src/service/SystemService.php b/vendor/zoujingli/think-library/src/service/SystemService.php index f961cd85b..6b3572ed5 100644 --- a/vendor/zoujingli/think-library/src/service/SystemService.php +++ b/vendor/zoujingli/think-library/src/service/SystemService.php @@ -224,6 +224,15 @@ class SystemService extends Service return true; } + /** + * 判断实时运行模式 + * @return boolean + */ + public function isDebug() + { + return $this->getRuntime('run') !== 'product'; + } + /** * 设置运行环境模式 * @param null|boolean $state @@ -248,16 +257,16 @@ class SystemService extends Service public function setRuntime($map = [], $run = null, $uri = []) { $data = $this->getRuntime(); - if (is_array($map) && count($map) > 0 && count($data['app_map']) > 0) { - foreach ($data['app_map'] as $kk => $vv) if (in_array($vv, $map)) unset($data['app_map'][$kk]); + if (is_array($map) && count($map) > 0 && count($data['map']) > 0) { + 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) { - foreach ($data['app_uri'] as $kk => $vv) if (in_array($vv, $uri)) unset($data['app_uri'][$kk]); + if (is_array($uri) && count($uri) > 0 && count($data['uri']) > 0) { + foreach ($data['uri'] as $kk => $vv) if (in_array($vv, $uri)) unset($data['uri'][$kk]); } $file = "{$this->app->getRootPath()}runtime/config.json"; - $data['app_run'] = is_null($run) ? $data['app_run'] : $run; - $data['app_map'] = is_null($map) ? [] : array_merge($data['app_map'], $map); - $data['app_uri'] = is_null($uri) ? [] : array_merge($data['app_uri'], $uri); + $data['run'] = is_null($run) ? $data['run'] : $run; + $data['map'] = is_null($map) ? [] : array_merge($data['map'], $map); + $data['uri'] = is_null($uri) ? [] : array_merge($data['uri'], $uri); file_put_contents($file, json_encode($data, JSON_UNESCAPED_UNICODE)); return $this->bindRuntime($data); } @@ -272,9 +281,9 @@ class SystemService extends Service $file = "{$this->app->getRootPath()}runtime/config.json"; $data = file_exists($file) ? json_decode(file_get_contents($file), true) : []; if (empty($data) || !is_array($data)) $data = []; - if (empty($data['app_map']) || !is_array($data['app_map'])) $data['app_map'] = []; - if (empty($data['app_uri']) || !is_array($data['app_uri'])) $data['app_uri'] = []; - if (empty($data['app_run']) || !is_string($data['app_run'])) $data['app_run'] = 'developer'; + if (empty($data['map']) || !is_array($data['map'])) $data['map'] = []; + if (empty($data['uri']) || !is_array($data['uri'])) $data['uri'] = []; + if (empty($data['run']) || !is_string($data['run'])) $data['run'] = 'developer'; return is_null($key) ? $data : ($data[$key] ?? null); } @@ -286,33 +295,48 @@ class SystemService extends Service public function bindRuntime($data = []) { if (empty($data)) $data = $this->getRuntime(); - // 动态绑定应用 - if (!empty($data['app_map'])) { + // 动态设置应用绑定 + if (!empty($data['map'])) { $maps = $this->app->config->get('app.app_map', []); - if (is_array($maps) && count($maps) > 0 && count($data['app_map']) > 0) { - foreach ($maps as $kk => $vv) if (in_array($vv, $data['app_map'])) unset($maps[$kk]); + if (is_array($maps) && count($maps) > 0 && count($data['map']) > 0) { + 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', []); - if (is_array($uris) && count($uris) > 0 && count($data['app_uri']) > 0) { - foreach ($uris as $kk => $vv) if (in_array($vv, $data['app_uri'])) unset($uris[$kk]); + if (is_array($uris) && count($uris) > 0 && count($data['uri']) > 0) { + 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']); } /**