From dd4c3c1a34bf393e00d53a5dc615d11f3075e375 Mon Sep 17 00:00:00 2001 From: daitingting Date: Mon, 22 May 2023 08:02:25 +0000 Subject: [PATCH] * Refactor getBugs2Link function. --- module/bug/control.php | 8 ++-- module/bug/js/edit.js | 2 +- module/bug/model.php | 39 +++++++++---------- module/bug/test/model/getbugs2link.php | 54 ++++++++++++++++++++++++++ module/bug/zen.php | 2 +- 5 files changed, 78 insertions(+), 27 deletions(-) create mode 100755 module/bug/test/model/getbugs2link.php diff --git a/module/bug/control.php b/module/bug/control.php index 7c013b7073..8007baeabe 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1039,7 +1039,7 @@ class bug extends control * Link related bugs. * * @param int $bugID - * @param string $browseType + * @param bool $bySearch * @param string $excludeBugs * @param int $queryID * @param int $recTotal @@ -1048,7 +1048,7 @@ class bug extends control * @access public * @return void */ - public function linkBugs(int $bugID, string $browseType = '', string $excludeBugs = '', int $queryID = 0, int $recTotal = 0, int $recPerPage = 20, int $pageID = 1) + public function linkBugs(int $bugID, bool $bySearch = false, string $excludeBugs = '', int $queryID = 0, int $recTotal = 0, int $recPerPage = 20, int $pageID = 1) { $bug = $this->bug->getByID($bugID); @@ -1065,9 +1065,9 @@ class bug extends control $pager = new pager($recTotal, $recPerPage, $pageID); /* Assign. */ - $this->view->title = $this->lang->bug->linkBugs . "BUG #$bug->id $bug->title $this->lang->dash " . $this->products[$bug->product]; + $this->view->title = $this->lang->bug->linkBugs . "BUG #$bug->id $bug->title {$this->lang->dash} " . $this->products[$bug->product]; $this->view->bug = $bug; - $this->view->bugs2Link = $this->bug->getBugs2Link($bugID, $browseType, $queryID, $pager, $excludeBugs); + $this->view->bugs2Link = $this->bug->getBugs2Link($bugID, $bySearch, $excludeBugs, $queryID, $pager); $this->view->users = $this->user->getPairs('noletter'); $this->view->pager = $pager; $this->display(); diff --git a/module/bug/js/edit.js b/module/bug/js/edit.js index c827f33982..debf718695 100644 --- a/module/bug/js/edit.js +++ b/module/bug/js/edit.js @@ -34,7 +34,7 @@ $(function() bugIdList += $(this).val() + ','; }); - var link = createLink('bug', 'linkBugs', 'bugID=' + bugID + '&browseType=&excludeBugs=' + bugIdList, '', true); + var link = createLink('bug', 'linkBugs', 'bugID=' + bugID + '&bySearch=&excludeBugs=' + bugIdList, '', true); var modalTrigger = new $.zui.ModalTrigger({type: 'iframe', width: '95%', url: link}); modalTrigger.show(); diff --git a/module/bug/model.php b/module/bug/model.php index 06ac633a53..78b2cc753b 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1134,37 +1134,34 @@ class bugModel extends model } /** + * 获取可以关联的 bug 列表。 * Get bugs to link. * * @param int $bugID - * @param string $browseType + * @param bool $bySearch * @param int $queryID - * @param object $pager * @param string $excludeBugs + * @param object $pager * @access public * @return array */ - public function getBugs2Link($bugID, $browseType = 'bySearch', $queryID = 0, $pager = null, $excludeBugs = '') + public function getBugs2Link(int $bugID, bool $bySearch = false, string $excludeBugs = '', int $queryID = 0, object $pager = null): array { - $bug = $this->getById($bugID); - $bugIDList = $bug->id . ',' . $bug->linkBug . ',' . $excludeBugs; + $bug = $this->getByID($bugID); - if($browseType == 'bySearch') - { - return $this->bugTao->getBySearch((array)$bug->product, 'all', 0, $queryID, $bugIDList, 'id', $pager); - } - else - { - return $this->dao->select('*')->from(TABLE_BUG) - ->where('deleted')->eq('0') - ->andWhere('id')->notin($bugIDList) - ->andWhere('product')->eq($bug->product) - ->beginIF($bug->project)->andWhere('project')->eq($bug->project)->fi() - ->beginIF($bug->execution)->andWhere('execution')->eq($bug->execution)->fi() - ->orderBy('id desc') - ->page($pager) - ->fetchAll(); - } + $excludeBugs .= ",{$bug->id},{$bug->linkBug}"; + + if($bySearch) return $this->bugTao->getBySearch((array)$bug->product, $branch = 'all', $projectID = 0, $queryID, $excludeBugs, $orderBy = 'id desc', $pager); + + return $this->dao->select('*')->from(TABLE_BUG) + ->where('deleted')->eq('0') + ->andWhere('id')->notin($excludeBugs) + ->andWhere('product')->eq($bug->product) + ->beginIF($bug->project)->andWhere('project')->eq($bug->project)->fi() + ->beginIF($bug->execution)->andWhere('execution')->eq($bug->execution)->fi() + ->orderBy('id desc') + ->page($pager) + ->fetchAll(); } /** diff --git a/module/bug/test/model/getbugs2link.php b/module/bug/test/model/getbugs2link.php new file mode 100755 index 0000000000..81f3cc52ed --- /dev/null +++ b/module/bug/test/model/getbugs2link.php @@ -0,0 +1,54 @@ +#!/usr/bin/env php +getBugs2Link(); +timeout=0 +cid=1 + +- 获取和 bug1 相同产品下的 bug 列表,第一个 bug 的标题是 BUG9第0条的title属性 @BUG9 + +- 获取和 bug1 相同产品下并且不包含 bug9 的 bug 列表,第一个 bug 的标题是 BUG7第0条的title属性 @BUG7 + +- 搜索和 bug2 相同产品下的 bug 列表,第一个 bug 的标题是 BUG10第0条的title属性 @BUG10 + +- 搜索和 bug2 相同产品下并且不包含 bug4 的 bug 列表,第一个 bug 的标题是 BUG8第0条的title属性 @BUG8 + +*/ + +function initData() +{ + $bug = zdTable('bug'); + $bug->id->range('1-10'); + $bug->product->range('1,2'); + $bug->branch->range('0,1'); + $bug->project->range('0,2'); + $bug->execution->range('0,3'); + $bug->module->range('1,0'); + $bug->title->prefix("BUG")->range('1-10'); + $bug->status->range("resolved,active,closed"); + $bug->plan->range('1,0'); + $bug->assignedTo->range('admin'); + $bug->openedBy->range('admin'); + $bug->resolvedBy->range('admin'); + $bug->confirmed->range('0,1'); + $bug->resolution->range('postponed,fixed'); + $bug->openedBuild->range('trunk'); + $bug->gen(10); +} + +initData(); + +$bugIdList = array(1,2); +$bySearch = array(false, true); +$excludeBugs = array('', '9', '10'); + +global $tester; +$bug = $tester->loadModel('bug'); +r($bug->getBugs2Link($bugIdList[0], $bySearch[0], $excludeBugs[0])) && p('0:title') && e('BUG9'); //获取和 bug1 相同产品下的 bug 列表,第一个 bug 的标题是 BUG9 +r($bug->getBugs2Link($bugIdList[0], $bySearch[0], $excludeBugs[1])) && p('0:title') && e('BUG7'); //获取和 bug1 相同产品下并且不包含 bug9 的 bug 列表,第一个 bug 的标题是 BUG7 +r($bug->getBugs2Link($bugIdList[1], $bySearch[1], $excludeBugs[0])) && p('0:title') && e('BUG10'); //搜索和 bug2 相同产品下的 bug 列表,第一个 bug 的标题是 BUG10 +r($bug->getBugs2Link($bugIdList[1], $bySearch[1], $excludeBugs[2])) && p('0:title') && e('BUG8'); //搜索和 bug2 相同产品下并且不包含 bug4 的 bug 列表,第一个 bug 的标题是 BUG8 \ No newline at end of file diff --git a/module/bug/zen.php b/module/bug/zen.php index e4660c9275..4eaa184aa9 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -1966,7 +1966,7 @@ class bugZen extends bug } } - $actionURL = $this->createLink('bug', 'linkBugs', "bugID={$bug->id}&browseType=bySearch&excludeBugs={$excludeBugs}&queryID=myQueryID", '', true); + $actionURL = $this->createLink('bug', 'linkBugs', "bugID={$bug->id}&bySearch=true&excludeBugs={$excludeBugs}&queryID=myQueryID", '', true); $this->bug->buildSearchForm($bug->product, $this->products, $queryID, $actionURL); } }