* Add function to avoid error when user cron to async send message.
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,5 @@ $(function()
|
||||
});
|
||||
|
||||
$('#name').focus();
|
||||
$('#paramsmessage').attr('disabled', 'disabled');
|
||||
$('#paramstext').attr('disabled', 'disabled');
|
||||
});
|
||||
|
||||
@@ -13,5 +13,5 @@ $(function()
|
||||
});
|
||||
|
||||
$('#name').focus();
|
||||
$('#paramsmessage').attr('disabled', 'disabled');
|
||||
$('#paramstext').attr('disabled', 'disabled');
|
||||
});
|
||||
|
||||
@@ -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吗?';
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<?php if($type != 'dingding'):?>
|
||||
<tr>
|
||||
<th><?php echo $lang->webhook->params;?></th>
|
||||
<td class='labelWidth' colspan='2'><?php echo html::checkbox('params', $lang->webhook->paramsList, 'message');?></td>
|
||||
<td class='labelWidth' colspan='2'><?php echo html::checkbox('params', $lang->webhook->paramsList, 'text');?></td>
|
||||
</tr>
|
||||
<?php endif;?>
|
||||
<tr>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<tr>
|
||||
<?php $vars = "id={$webhook->id}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
|
||||
<th class='w-60px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->webhook->id);?></th>
|
||||
<th class='w-160px'><?php common::printOrderLink('date', $orderBy, $vars, $lang->webhook->date);?></th>
|
||||
<th><?php common::printOrderLink('url', $orderBy, $vars, $lang->webhook->url);?></th>
|
||||
<th class='w-300px'><?php common::printOrderLink('action', $orderBy, $vars, $lang->webhook->action);?></th>
|
||||
<th class='w-200px'><?php common::printOrderLink('contentType', $orderBy, $vars, $lang->webhook->contentType);?></th>
|
||||
@@ -33,6 +34,7 @@
|
||||
<?php foreach($logs as $id => $log):?>
|
||||
<tr>
|
||||
<td class='text-center'><?php echo $id;?></td>
|
||||
<td><?php echo $log->date;?></td>
|
||||
<td class='text' title='<?php echo $log->url;?>'><?php echo $log->url;?></td>
|
||||
<td class='text' title='<?php echo $log->action;?>'><?php echo html::a($log->actionURL, $log->action);?></td>
|
||||
<td class='text-center'><?php echo $log->contentType;?></td>
|
||||
|
||||
Reference in New Issue
Block a user