* Fix bugs.

This commit is contained in:
liugang
2017-10-25 15:06:47 +08:00
parent 51db6a81b9
commit 9375676a66
12 changed files with 65 additions and 53 deletions
+2
View File
@@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS `zt_entry` (
`createdDate` datetime NOT NULL,
`editedBy` varchar(30) NOT NULL,
`editedDate` datetime NOT NULL,
`deleted` enum('0', '1') NOT NULL DEFAULT '0',
PRIMARY KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -30,6 +31,7 @@ CREATE TABLE IF NOT EXISTS `zt_webhook` (
`createdDate` datetime NOT NULL,
`editedBy` varchar(30) NOT NULL,
`editedDate` datetime NOT NULL,
`deleted` enum('0', '1') NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+2
View File
@@ -19,5 +19,7 @@ $config->action->objectNameFields['module'] = 'name';
$config->action->objectNameFields['testsuite'] = 'name';
$config->action->objectNameFields['caselib'] = 'name';
$config->action->objectNameFields['testreport'] = 'title';
$config->action->objectNameFields['entry'] = 'name';
$config->action->objectNameFields['webhook'] = 'name';
$config->action->commonImgSize = 870;
+4
View File
@@ -73,6 +73,8 @@ $lang->action->objectTypes['module'] = '模块';
$lang->action->objectTypes['testsuite'] = '套件';
$lang->action->objectTypes['caselib'] = '用例库';
$lang->action->objectTypes['testreport'] = '报告';
$lang->action->objectTypes['entry'] = '应用';
$lang->action->objectTypes['webhook'] = 'Webhook';
/* 用来描述操作历史记录。*/
$lang->action->desc = new stdclass();
@@ -197,6 +199,8 @@ $lang->action->label->doclib = '文档库|doc|browse|libID=%s';
$lang->action->label->doc = '文档|doc|view|docID=%s';
$lang->action->label->user = '用户|user|view|account=%s';
$lang->action->label->testreport = '报告|testreport|view|report=%s';
$lang->action->label->entry = '应用|entry|browse|';
$lang->action->label->webhook = 'Webhook|webhook|browse|';
$lang->action->label->space = ' ';
/* Object type. */
+1 -1
View File
@@ -91,7 +91,7 @@ class entry extends control
*/
public function delete($entryID)
{
$this->entry->delete($entryID);
$this->entry->delete(TABLE_ENTRY, $entryID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success'));
+1 -15
View File
@@ -33,7 +33,7 @@ class entryModel extends model
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
return $this->dao->select('*')->from(TABLE_ENTRY)->orderBy($orderBy)->page($pager)->fetchAll('id');
return $this->dao->select('*')->from(TABLE_ENTRY)->where('deleted')->eq('0')->orderBy($orderBy)->page($pager)->fetchAll('id');
}
/**
@@ -93,18 +93,4 @@ class entryModel extends model
return common::createChanges($oldEntry, $entry);
}
/**
* Delete an entry.
*
* @param int $entryID
* @param int $null
* @access public
* @return bool
*/
public function delete($entryID, $null = null)
{
$this->dao->delete()->from(TABLE_ENTRY)->where('id')->eq($entryID)->exec();
return !dao::isError();
}
}
+2 -2
View File
@@ -13,12 +13,12 @@ $config->webhook->objectTypes['story'] = array('opened', 'edited', 'commen
$config->webhook->objectTypes['productplan'] = array('opened', 'edited');
//$config->webhook->objectTypes['release'] = array('opened', 'edited', 'changestatus');
$config->webhook->objectTypes['project'] = array('opened', 'edited', 'started', 'delayed', 'suspended', 'closed', 'activated', 'undeleted');
$config->webhook->objectTypes['task'] = array('opened', 'edited', 'commented', 'assigned', 'confirmed', 'started', 'finished', 'editestimate', 'deleteestimate', 'paused', 'canceled', 'restarted', 'closed', 'activated');
$config->webhook->objectTypes['task'] = array('opened', 'edited', 'commented', 'assigned', 'confirmed', 'started', 'finished', 'editestimate', 'paused', 'canceled', 'restarted', 'closed', 'activated');
//$config->webhook->objectTypes['build'] = array('opened', 'edited');
$config->webhook->objectTypes['bug'] = array('opened', 'edited', 'commented', 'assigned', 'confirmed', 'bugconfirmed', 'resolved', 'closed', 'activated');
$config->webhook->objectTypes['case'] = array('opened', 'edited', 'commented', 'reviewed', 'confirmed');
$config->webhook->objectTypes['testtask'] = array('opened', 'edited', 'started', 'blocked', 'closed', 'activated');
$config->webhook->objectTypes['todo'] = array('opened', 'edited', 'erased');
$config->webhook->objectTypes['todo'] = array('opened', 'edited');
//$config->webhook->objectTypes['testsuite'] = array('opened', 'edited');
//$config->webhook->objectTypes['caselib'] = array('opened', 'edited');
//$config->webhook->objectTypes['testreport'] = array('opened', 'edited');
+3 -3
View File
@@ -97,7 +97,7 @@ class webhook extends control
*/
public function delete($id)
{
$this->webhook->delete($id);
$this->webhook->delete(TABLE_WEBHOOK, $id);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success'));
@@ -149,8 +149,8 @@ class webhook extends control
if($webhook)
{
$contentType = zget($this->config->webhook->contentTypes, $webhook->contentType, 'application/json');
$httpCode = $this->webhook->fetchHook($contentType, $webhook->url, $data->data);
$this->saveLog($data->webhook, $data->action, $webhook->url, $contentType, $data->data, $httpCode);
$result = $this->webhook->fetchHook($contentType, $webhook->url, $data->data);
$this->saveLog($data->webhook, $data->action, $webhook->url, $contentType, $data->data, $result);
}
if($httpCode == 200) $this->dao->update(TABLE_WEBHOOKDATA)->set('status')->eq('sended')->where('id')->eq($data->id)->exec();
+4 -1
View File
@@ -44,4 +44,7 @@ $lang->webhook->confirmDelete = '您确认要删除该webhook吗?';
$lang->webhook->trimWords = '了';
$lang->webhook->note = new stdClass();
$lang->webhook->note->async = '异步需要打开计划任务';
$lang->webhook->note->async = '异步需要打开计划任务';
$lang->webhook->note->dingding = '请在钉钉中添加一个自定义机器人,并将其webhook填写到此处。';
$lang->webhook->note->product = '此项为空时所有产品的动作都会触发钩子,否则只有关联产品的动作才会触发。';
$lang->webhook->note->project = '此项为空时所有项目的动作都会触发钩子,否则只有关联项目的动作才会触发。';
+37 -26
View File
@@ -37,7 +37,7 @@ class webhookModel extends model
public function getList($type = '', $orderBy = 'id_desc', $pager = null)
{
$webhooks = $this->dao->select('*')->from(TABLE_WEBHOOK)
->where(1)
->where('deleted')->eq('0')
->beginIF($type)->andWhere('type')->eq($type)->fi()
->orderBy($orderBy)
->page($pager)
@@ -63,7 +63,32 @@ class webhookModel extends model
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
foreach($logs as $log) $log->data = json_decode($log->data);
$actions = array();
foreach($logs as $log) $actions[] = $log->action;
$this->loadModel('action');
$actions = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->in($actions)->fetchAll('id');
foreach($logs as $log)
{
if(!isset($actions[$log->action]))
{
$log->action = '';
continue;
}
$action = $actions[$log->action];
$text = $this->app->user->realname . $this->lang->action->label->{$action->action}. $this->lang->action->objectTypes[$action->objectType];
$object = $this->dao->select('*')->from($this->config->objectTables[$action->objectType])->where('id')->eq($action->objectID)->fetch();
$field = $this->config->action->objectNameFields[$action->objectType];
$text .= "[#{$action->objectID}::{$object->$field}]";
if($action->action == 'assigned') $text .= ' ' . $this->lang->webhook->assigned . ' ' . zget($users, $object->assignedTo);
$log->action = $text;
$log->actionURL = $this->getViewLink($action->objectType, $action->objectID);
}
return $logs;
}
@@ -167,21 +192,6 @@ class webhookModel extends model
return !dao::isError();
}
/**
* Delete a webhook.
*
* @param int $id
* @param object $null
* @access public
* @return bool
*/
public function delete($id, $null = null)
{
$this->dao->delete()->from(TABLE_WEBHOOK)->where('id')->eq($id)->exec();
$this->dao->delete()->from(TABLE_LOG)->where('objectType')->eq('webhook')->andWhere('objectID')->eq($id)->exec();
return !dao::isError();
}
/**
* Send data.
*
@@ -201,7 +211,7 @@ class webhookModel extends model
$snoopy = $this->app->loadClass('snoopy');
foreach($webhooks as $id => $webhook)
{
if(!in_array($actionType, $webhook->actions->$objectType)) continue;
if(!isset($webhook->actions->$objectType) or !in_array($actionType, $webhook->actions->$objectType)) continue;
$postData = $this->buildData($objectType, $objectID, $actionType, $actionID, $webhook);
if(!$postData) continue;
@@ -212,8 +222,8 @@ class webhookModel extends model
}
$contentType = zget($this->config->webhook->contentTypes, $webhook->contentType, 'application/json');
$httpCode = $this->fetchHook($contentType, $webhook->url, $postData);
$this->saveLog($id, $actionID, $webhook->url, $contentType, $postData, $httpCode);
$result = $this->fetchHook($contentType, $webhook->url, $postData);
$this->saveLog($id, $actionID, $webhook->url, $contentType, $postData, $result);
}
return !dao::isError();
}
@@ -275,7 +285,7 @@ class webhookModel extends model
{
if($param == 'text')
{
$data->text = $this->app->user->realname . $this->lang->action->label->$actionType . $this->lang->action->objectTypes[$objectType] . ' ' . "[#{$objectID}::{$title}](" . $host . $viewLink . ")";
$data->text = $this->app->user->realname . $this->lang->action->label->$actionType . $this->lang->action->objectTypes[$objectType] . ' ' . "[#{$objectID}::{$text}](" . $host . $viewLink . ")";
if($actionType == 'assigned') $data->text .= ' ' . $this->lang->webhook->assigned . ' ' . zget($users, $object->assignedTo);
}
else
@@ -360,12 +370,13 @@ class webhookModel extends model
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($ch);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if($error) return $error;
if($error) return $error;
if($result) return $result;
return $httpCode;
}
@@ -399,11 +410,11 @@ class webhookModel extends model
* @param string $url
* @param string $contentType
* @param string $data
* @param int $status
* @param string $result
* @access public
* @return bool
*/
public function saveLog($webhookID, $actionID, $url, $contentType, $data, $status)
public function saveLog($webhookID, $actionID, $url, $contentType, $data, $result)
{
$log = new stdclass();
$log->objectType = 'webhook';
@@ -413,7 +424,7 @@ class webhookModel extends model
$log->url = $url;
$log->contentType = $contentType;
$log->data = $data;
$log->status = $status;
$log->result = $result;
$this->dao->insert(TABLE_LOG)->data($log)->exec();
return !dao::isError();
+3 -1
View File
@@ -29,7 +29,7 @@
<tr>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', '', "class='form-control'");?></td>
<td></td>
<td><?php if($type == 'dingding') echo $lang->webhook->note->dingding;?></td>
</tr>
<?php if($type != 'dingding'):?>
<tr>
@@ -46,10 +46,12 @@
<tr>
<th><?php echo $lang->webhook->product;?></th>
<td><?php echo html::select('products[]', $products, '', "class='form-control chosen' multiple");?></td>
<td><?php echo $lang->webhook->note->product;?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->project;?></th>
<td><?php echo html::select('projects[]', $projects, '', "class='form-control chosen' multiple");?></td>
<td><?php echo $lang->webhook->note->project;?></td>
</tr>
<?php if($type != 'dingding'):?>
<tr>
+3 -1
View File
@@ -29,7 +29,7 @@
<tr>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', $webhook->url, "class='form-control'");?></td>
<td></td>
<td><?php if($webhook->type == 'dingding') echo $lang->webhook->note->dingding;?></td>
</tr>
<?php if($webhook->type != 'dingding'):?>
<tr>
@@ -46,10 +46,12 @@
<tr>
<th><?php echo $lang->webhook->product;?></th>
<td><?php echo html::select('products[]', $products, $webhook->products, "class='form-control chosen' multiple");?></td>
<td><?php echo $lang->webhook->note->product;?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->project;?></th>
<td><?php echo html::select('projects[]', $projects, $webhook->projects, "class='form-control chosen' multiple");?></td>
<td><?php echo $lang->webhook->note->project;?></td>
</tr>
<?php if($webhook->type != 'dingding'):?>
<tr>
+3 -3
View File
@@ -26,7 +26,7 @@
<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>
<th class='w-80px'><?php common::printOrderLink('status', $orderBy, $vars, $lang->webhook->status);?></th>
<th class='w-200px'><?php common::printOrderLink('status', $orderBy, $vars, $lang->webhook->status);?></th>
</tr>
</thead>
<tbody>
@@ -34,9 +34,9 @@
<tr>
<td class='text-center'><?php echo $id;?></td>
<td class='text' title='<?php echo $log->url;?>'><?php echo $log->url;?></td>
<td class='text' title='<?php echo $log->data->text;?>'><?php echo $log->data->text;?></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>
<td><?php echo $log->status;?></td>
<td title='<?php echo $log->result;?>'><?php echo $log->result;?></td>
</tr>
<?php endforeach;?>
</tbody>