diff --git a/module/webhook/model.php b/module/webhook/model.php index da6ea25ade..0b13fc0a6b 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -84,7 +84,7 @@ class webhookModel extends model * @access public * @return array */ - public function getLogList($id, $orderBy = 'date_desc', $pager = null) + public function getLogList(int $id, string $orderBy = 'date_desc', object $pager = null): array { $logs = $this->dao->select('*')->from(TABLE_LOG) ->where('objectType')->eq('webhook') @@ -98,8 +98,8 @@ class webhookModel extends model $this->loadModel('action'); $actions = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->in($actions)->fetchAll('id'); - $users = $this->loadModel('user')->getPairs('noletter'); + foreach($logs as $log) { if(!isset($actions[$log->action])) @@ -119,30 +119,7 @@ class webhookModel extends model $object->$field = ''; } - $text = ''; - if(isset($data->markdown->text)) - { - $text = substr($data->markdown->text, 0, strpos($data->markdown->text, '(http')); - } - elseif(isset($data->markdown->content)) - { - $text = substr($data->markdown->content, 0, strpos($data->markdown->content, '(http')); - } - elseif(isset($data->text->content)) - { - $text = substr($data->text->content, 0, strpos($data->text->content, '(http')); - } - elseif(isset($data->content)) - { - $text = $data->content->text; - $text = substr($text, 0, strpos($text, '(http')) ? substr($text, 0, strpos($text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]"; - } - else - { - $text = substr($data->text, 0, strpos($data->text, '(http')) ? substr($data->text, 0, strpos($data->text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]"; - } - - $log->action = $text; + $log->action = $this->webhookTao->getActionText($data, $action, $object, $users); $log->actionURL = $this->getViewLink($action->objectType, $action->objectID); $log->module = $action->objectType; $log->moduleID = $action->objectID; diff --git a/module/webhook/tao.php b/module/webhook/tao.php index 0f4ea90f8e..e0ab341eac 100644 --- a/module/webhook/tao.php +++ b/module/webhook/tao.php @@ -87,4 +87,44 @@ class webhookTao extends webhookModel return $webhook; } + + /** + * 获取动作的文本。 + * Get the text of action. + * + * @param object $data + * @param object $action + * @param object $object + * @param array $users + * @access public + * @return string + */ + protected function getActionText(object $data, object $action, object $object, array $users): string + { + $text = ''; + + if(isset($data->markdown->text)) + { + $text = substr($data->markdown->text, 0, strpos($data->markdown->text, '(http')); + } + elseif(isset($data->markdown->content)) + { + $text = substr($data->markdown->content, 0, strpos($data->markdown->content, '(http')); + } + elseif(isset($data->text->content)) + { + $text = substr($data->text->content, 0, strpos($data->text->content, '(http')); + } + elseif(isset($data->content)) + { + $text = $data->content->text; + $text = substr($text, 0, strpos($text, '(http')) ? substr($text, 0, strpos($text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]"; + } + else + { + $text = substr($data->text, 0, strpos($data->text, '(http')) ? substr($data->text, 0, strpos($data->text, '(http')) : zget($users, $data->user, $this->app->user->realname) . $this->lang->action->label->{$action->action} . $this->lang->action->objectTypes[$action->objectType] . "[#{$action->objectID}::{$object->$field}]"; + } + + return $text; + } } diff --git a/module/webhook/test/model/getloglist.php b/module/webhook/test/model/getloglist.php index 447a446c72..81db0f0be0 100755 --- a/module/webhook/test/model/getloglist.php +++ b/module/webhook/test/model/getloglist.php @@ -4,16 +4,18 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/webhook.class.php'; su('admin'); +zdTable('log')->gen(10); + /** title=测试 webhookModel->getLogList(); +timeout=0 cid=1 -pid=1 -统计ID为1的日志数量 >> 0 -统计ID为2的日志数量 >> 0 -统计ID不存在时的数量 >> 0 -取出ID为1的其中一个匹配操作内容 >> 0 +- 统计ID为1的日志数量 @0 +- 统计ID为2的日志数量 @1 +- 统计ID不存在时的数量 @0 +- 取出ID为1的其中一个匹配操作内容第4条的action属性 @0 */ @@ -24,12 +26,12 @@ $ID[0] = 1; $ID[1] = 3; $ID[2] = 1111; -$result1 = $webhook->getLogListTest($ID[0], '', ''); -$result2 = $webhook->getLogListTest($ID[1], '', ''); -$result3 = $webhook->getLogListTest($ID[2], '', ''); +$result1 = $webhook->getLogListTest($ID[0]); +$result2 = $webhook->getLogListTest($ID[1]); +$result3 = $webhook->getLogListTest($ID[2]); //a($result1);die; -r(count($result1)) && p() && e('0'); //统计ID为1的日志数量 -r(count($result2)) && p() && e('0'); //统计ID为2的日志数量 -r(count($result3)) && p() && e('0'); //统计ID不存在时的数量 -r($result1) && p('4:action') && e('0'); //取出ID为1的其中一个匹配操作内容 \ No newline at end of file +r(count($result1)) && p() && e('0'); //统计ID为1的日志数量 +r(count($result2)) && p() && e('1'); //统计ID为2的日志数量 +r(count($result3)) && p() && e('0'); //统计ID不存在时的数量 +r($result1) && p('4:action') && e('0'); //取出ID为1的其中一个匹配操作内容 \ No newline at end of file diff --git a/test/data/log.yaml b/test/data/log.yaml index 9ac693b34a..5f8ee5d649 100644 --- a/test/data/log.yaml +++ b/test/data/log.yaml @@ -54,9 +54,7 @@ fields: format: "" - field: data note: "数据" - range: a-z - prefix: "" - postfix: "" + range: '`{"content":{"text":"test(http://test.com)"}}`' loop: 0 format: "" - field: result