* Refactor getDataOfBugsPerBuild function.
This commit is contained in:
+33
-26
@@ -1829,50 +1829,57 @@ class bugModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取版本 Bug 数量。
|
||||
* Get report data of bugs per build.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getDataOfBugsPerBuild()
|
||||
public function getDataOfBugsPerBuild(): array
|
||||
{
|
||||
$datas = $this->dao->select('openedBuild as name, count(openedBuild) as value')->from(TABLE_BUG)->where($this->reportCondition())->groupBy('openedBuild')->orderBy('value DESC')->fetchAll('name');
|
||||
$datas = $this->dao->select('openedBuild AS name, COUNT(openedBuild) AS value')->from(TABLE_BUG)->where($this->reportCondition())->groupBy('openedBuild')->orderBy('value DESC')->fetchAll('name');
|
||||
if(!$datas) return array();
|
||||
/* Judge if all product or not. */
|
||||
$products = $this->session->product;
|
||||
preg_match('/`product` IN \((?P<productIdList>.+)\)/', $this->reportCondition(), $matchs);
|
||||
if(!empty($matchs) and isset($matchs['productIdList'])) $products = str_replace('\'', '', $matchs['productIdList']);
|
||||
$builds = $this->loadModel('build')->getBuildPairs($products, $branch = 0, $params = 'hasdeleted');
|
||||
|
||||
/* Deal with the situation that a bug maybe associate more than one openedBuild. */
|
||||
foreach($datas as $buildIDList => $data)
|
||||
{
|
||||
$openBuildIDList = explode(',', $buildIDList);
|
||||
if(count($openBuildIDList) > 1)
|
||||
if(is_int($buildIDList)) continue;
|
||||
if(strpos(trim($buildIDList, ','), ',') === false) continue;
|
||||
|
||||
$openedBuildIDList = explode(',', $buildIDList);
|
||||
|
||||
/* Bug 可以关联多个影响版本,一个版本被多个 bug 关联时,累加 bug 数量。*/
|
||||
/* Bugs can be associated with multiple builds. When a build is associated with multiple bugs, accumulated bugs.*/
|
||||
foreach($openedBuildIDList as $buildID)
|
||||
{
|
||||
foreach($openBuildIDList as $buildID)
|
||||
if(!isset($datas[$buildID]))
|
||||
{
|
||||
if(isset($datas[$buildID]))
|
||||
{
|
||||
$datas[$buildID]->value += $data->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!isset($datas[$buildID])) $datas[$buildID] = new stdclass();
|
||||
$datas[$buildID]->name = $buildID;
|
||||
$datas[$buildID]->value = $data->value;
|
||||
}
|
||||
$datas[$buildID] = new stdclass();
|
||||
$datas[$buildID]->name = $buildID;
|
||||
$datas[$buildID]->value = 0;
|
||||
}
|
||||
unset($datas[$buildIDList]);
|
||||
|
||||
$datas[$buildID]->value += $data->value;
|
||||
}
|
||||
|
||||
unset($datas[$buildIDList]);
|
||||
}
|
||||
|
||||
$this->app->loadLang('report');
|
||||
foreach($datas as $buildID => $data)
|
||||
/* 获取最后一次查询的所属产品列表。*/
|
||||
/* Get products in the last query. */
|
||||
$products = $this->session->product;
|
||||
if($this->reportCondition() !== true)
|
||||
{
|
||||
$data->name = isset($builds[$buildID]) ? $builds[$buildID] : $this->lang->report->undefined;
|
||||
preg_match('/`product` IN \((?P<productIdList>.+)\)/', $this->reportCondition(), $matchs);
|
||||
if(!empty($matchs) && isset($matchs['productIdList'])) $products = str_replace('\'', '', $matchs['productIdList']);
|
||||
}
|
||||
|
||||
$builds = $this->loadModel('build')->getBuildPairs($products, $branch = 0, $params = 'hasdeleted');
|
||||
|
||||
$this->app->loadLang('report');
|
||||
foreach($datas as $buildID => $data) $data->name = zget($builds, $buildID, $this->lang->report->undefined);
|
||||
|
||||
ksort($datas);
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
|
||||
@@ -1599,23 +1599,19 @@ class bugTest
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取版本 bug 数量报表的测试用例。
|
||||
* Test get report data of bugs per build.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getDataOfBugsPerBuildTest()
|
||||
public function getDataOfBugsPerBuildTest(): array
|
||||
{
|
||||
$array = $this->objectModel->getDataOfBugsPerBuild();
|
||||
$datas = $this->objectModel->getDataOfBugsPerBuild();
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . "/test/lib/init.php"; su('admin');
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/bug.class.php';
|
||||
su('admin');
|
||||
|
||||
zdTable('bug')->config('build')->gen(10);
|
||||
zdTable('build')->gen(10);
|
||||
|
||||
/**
|
||||
|
||||
title=bugModel->getDataOfBugsPerBuild();
|
||||
timeout=0
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
获取主干bug数 >> 主干,291
|
||||
获取bug数 >> 未设定,3
|
||||
获取项目版本版本1bug数 >> 项目版本版本1,6
|
||||
- 获取主干 bug 数
|
||||
- 第trunk条的name属性 @主干
|
||||
- 第trunk条的value属性 @6
|
||||
|
||||
- 获取没关联影响版本的 bug 数
|
||||
- 第0条的name属性 @未设定
|
||||
- 第0条的value属性 @1
|
||||
|
||||
- 获取项目版本版本1 bug 数
|
||||
- 第1条的name属性 @项目版本版本1
|
||||
- 第1条的value属性 @2
|
||||
|
||||
- 获取项目版本版本2 bug 数
|
||||
- 第2条的name属性 @项目版本版本2
|
||||
- 第2条的value属性 @2
|
||||
|
||||
*/
|
||||
|
||||
$bug=new bugTest();
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('trunk:name,value') && e('主干,291'); // 获取主干bug数
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('0:name,value') && e('未设定,3'); // 获取bug数
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('1:name,value') && e('项目版本版本1,6'); // 获取项目版本版本1bug数
|
||||
$bug = new bugTest();
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('trunk:name,value') && e('主干,6'); // 获取主干 bug 数
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('0:name,value') && e('未设定,1'); // 获取没关联影响版本的 bug 数
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('1:name,value') && e('项目版本版本1,2'); // 获取项目版本版本1 bug 数
|
||||
r($bug->getDataOfBugsPerBuildTest()) && p('2:name,value') && e('项目版本版本2,2'); // 获取项目版本版本2 bug 数
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: zt_bug
|
||||
author: Tingting Dai
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: openedBuild
|
||||
fields:
|
||||
- field: openedBuild1
|
||||
range: 0,1,1,2,trunk{6}
|
||||
- field: openedBuild2
|
||||
range: "[]{2},2,[]{7}"
|
||||
prefix: ","
|
||||
...
|
||||
Reference in New Issue
Block a user