当我们新增bug的时候,需要在新增、编辑、查看等界面新增一列方便记录和统计时,就需要去修改禅道的配置
- 禅道版本:12.5.2
- 服务器:阿里云
- 系统:CentOS Linux release 7.6.1810 (Core)
一、数据库插入自定义列字段
1、查看数据库配置 my.cnf
- 位置:
/opt/zbox/etc/mysql
[root@iZwz9ga2spyeb5u9tdq8t5Z mysql]# pwd
/opt/zbox/etc/mysql
[root@iZwz9ga2spyeb5u9tdq8t5Z mysql]# ls
my.cnf
PS:是为了方便查询下端口
2、命令行进入数据库
- 初始密码是:123456
/opt/zbox/bin/mysql -u root -P 3306 -p # 注意使用自己的端口号
- 使用“zentao”的库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zentao |
| zentaoep |
| zentaopro |
+--------------------+
6 rows in set (0.000 sec)
- 查看表,我们需要操作的表是
zt_bug
MariaDB [(none)]> use zentao;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zentao]> show tables;
+------------------------+
| Tables_in_zentao |
+------------------------+
| zt_action |
| zt_block |
| zt_branch |
| zt_bug |
| zt_build |
| zt_burn |
....
+------------------------+
71 rows in set (0.001 sec)
- 给表插入新的列
owner
ALTER TABLE `zt_bug` ADD COLUMN owner(列名) VARCHAR(50) AFTER resolvedBy;
二、修改源码
1、修改zh-cn.php
- 路径:/opt/zbox/app/zentao/module/bug/lang
[root@iZwz9ga2spyeb5u9tdq8t5Z lang]# ls
de.php en.php fr.php index.html vi.php zh-cn.php zh-tw.php
- “字段列表”标签下,添加如下“
owner责任人
”代码
/* 字段列表。*/
$lang->bug->common = 'Bug';
$lang->bug->id = 'Bug编号';
......
$lang->bug->lastEditedDateAB = '修改日期';
$lang->bug->lastEditedDate = '修改日期';
$lang->bug->fromCase = '来源用例';
$lang->bug->toCase = '生成用例';
$lang->bug->colorTag = '颜色标签';
$lang->bug->owner = 'owner责任人'; # 新添加的
2、修改 新增界面源码create.html.php
- 路径:/opt/zbox/app/zentao/module/bug/view
[root@iZwz9ga2spyeb5u9tdq8t5Z view]# ls
1 batchactivate.html.php browse.html.php create.html.php index.html resolve.html.php
activate.html.php batchcreate.html.php close.html.php edit.html.php linkbugs.html.php sendmail.html.php
assignto.html.php batchedit.html.php confirmbug.html.php export.html.php report.html.php view.html.php
- 合适位置插入如下代码,我是在122行 assignedTo 下插入的
<tr>
<th><nobr><?php echo $lang->bug->owner;?></nobr></th>
<td>
<div class='input-group'>
<?php echo html::select('owner', $projectMembers, $owner, "class='from-control chosen'");?>
<span class='input-group-btn'><?php echo html::commonButton($lang->bug->allUsers, "class='btn btn-default' onclick='loadAllUsers()' data-toggle='tooltip'");?></span>
</div>
</td>
</tr>
PS:$projectMembers是指派给字段的下拉枚举
3、修改 编辑界面源码edit.html.php
- 路径:/opt/zbox/app/zentao/module/bug/view
- 合适位置插入如下代码
js::set('owner' , $bug->owner);
include '../../common/view/header.html.php';
include '../../common/view/datepicker.html.php';
include '../../common/view/kindeditor.html.php';
js::set('page' , 'edit');
js::set('changeProductConfirmed' , false);
js::set('changeProjectConfirmed' , false);
js::set('confirmChangeProduct' , $lang->bug->confirmChangeProduct);
js::set('planID' , $bug->plan);
js::set('oldProjectID' , $bug->project);
js::set('oldStoryID' , $bug->story);
js::set('oldTaskID' , $bug->task);
js::set('oldOpenedBuild' , $bug->openedBuild);
js::set('oldResolvedBuild' , $bug->resolvedBuild);
js::set('owner' , $bug->owner);
?>
<div class='main-content' id='mainContent'>
- 再次插入如下代码,我是在144行插入的,assignedTo上面
<tr>
<th><?php echo $lang->bug->owner;?></th>
<td><?php echo html::select('owner', $users, $bug->owner, "class='form-control chosen'");?></td>
</tr>
4、修改 查看界面源码view.html.php
- 路径:/opt/zbox/app/zentao/module/bug/view
- 在合适位置插入如下代码
<tr>
<th><?php echo $lang->bug->personLiable;?></th>
<td><?php if($bug->personLiable) echo $users[$bug->personLiable];?></td>
</tr>
5、修改 配置config.php
- 路径:/opt/zbox/app/zentao/module/bug
[root@iZwz9ga2spyeb5u9tdq8t5Z bug]# pwd
/opt/zbox/app/zentao/module/bug
[root@iZwz9ga2spyeb5u9tdq8t5Z bug]# ls
config.php control.php css ext index.html js lang model.php view
- 给新增时添加必填项目owner
$config->bug->create->requiredFields = 'title,openedBuild,owner';
- 给解决时添加必填项目owner
$config->bug->resolve->requiredFields = 'resolution,source,owner';
- 增加owner责任人搜索字段
在global $lang 下面
global $lang;
$config->bug->search['module'] = 'bug';
$config->bug->search['fields']['title'] = $lang->bug->title;
$config->bug->search['fields']['id'] = $lang->bug->id;
$config->bug->search['fields']['keywords'] = $lang->bug->keywords;
$config->bug->search['fields']['steps'] = $lang->bug->steps;
$config->bug->search['fields']['assignedTo'] = $lang->bug->assignedTo;
$config->bug->search['fields']['resolvedBy'] = $lang->bug->resolvedBy;
$config->bug->search['fields']['owner'] = $lang->bug->owner; # 搜索字段
- 设置责任人可选列表
$config->bug->search['params']['title'] = array('operator' => 'include', 'control' => 'input', 'values' => '');
$config->bug->search['params']['keywords'] = array('operator' => 'include', 'control' => 'input', 'values' => '');
$config->bug->search['params']['steps'] = array('operator' => 'include', 'control' => 'input', 'values' => '');
$config->bug->search['params']['assignedTo'] = array('operator' => '=', 'control' => 'select', 'values' => 'users');
$config->bug->search['params']['resolvedBy'] = array('operator' => '=', 'control' => 'select', 'values' => 'users');
$config->bug->search['params']['owner'] = array('operator' => '=', 'control' => 'select', 'values' => 'users'); # 可选列表
- 给导出新增owner字段
$config->bug->list->exportFields = 'id, product, branch, module, project, story, task,
title, keywords, severity, pri, type, os, browser, owner, # 导出新增owner
steps, status, deadline, activatedCount, confirmed, mailto,
openedBy, openedDate, openedBuild,
assignedTo, assignedDate,
resolvedBy, resolution, resolvedBuild, resolvedDate,
closedBy, closedDate,
duplicateBug, linkBug,
case,
lastEditedBy,
lastEditedDate, files';
三、统计图添加字段
1、修改对应语言文件:vi zh-cn.php
- 添加统计报表字段
$lang->bug->report->charts['personLiable'] = 'owner统计';
/* 统计报表。*/
$lang->bug->report = new stdclass();
$lang->bug->report->common = '报表';
$lang->bug->report->select = '请选择报表类型';
$lang->bug->report->create = '生成报表';
...
$lang->bug->report->charts['bugsPerPri'] = '按Bug优先级统计';
$lang->bug->report->charts['bugsPerType'] = '按Bug类型统计';
$lang->bug->report->charts['bugsPerAssignedTo'] = '按指派给统计';
$lang->bug->report->charts['personLiable'] = 'owner统计';
- 添加字段报表空对象
$lang->bug->report->personLiable = new stdclass();
...
$lang->bug->report->bugsPerType = new stdclass();
$lang->bug->report->bugsPerPri = new stdclass();
$lang->bug->report->bugsPerAssignedTo = new stdclass();
$lang->bug->report->bugLiveDays = new stdclass();
$lang->bug->report->personLiable = new stdclass();
$lang->bug->report->bugHistories = new stdclass();
- 添加图表空对象
$lang->bug->report->personLiable->graph = new stdclass();
$lang->bug->report->resolvedBugsPerUser->graph = new stdclass();
$lang->bug->report->closedBugsPerUser->graph = new stdclass();
$lang->bug->report->bugsPerSeverity->graph = new stdclass();
$lang->bug->report->bugsPerResolution->graph = new stdclass();
$lang->bug->report->bugsPerStatus->graph = new stdclass();
$lang->bug->report->bugsPerActivatedCount->graph = new stdclass();
$lang->bug->report->bugsPerType->graph = new stdclass();
$lang->bug->report->bugsPerPri->graph = new stdclass();
$lang->bug->report->bugsPerAssignedTo->graph = new stdclass();
$lang->bug->report->bugLiveDays->graph = new stdclass();
$lang->bug->report->personLiable->graph = new stdclass();
- 添加图表显示字段信息
$lang->bug->report->personLiable->graph->xAxisName = 'owner责任人';
2、module.php中新增字段统计方法
- 路径:/opt/zbox/app/zentao/module/bug/model.php
- 在合适位置插入如下代码
public function getDataOfPersonLiable()
{
$datas = $this->dao->select('personLiable As name, COUNT(*) AS value')->from(TABLE_BUG)->where($this->reportCondition())->groupBy('name')->orderBy('value DESC')->fetchAll('name');
if(!$datas) return array();
foreach($datas as $personLiable => $data) if(isset($this->lang->bug->users[$personLiable])) $data->name = $this->lang->bug->users[$personLiable];
return $datas;
}