From 5492d277983a604469b20ae76f8d46052ec09bd1 Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Mon, 22 Nov 2021 13:46:02 +0800 Subject: [PATCH] * Fix bug #16512. --- module/branch/model.php | 24 ++++++++++++++++++++++++ module/testcase/control.php | 10 +++++++++- module/testcase/view/batchedit.html.php | 6 +++--- module/tree/model.php | 21 ++++++++++++++++++--- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/module/branch/model.php b/module/branch/model.php index acd03d415e..1e717a78bb 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -468,4 +468,28 @@ class branchModel extends model if($branchID) $this->dao->update(TABLE_BRANCH)->set('`default`')->eq('1')->where('id')->eq($branchID)->exec(); } + + /** + * Get branches of product which linked project. + * + * @param int $projectID + * @param int $productID + * @access public + * @return array + */ + public function getPairsByProjectProduct($projectID, $productID) + { + $branches = $this->dao->select('branch,t2.name')->from(TABLE_PROJECTPRODUCT)->alias('t1') + ->leftJoin(TABLE_BRANCH)->alias('t2')->on('t1.branch=t2.id') + ->where('t1.project')->eq($projectID) + ->andWhere('t1.product')->eq($productID) + ->andWhere('t2.deleted')->eq('0') + ->fetchPairs('branch', 'name'); + + $projectProduct = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->andWhere('product')->eq($productID)->fetchAll('branch'); + + if(isset($projectProduct[BRANCH_MAIN])) $branches = array(BRANCH_MAIN => $this->lang->branch->main) + $branches; + + return $branches; + } } diff --git a/module/testcase/control.php b/module/testcase/control.php index d0ddd6611d..9211d28112 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -182,7 +182,7 @@ class testcase extends control } else { - $moduleTree = $this->tree->getTreeMenu($productID, $viewType = 'case', $startModuleID = 0, array('treeModel', 'createCaseLink'), '', $branch); + $moduleTree = $this->tree->getTreeMenu($productID, $viewType = 'case', $startModuleID = 0, array('treeModel', 'createCaseLink'), array('projectID' => $projectID, 'productID' => $productID), $branch); } $product = $this->product->getById($productID); @@ -880,6 +880,8 @@ class testcase extends control * Batch edit case. * * @param int $productID + * @param int $branch + * @param string $type * @access public * @return void */ @@ -940,6 +942,11 @@ class testcase extends control if($product->type != 'normal') { $branches = $this->loadModel('branch')->getPairs($productID); + + if($this->app->tab == 'project') + { + $branches = $this->loadModel('branch')->getPairsByProjectProduct($this->session->project, $productID); + } foreach($branches as $branchID => $branchName) $modules[$branchID] = $this->tree->getOptionMenu($productID, $viewType = 'case', 0, $branchID); } else @@ -951,6 +958,7 @@ class testcase extends control $this->view->modules = $modules; $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID=$productID"), $this->products[$productID]); $this->view->title = $product->name . $this->lang->colon . $this->lang->testcase->batchEdit; + $this->view->product = $product; } } else diff --git a/module/testcase/view/batchedit.html.php b/module/testcase/view/batchedit.html.php index 13ec07205a..84f1a6c293 100644 --- a/module/testcase/view/batchedit.html.php +++ b/module/testcase/view/batchedit.html.php @@ -72,11 +72,11 @@ if((!$productID and !$cases[$caseID]->lib) or $app->tab != 'qa') { $caseProductID = $cases[$caseID]->product; - $product = $products[$caseProductID]; - $branches = array('' => ''); + $product = isset($product) ? $product : $products[$caseProductID]; + $branches = isset($branches) ? $branches : array('' => ''); if($product->type != 'normal') { - $branches = isset($productBranches[$product->id]) ? $productBranches[$product->id] : array(); + $branches = isset($productBranches[$product->id]) ? $productBranches[$product->id] : $branches; foreach($branches as $branchID => $branchName) $branches[$branchID] = '/' . $product->name . '/' . $branchName; } diff --git a/module/tree/model.php b/module/tree/model.php index 08ac2bc94c..92d1c1ea43 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -387,7 +387,7 @@ class treeModel extends model { if($product->type != 'normal') $branches = array(BRANCH_MAIN => $this->lang->branch->main) + $this->loadModel('branch')->getPairs($rootID, 'noempty'); } - elseif($type == 'story' and $this->app->rawModule == 'projectstory') + elseif(($type == 'story' and $this->app->rawModule == 'projectstory') or ($type == 'case' and $this->app->tab == 'project')) { $projectID = zget($extra, 'projectID', 0); if($product->type != 'normal' and $projectID) @@ -721,7 +721,22 @@ class treeModel extends model /* If createdVersion <= 4.1, go to getTreeMenu(). */ $products = $this->loadModel('product')->getProductPairsByProject($rootID); - $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products)); + $branchGroups = $this->dao->select('t1.product as product,branch,t3.name')->from(TABLE_PROJECTPRODUCT)->alias('t1') + ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id') + ->leftJoin(TABLE_BRANCH)->alias('t3')->on('t1.branch=t3.id') + ->where('t1.project')->eq($rootID) + ->andWhere('t2.type')->ne('normal') + ->andWhere('t1.product')->in(array_keys($products)) + ->andWhere('t2.deleted')->eq('0') + ->fetchGroup('product', 'branch'); + + foreach($branchGroups as $productID => $branches) + { + foreach($branches as $branchID => $branchInfo) + { + $branchGroups[$productID][$branchID] = $branchID == BRANCH_MAIN ? $this->lang->branch->main : $branchInfo->name; + } + } /* createdVersion > 4.1. */ $menu = "