From 7116d5b45421135970d36cb6694310b65f718a28 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 27 Oct 2017 10:26:11 +0800 Subject: [PATCH] * Add function to avoid error when user cron to async send message. --- db/update9.5.1.sql | 2 +- module/webhook/control.php | 26 ++++++++++++++++++-------- module/webhook/js/create.js | 2 +- module/webhook/js/edit.js | 2 +- module/webhook/lang/zh-cn.php | 3 ++- module/webhook/model.php | 6 +++--- module/webhook/view/create.html.php | 2 +- module/webhook/view/log.html.php | 2 ++ 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/db/update9.5.1.sql b/db/update9.5.1.sql index 50c22de4a3..7223eb3bf6 100644 --- a/db/update9.5.1.sql +++ b/db/update9.5.1.sql @@ -94,4 +94,4 @@ CREATE TABLE `zt_score` ( KEY `method` (`method`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES ('*/5', '*', '*', '*', '*', 'moduleName=webhook&methodName=asyncSend', '异步发送Webhook', 'zentao', 0, 'normal', '0000-00-00 00:00:00'); +INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES ('*/5', '*', '*', '*', '*', 'moduleName=webhook&methodName=asyncSend', '异步发送Webhook', 'zentao', 1, 'normal', '0000-00-00 00:00:00'); diff --git a/module/webhook/control.php b/module/webhook/control.php index bab999ee9e..9f768555d6 100644 --- a/module/webhook/control.php +++ b/module/webhook/control.php @@ -136,12 +136,20 @@ class webhook extends control */ public function asyncSend() { - $webhooks = $this->webhook->getList(); - if(empty($hooks)) return false; - $dataList = $this->webhook->getDataList(); - if(empty($dataList)) return true; + $webhooks = $this->webhook->getList($type = '', $orderBy = 'id_desc', $pager = null, $decode = false); + if(empty($webhooks)) + { + echo "NO WEBHOOK EXIST.\n"; + return false; + } + + $dataList = $this->webhook->getDataList(); + if(empty($dataList)) + { + echo "OK\n"; + return true; + } - $snoopy = $this->app->loadClass('snoopy'); foreach($dataList as $data) { $webhook = zget($webhooks, $data->webhook, ''); @@ -149,13 +157,15 @@ class webhook extends control { $contentType = zget($this->config->webhook->contentTypes, $webhook->contentType, 'application/json'); $result = $this->webhook->fetchHook($contentType, $webhook->url, $data->data); - $this->saveLog($data->webhook, $data->action, $webhook->url, $contentType, $data->data, $result); + $this->webhook->saveLog($data->webhook, $data->action, $webhook->url, $contentType, $data->data, $result); } - $this->dao->update(TABLE_WEBHOOKDATA)->set('status')->eq('sended')->where('id')->eq($data->id)->exec(); + $this->dao->update(TABLE_WEBHOOKDATAS)->set('status')->eq('sended')->where('id')->eq($data->id)->exec(); } - $this->dao->delete()->from(TABLE_WEBHOOKDATA)->where('status')->eq('sended')->exec(); + $this->dao->delete()->from(TABLE_WEBHOOKDATAS)->where('status')->eq('sended')->exec(); + + echo "OK\n"; return true; } } diff --git a/module/webhook/js/create.js b/module/webhook/js/create.js index 3acb71ac46..9fed36bc05 100644 --- a/module/webhook/js/create.js +++ b/module/webhook/js/create.js @@ -13,5 +13,5 @@ $(function() }); $('#name').focus(); - $('#paramsmessage').attr('disabled', 'disabled'); + $('#paramstext').attr('disabled', 'disabled'); }); diff --git a/module/webhook/js/edit.js b/module/webhook/js/edit.js index 3acb71ac46..9fed36bc05 100644 --- a/module/webhook/js/edit.js +++ b/module/webhook/js/edit.js @@ -13,5 +13,5 @@ $(function() }); $('#name').focus(); - $('#paramsmessage').attr('disabled', 'disabled'); + $('#paramstext').attr('disabled', 'disabled'); }); diff --git a/module/webhook/lang/zh-cn.php b/module/webhook/lang/zh-cn.php index 2e95a320d8..f7f0c744fe 100644 --- a/module/webhook/lang/zh-cn.php +++ b/module/webhook/lang/zh-cn.php @@ -26,6 +26,7 @@ $lang->webhook->createdBy = '由谁创建'; $lang->webhook->createdDate = '创建时间'; $lang->webhook->editedby = '最后编辑'; $lang->webhook->editedDate = '编辑时间'; +$lang->webhook->date = '发送时间'; $lang->webhook->data = '数据'; $lang->webhook->result = '结果'; @@ -40,7 +41,7 @@ $lang->webhook->paramsList['action'] = '动作'; $lang->webhook->paramsList['actor'] = '操作者'; $lang->webhook->paramsList['date'] = '操作日期'; $lang->webhook->paramsList['comment'] = '备注'; -$lang->webhook->paramsList['message'] = '操作内容'; +$lang->webhook->paramsList['text'] = '操作内容'; $lang->webhook->saveSuccess = '保存成功'; $lang->webhook->confirmDelete = '您确认要删除该webhook吗?'; diff --git a/module/webhook/model.php b/module/webhook/model.php index 7fc7df5c8e..16699baf5d 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -31,10 +31,11 @@ class webhookModel extends model * @param string $type * @param string $orderBy * @param object $pager + * @param bool $decode * @access public * @return array */ - public function getList($type = '', $orderBy = 'id_desc', $pager = null) + public function getList($type = '', $orderBy = 'id_desc', $pager = null, $decode = true) { $webhooks = $this->dao->select('*')->from(TABLE_WEBHOOK) ->where('deleted')->eq('0') @@ -42,7 +43,7 @@ class webhookModel extends model ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); - foreach($webhooks as $webhook) $webhook->actions = json_decode($webhook->actions); + if($decode) foreach($webhooks as $webhook) $webhook->actions = json_decode($webhook->actions); return $webhooks; } @@ -208,7 +209,6 @@ class webhookModel extends model if(!$webhooks) $webhooks = $this->getList(); if(!$webhooks) return true; - $snoopy = $this->app->loadClass('snoopy'); foreach($webhooks as $id => $webhook) { if(!isset($webhook->actions->$objectType) or !in_array($actionType, $webhook->actions->$objectType)) continue; diff --git a/module/webhook/view/create.html.php b/module/webhook/view/create.html.php index ddd74bacf0..6b59be8c1f 100644 --- a/module/webhook/view/create.html.php +++ b/module/webhook/view/create.html.php @@ -56,7 +56,7 @@ webhook->params;?> - webhook->paramsList, 'message');?> + webhook->paramsList, 'text');?> diff --git a/module/webhook/view/log.html.php b/module/webhook/view/log.html.php index 8d2add7770..755aef4c62 100644 --- a/module/webhook/view/log.html.php +++ b/module/webhook/view/log.html.php @@ -23,6 +23,7 @@ id}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> webhook->id);?> + webhook->date);?> webhook->url);?> webhook->action);?> webhook->contentType);?> @@ -33,6 +34,7 @@ $log):?> + date;?> url;?> actionURL, $log->action);?> contentType;?>