From c59ca0b3ca792e5ab0d1816452d55f277763be65 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 22 Jun 2020 17:44:03 +0800 Subject: [PATCH] ComposerUpdate --- .gitignore | 2 +- composer.lock | 8 +-- vendor/composer/installed.json | 8 +-- vendor/services.php | 2 +- .../zoujingli/think-library/src/Command.php | 64 ++++++++++--------- .../zoujingli/think-library/src/Library.php | 2 +- .../think-library/src/command/Queue.php | 18 +++--- .../think-library/src/helper/DeleteHelper.php | 15 ++--- .../src/service/ModuleService.php | 17 +++-- .../think-library/src/service/OpenService.php | 2 +- 10 files changed, 72 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index cadcf5453..39d38c994 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ /runtime /safefile /nbproject -/public/upload /composer.lock +/public/upload diff --git a/composer.lock b/composer.lock index f2a6eb5ad..d4f597f3b 100644 --- a/composer.lock +++ b/composer.lock @@ -929,12 +929,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "8626798197fcdef636619e59b7151ca9f2952f63" + "reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/8626798197fcdef636619e59b7151ca9f2952f63", - "reference": "8626798197fcdef636619e59b7151ca9f2952f63", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/2fe569700bd8d7e2a24054f3592c5b06171c617c", + "reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c", "shasum": "", "mirrors": [ { @@ -978,7 +978,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "homepage": "http://framework.thinkadmin.top", - "time": "2020-06-20T09:56:03+00:00" + "time": "2020-06-22T09:29:56+00:00" }, { "name": "zoujingli/wechat-developer", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index d08f6a315..c5a59ff4b 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -955,12 +955,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "8626798197fcdef636619e59b7151ca9f2952f63" + "reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/8626798197fcdef636619e59b7151ca9f2952f63", - "reference": "8626798197fcdef636619e59b7151ca9f2952f63", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/2fe569700bd8d7e2a24054f3592c5b06171c617c", + "reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c", "shasum": "", "mirrors": [ { @@ -976,7 +976,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2020-06-20T09:56:03+00:00", + "time": "2020-06-22T09:29:56+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index a94ee93a6..e2bb9b78d 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.php b/vendor/zoujingli/think-library/src/Command.php index e38b6e5f9..f352f60aa 100644 --- a/vendor/zoujingli/think-library/src/Command.php +++ b/vendor/zoujingli/think-library/src/Command.php @@ -45,26 +45,15 @@ class Command extends ThinkCommand * @param Input $input * @param Output $output * @return $this - */ - protected function initialize(Input $input, Output $output) - { - $this->queue = QueueService::instance(); - $this->process = ProcessService::instance(); - return $this; - } - - /** - * 设置当前任务进度 - * @param null|string $message 进度消息 - * @param null|integer $progress 进度数值 - * @return Command * @throws Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - protected function setQueueProgress($message = null, $progress = null) + protected function initialize(Input $input, Output $output) { + $this->queue = QueueService::instance(); + $this->process = ProcessService::instance(); if (defined('WorkQueueCode')) { if (!$this->queue instanceof QueueService) { $this->queue = QueueService::instance(); @@ -72,6 +61,19 @@ class Command extends ThinkCommand if ($this->queue->code !== WorkQueueCode) { $this->queue->initialize(WorkQueueCode); } + } + return $this; + } + + /** + * 设置进度消息并继续执行 + * @param null|string $message 进度消息 + * @param null|integer $progress 进度数值 + * @return Command + */ + protected function setQueueProgress($message = null, $progress = null) + { + if (defined('WorkQueueCode')) { $this->queue->progress(2, $message, $progress); } elseif (is_string($message)) { $this->output->writeln($message); @@ -80,23 +82,7 @@ class Command extends ThinkCommand } /** - * 设置成功的消息 - * @param string $message 消息内容 - * @return Command - * @throws Exception - */ - protected function setQueueSuccess($message) - { - if (defined('WorkQueueCode')) { - throw new Exception($message, 3, WorkQueueCode); - } elseif (is_string($message)) { - $this->output->writeln($message); - } - return $this; - } - - /** - * 设置失败的消息 + * 设置失败消息并结束进程 * @param string $message 消息内容 * @return Command * @throws Exception @@ -111,4 +97,20 @@ class Command extends ThinkCommand return $this; } + /** + * 设置成功消息并结束进程 + * @param string $message 消息内容 + * @return Command + * @throws Exception + */ + protected function setQueueSuccess($message) + { + if (defined('WorkQueueCode')) { + throw new Exception($message, 3, WorkQueueCode); + } elseif (is_string($message)) { + $this->output->writeln($message); + } + return $this; + } + } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/Library.php b/vendor/zoujingli/think-library/src/Library.php index 03ec12c1a..9d5bd5d08 100644 --- a/vendor/zoujingli/think-library/src/Library.php +++ b/vendor/zoujingli/think-library/src/Library.php @@ -87,7 +87,7 @@ class Library extends Service }, 'route'); } // 动态加入应用函数 - $sysRule = "{$this->app->getAppPath()}*/sys.php"; + $sysRule = "{$this->app->getBasePath()}*/sys.php"; foreach (glob($sysRule) as $file) includeFile($file); } } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/command/Queue.php b/vendor/zoujingli/think-library/src/command/Queue.php index 11d31d117..46777effd 100644 --- a/vendor/zoujingli/think-library/src/command/Queue.php +++ b/vendor/zoujingli/think-library/src/command/Queue.php @@ -98,11 +98,11 @@ class Queue extends Command if ($this->process->iswin()) { $this->process->exec("start http://{$host}:{$port}"); } - $this->output->writeln("WebServer process already exist for pid {$result['0']['pid']}"); + $this->output->writeln("WebServer process already exist for pid {$result[0]['pid']}"); } else { [$this->process->create($command), usleep(2000)]; if (count($result = $this->process->query($command)) > 0) { - $this->output->writeln("WebServer process started successfully for pid {$result['0']['pid']}"); + $this->output->writeln("WebServer process started successfully for pid {$result[0]['pid']}"); if ($this->process->iswin()) { $this->process->exec("start http://{$host}:{$port}"); } @@ -192,7 +192,7 @@ class Queue extends Command $this->app->db->name($this->table)->whereOr([$map1, $map2])->chunk(100, function (Collection $result) use ($total, &$loops, &$timeout) { foreach ($result->toArray() as $item) { $item['loops_time'] > 0 ? $loops++ : $timeout++; - $prefix = str_pad($timeout + $loops, strlen("{$total}"), '0', STR_PAD_LEFT); + $prefix = str_pad($timeout + $loops, strlen("{$total}"), 0, STR_PAD_LEFT); if ($item['loops_time'] > 0) { $this->setQueueProgress("[{$prefix}/{$total}] 正在重置任务 {$item['code']} 为运行", ($timeout + $loops) * 100 / $total); [$status, $message] = [1, intval($item['status']) === 4 ? '任务执行失败,已自动重置任务!' : '任务执行超时,已自动重置任务!']; @@ -233,7 +233,7 @@ class Queue extends Command $this->output->writeln("\tYou can exit with `CTRL-C`"); $this->output->writeln('============== LISTENING =============='); while (true) { - $where = [['status', '=', '1'], ['exec_time', '<=', time()]]; + list($last, $where) = [microtime(true), [['status', '=', 1], ['exec_time', '<=', time()]]]; $this->app->db->name($this->table)->where($where)->order('exec_time asc')->chunk(100, function (Collection $result) { foreach ($result->toArray() as $vo) try { $command = $this->process->think("xadmin:queue dorun {$vo['code']} -"); @@ -245,12 +245,14 @@ class Queue extends Command } } catch (\Exception $exception) { $this->app->db->name($this->table)->where(['code' => $vo['code']])->update([ - 'status' => '4', 'outer_time' => time(), 'exec_desc' => $exception->getMessage(), + 'status' => 4, 'outer_time' => time(), 'exec_desc' => $exception->getMessage(), ]); $this->output->error("Execution failed -> [{$vo['code']}] {$vo['title']},{$exception->getMessage()}"); } }); - usleep(500000); + if (microtime(true) - $last < 0.5000) { + usleep(500000); + } } } @@ -268,12 +270,12 @@ class Queue extends Command $this->queue->initialize($this->code); if (empty($this->queue->record) || intval($this->queue->record['status']) !== 1) { // 这里不做任何处理(该任务可能在其它地方已经在执行) - $this->output->warning($message = "The or status of task {$this->code} is abnormal"); + $this->output->warning("The or status of task {$this->code} is abnormal"); } else { // 锁定任务状态,防止任务再次被执行 $this->app->db->name($this->table)->strict(false)->where(['code' => $this->code])->update([ 'enter_time' => microtime(true), 'attempts' => $this->app->db->raw('attempts+1'), - 'outer_time' => '0', 'exec_pid' => getmypid(), 'exec_desc' => '', 'status' => '2', + 'outer_time' => 0, 'exec_pid' => getmypid(), 'exec_desc' => '', 'status' => 2, ]); $this->queue->progress(2, '>>> 任务处理开始 <<<', 0); // 设置进程标题 diff --git a/vendor/zoujingli/think-library/src/helper/DeleteHelper.php b/vendor/zoujingli/think-library/src/helper/DeleteHelper.php index ade12a0eb..1479cf564 100644 --- a/vendor/zoujingli/think-library/src/helper/DeleteHelper.php +++ b/vendor/zoujingli/think-library/src/helper/DeleteHelper.php @@ -29,7 +29,7 @@ class DeleteHelper extends Helper * 表单额外更新条件 * @var array */ - protected $map; + protected $where; /** * 数据对象主键名称 @@ -53,16 +53,16 @@ class DeleteHelper extends Helper */ public function init($dbQuery, $field = '', $where = []) { - $this->map = $where; + $this->where = $where; $this->query = $this->buildQuery($dbQuery); $this->field = $field ?: $this->query->getPk(); $this->value = $this->app->request->post($this->field, null); // 主键限制处理 - if (!isset($this->map[$this->field]) && is_string($this->value)) { + if (!isset($this->where[$this->field]) && is_string($this->value)) { $this->query->whereIn($this->field, explode(',', $this->value)); } // 前置回调处理 - if (false === $this->controller->callback('_delete_filter', $this->query, $this->map)) { + if (false === $this->controller->callback('_delete_filter', $this->query, $this->where)) { return null; } // 执行删除操作 @@ -72,11 +72,8 @@ class DeleteHelper extends Helper if (in_array('deleted', $fields)) $data['deleted'] = 1; if (in_array('is_deleted', $fields)) $data['is_deleted'] = 1; } - if (empty($data)) { - $result = $this->query->where($this->map)->update($data); - } else { - $result = $this->query->where($this->map)->delete(); - } + empty($this->where) or $this->query->where($this->where); + $result = empty($data) ? $this->query->delete() : $this->query->update($data); // 结果回调处理 if (false === $this->controller->callback('_delete_result', $result)) { return $result; diff --git a/vendor/zoujingli/think-library/src/service/ModuleService.php b/vendor/zoujingli/think-library/src/service/ModuleService.php index 94967a976..0a70c8bd1 100644 --- a/vendor/zoujingli/think-library/src/service/ModuleService.php +++ b/vendor/zoujingli/think-library/src/service/ModuleService.php @@ -32,7 +32,7 @@ class ModuleService extends Service * @param ZipArchive $file 安装包 * @return array */ - public function install($name, ZipArchive $file) + public function install(string $name, ZipArchive $file): array { // 安装包检查 list($state, $message) = $this->checkInstall($name, $file); @@ -47,12 +47,17 @@ class ModuleService extends Service /** * 移除应用模块 - * @param string $name + * @param string $name 模块名称 + * @return array */ - public function remove($name) + public function remove(string $name): array { $directory = $this->app->getBasePath() . $name; - $this->forceRemove($directory); + if (file_exists($directory) && is_dir($directory)) { + return [0, '提交移除应用模块指令成功']; + } else { + return [1, '待删除的应用模块不存在']; + } } /** @@ -61,7 +66,7 @@ class ModuleService extends Service * @param ZipArchive $file 安装包 * @return array */ - private function checkInstall($name, ZipArchive $file) + private function checkInstall(string $name, ZipArchive $file): array { $directory = "{$file->filename}.files"; file_exists($directory) || mkdir($directory, 0755, true); @@ -82,7 +87,7 @@ class ModuleService extends Service * 强制删除指定的目录 * @param string $directory */ - private function forceRemove($directory) + private function forceRemove(string $directory) { if (file_exists($directory) && is_dir($directory) && $handle = opendir($directory)) { while (false !== ($item = readdir($handle))) if (!in_array($item, ['.', '..'])) { diff --git a/vendor/zoujingli/think-library/src/service/OpenService.php b/vendor/zoujingli/think-library/src/service/OpenService.php index ec8e18b85..4ca3e4980 100644 --- a/vendor/zoujingli/think-library/src/service/OpenService.php +++ b/vendor/zoujingli/think-library/src/service/OpenService.php @@ -62,7 +62,7 @@ class OpenService extends Service * @return array * @throws \think\admin\Exception */ - public function doRequest(string $uri, array $data = []) + public function doRequest(string $uri, array $data = []): array { [$time, $nostr, $json] = [time(), uniqid(), json_encode($data)]; $sign = md5($this->appid . '#' . $json . '#' . $time . '#' . $this->appkey . '#' . $nostr);