mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
ComposerUpdate
This commit is contained in:
parent
335c528999
commit
c59ca0b3ca
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,5 +5,5 @@
|
|||||||
/runtime
|
/runtime
|
||||||
/safefile
|
/safefile
|
||||||
/nbproject
|
/nbproject
|
||||||
/public/upload
|
|
||||||
/composer.lock
|
/composer.lock
|
||||||
|
/public/upload
|
||||||
|
8
composer.lock
generated
8
composer.lock
generated
@ -929,12 +929,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||||
"reference": "8626798197fcdef636619e59b7151ca9f2952f63"
|
"reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/8626798197fcdef636619e59b7151ca9f2952f63",
|
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/2fe569700bd8d7e2a24054f3592c5b06171c617c",
|
||||||
"reference": "8626798197fcdef636619e59b7151ca9f2952f63",
|
"reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -978,7 +978,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-06-20T09:56:03+00:00"
|
"time": "2020-06-22T09:29:56+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "zoujingli/wechat-developer",
|
"name": "zoujingli/wechat-developer",
|
||||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -955,12 +955,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||||
"reference": "8626798197fcdef636619e59b7151ca9f2952f63"
|
"reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/8626798197fcdef636619e59b7151ca9f2952f63",
|
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/2fe569700bd8d7e2a24054f3592c5b06171c617c",
|
||||||
"reference": "8626798197fcdef636619e59b7151ca9f2952f63",
|
"reference": "2fe569700bd8d7e2a24054f3592c5b06171c617c",
|
||||||
"shasum": "",
|
"shasum": "",
|
||||||
"mirrors": [
|
"mirrors": [
|
||||||
{
|
{
|
||||||
@ -976,7 +976,7 @@
|
|||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"topthink/framework": "^6.0"
|
"topthink/framework": "^6.0"
|
||||||
},
|
},
|
||||||
"time": "2020-06-20T09:56:03+00:00",
|
"time": "2020-06-22T09:29:56+00:00",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"think": {
|
"think": {
|
||||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// This file is automatically generated at:2020-06-20 18:06:40
|
// This file is automatically generated at:2020-06-22 17:43:32
|
||||||
declare (strict_types = 1);
|
declare (strict_types = 1);
|
||||||
return array (
|
return array (
|
||||||
0 => 'think\\app\\Service',
|
0 => 'think\\app\\Service',
|
||||||
|
64
vendor/zoujingli/think-library/src/Command.php
vendored
64
vendor/zoujingli/think-library/src/Command.php
vendored
@ -45,26 +45,15 @@ class Command extends ThinkCommand
|
|||||||
* @param Input $input
|
* @param Input $input
|
||||||
* @param Output $output
|
* @param Output $output
|
||||||
* @return $this
|
* @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 Exception
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
* @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 (defined('WorkQueueCode')) {
|
||||||
if (!$this->queue instanceof QueueService) {
|
if (!$this->queue instanceof QueueService) {
|
||||||
$this->queue = QueueService::instance();
|
$this->queue = QueueService::instance();
|
||||||
@ -72,6 +61,19 @@ class Command extends ThinkCommand
|
|||||||
if ($this->queue->code !== WorkQueueCode) {
|
if ($this->queue->code !== WorkQueueCode) {
|
||||||
$this->queue->initialize(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);
|
$this->queue->progress(2, $message, $progress);
|
||||||
} elseif (is_string($message)) {
|
} elseif (is_string($message)) {
|
||||||
$this->output->writeln($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 消息内容
|
* @param string $message 消息内容
|
||||||
* @return Command
|
* @return Command
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@ -111,4 +97,20 @@ class Command extends ThinkCommand
|
|||||||
return $this;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -87,7 +87,7 @@ class Library extends Service
|
|||||||
}, 'route');
|
}, 'route');
|
||||||
}
|
}
|
||||||
// 动态加入应用函数
|
// 动态加入应用函数
|
||||||
$sysRule = "{$this->app->getAppPath()}*/sys.php";
|
$sysRule = "{$this->app->getBasePath()}*/sys.php";
|
||||||
foreach (glob($sysRule) as $file) includeFile($file);
|
foreach (glob($sysRule) as $file) includeFile($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -98,11 +98,11 @@ class Queue extends Command
|
|||||||
if ($this->process->iswin()) {
|
if ($this->process->iswin()) {
|
||||||
$this->process->exec("start http://{$host}:{$port}");
|
$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 {
|
} else {
|
||||||
[$this->process->create($command), usleep(2000)];
|
[$this->process->create($command), usleep(2000)];
|
||||||
if (count($result = $this->process->query($command)) > 0) {
|
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()) {
|
if ($this->process->iswin()) {
|
||||||
$this->process->exec("start http://{$host}:{$port}");
|
$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) {
|
$this->app->db->name($this->table)->whereOr([$map1, $map2])->chunk(100, function (Collection $result) use ($total, &$loops, &$timeout) {
|
||||||
foreach ($result->toArray() as $item) {
|
foreach ($result->toArray() as $item) {
|
||||||
$item['loops_time'] > 0 ? $loops++ : $timeout++;
|
$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) {
|
if ($item['loops_time'] > 0) {
|
||||||
$this->setQueueProgress("[{$prefix}/{$total}] 正在重置任务 {$item['code']} 为运行", ($timeout + $loops) * 100 / $total);
|
$this->setQueueProgress("[{$prefix}/{$total}] 正在重置任务 {$item['code']} 为运行", ($timeout + $loops) * 100 / $total);
|
||||||
[$status, $message] = [1, intval($item['status']) === 4 ? '任务执行失败,已自动重置任务!' : '任务执行超时,已自动重置任务!'];
|
[$status, $message] = [1, intval($item['status']) === 4 ? '任务执行失败,已自动重置任务!' : '任务执行超时,已自动重置任务!'];
|
||||||
@ -233,7 +233,7 @@ class Queue extends Command
|
|||||||
$this->output->writeln("\tYou can exit with <info>`CTRL-C`</info>");
|
$this->output->writeln("\tYou can exit with <info>`CTRL-C`</info>");
|
||||||
$this->output->writeln('============== LISTENING ==============');
|
$this->output->writeln('============== LISTENING ==============');
|
||||||
while (true) {
|
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) {
|
$this->app->db->name($this->table)->where($where)->order('exec_time asc')->chunk(100, function (Collection $result) {
|
||||||
foreach ($result->toArray() as $vo) try {
|
foreach ($result->toArray() as $vo) try {
|
||||||
$command = $this->process->think("xadmin:queue dorun {$vo['code']} -");
|
$command = $this->process->think("xadmin:queue dorun {$vo['code']} -");
|
||||||
@ -245,12 +245,14 @@ class Queue extends Command
|
|||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->app->db->name($this->table)->where(['code' => $vo['code']])->update([
|
$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()}");
|
$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);
|
$this->queue->initialize($this->code);
|
||||||
if (empty($this->queue->record) || intval($this->queue->record['status']) !== 1) {
|
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 {
|
} else {
|
||||||
// 锁定任务状态,防止任务再次被执行
|
// 锁定任务状态,防止任务再次被执行
|
||||||
$this->app->db->name($this->table)->strict(false)->where(['code' => $this->code])->update([
|
$this->app->db->name($this->table)->strict(false)->where(['code' => $this->code])->update([
|
||||||
'enter_time' => microtime(true), 'attempts' => $this->app->db->raw('attempts+1'),
|
'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);
|
$this->queue->progress(2, '>>> 任务处理开始 <<<', 0);
|
||||||
// 设置进程标题
|
// 设置进程标题
|
||||||
|
@ -29,7 +29,7 @@ class DeleteHelper extends Helper
|
|||||||
* 表单额外更新条件
|
* 表单额外更新条件
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $map;
|
protected $where;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据对象主键名称
|
* 数据对象主键名称
|
||||||
@ -53,16 +53,16 @@ class DeleteHelper extends Helper
|
|||||||
*/
|
*/
|
||||||
public function init($dbQuery, $field = '', $where = [])
|
public function init($dbQuery, $field = '', $where = [])
|
||||||
{
|
{
|
||||||
$this->map = $where;
|
$this->where = $where;
|
||||||
$this->query = $this->buildQuery($dbQuery);
|
$this->query = $this->buildQuery($dbQuery);
|
||||||
$this->field = $field ?: $this->query->getPk();
|
$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->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));
|
$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;
|
return null;
|
||||||
}
|
}
|
||||||
// 执行删除操作
|
// 执行删除操作
|
||||||
@ -72,11 +72,8 @@ class DeleteHelper extends Helper
|
|||||||
if (in_array('deleted', $fields)) $data['deleted'] = 1;
|
if (in_array('deleted', $fields)) $data['deleted'] = 1;
|
||||||
if (in_array('is_deleted', $fields)) $data['is_deleted'] = 1;
|
if (in_array('is_deleted', $fields)) $data['is_deleted'] = 1;
|
||||||
}
|
}
|
||||||
if (empty($data)) {
|
empty($this->where) or $this->query->where($this->where);
|
||||||
$result = $this->query->where($this->map)->update($data);
|
$result = empty($data) ? $this->query->delete() : $this->query->update($data);
|
||||||
} else {
|
|
||||||
$result = $this->query->where($this->map)->delete();
|
|
||||||
}
|
|
||||||
// 结果回调处理
|
// 结果回调处理
|
||||||
if (false === $this->controller->callback('_delete_result', $result)) {
|
if (false === $this->controller->callback('_delete_result', $result)) {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -32,7 +32,7 @@ class ModuleService extends Service
|
|||||||
* @param ZipArchive $file 安装包
|
* @param ZipArchive $file 安装包
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function install($name, ZipArchive $file)
|
public function install(string $name, ZipArchive $file): array
|
||||||
{
|
{
|
||||||
// 安装包检查
|
// 安装包检查
|
||||||
list($state, $message) = $this->checkInstall($name, $file);
|
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;
|
$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 安装包
|
* @param ZipArchive $file 安装包
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function checkInstall($name, ZipArchive $file)
|
private function checkInstall(string $name, ZipArchive $file): array
|
||||||
{
|
{
|
||||||
$directory = "{$file->filename}.files";
|
$directory = "{$file->filename}.files";
|
||||||
file_exists($directory) || mkdir($directory, 0755, true);
|
file_exists($directory) || mkdir($directory, 0755, true);
|
||||||
@ -82,7 +87,7 @@ class ModuleService extends Service
|
|||||||
* 强制删除指定的目录
|
* 强制删除指定的目录
|
||||||
* @param string $directory
|
* @param string $directory
|
||||||
*/
|
*/
|
||||||
private function forceRemove($directory)
|
private function forceRemove(string $directory)
|
||||||
{
|
{
|
||||||
if (file_exists($directory) && is_dir($directory) && $handle = opendir($directory)) {
|
if (file_exists($directory) && is_dir($directory) && $handle = opendir($directory)) {
|
||||||
while (false !== ($item = readdir($handle))) if (!in_array($item, ['.', '..'])) {
|
while (false !== ($item = readdir($handle))) if (!in_array($item, ['.', '..'])) {
|
||||||
|
@ -62,7 +62,7 @@ class OpenService extends Service
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws \think\admin\Exception
|
* @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)];
|
[$time, $nostr, $json] = [time(), uniqid(), json_encode($data)];
|
||||||
$sign = md5($this->appid . '#' . $json . '#' . $time . '#' . $this->appkey . '#' . $nostr);
|
$sign = md5($this->appid . '#' . $json . '#' . $time . '#' . $this->appkey . '#' . $nostr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user