From 1a591909925ccfbbd6d4af9863a07495f79cc3af Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Thu, 7 Apr 2022 17:09:41 +0800 Subject: [PATCH 1/2] * Fix bug#21550. --- module/branch/control.php | 5 +++-- module/branch/model.php | 8 ++++++-- module/execution/js/common.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/module/branch/control.php b/module/branch/control.php index 7ccc3db271..7398228c09 100644 --- a/module/branch/control.php +++ b/module/branch/control.php @@ -253,15 +253,16 @@ class branch extends control * @param int $oldBranch * @param string $param * @param int $projectID + * @param bool $addMainBranch * @access public * @return void */ - public function ajaxGetBranches($productID, $oldBranch = 0, $param = 'all', $projectID = 0) + public function ajaxGetBranches($productID, $oldBranch = 0, $param = 'all', $projectID = 0, $addMainBranch = true) { $product = $this->loadModel('product')->getById($productID); if(empty($product) or $product->type == 'normal') return; - $branches = $this->loadModel('branch')->getList($productID, $projectID, $param); + $branches = $this->loadModel('branch')->getList($productID, $projectID, $param, 'order', null, $addMainBranch); $branchOption = array(); $branchTagOption = array(); foreach($branches as $branchInfo) diff --git a/module/branch/model.php b/module/branch/model.php index ba2f199afb..aa74a37642 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -43,10 +43,11 @@ class branchModel extends model * @param string $browseType * @param string $orderBy * @param object $pager + * @param bool $addMainBranch * @access public * @return array */ - public function getList($productID, $executionID = 0, $browseType = 'active', $orderBy = 'order', $pager = null) + public function getList($productID, $executionID = 0, $browseType = 'active', $orderBy = 'order', $pager = null, $addMainBranch = true) { $executionBranches = array(); if($executionID) @@ -54,7 +55,8 @@ class branchModel extends model $executionBranches = $this->dao->select('branch')->from(TABLE_PROJECTPRODUCT) ->where('project')->eq($executionID) ->andWhere('product')->eq($productID) - ->fetchAll('branch'); + ->fetchPairs('branch'); + if(in_array(BRANCH_MAIN, $executionBranches)) $addMainBranch = true; if(empty($executionBranches)) return array(); } @@ -73,6 +75,8 @@ class branchModel extends model $defaultBranch = BRANCH_MAIN; foreach($branchList as $branch) $defaultBranch = $branch->default ? $branch->id : $defaultBranch; + if(!$addMainBranch) return $branchList; + /* Display the main branch under all and active page. */ $mainBranch = new stdclass(); $mainBranch->id = BRANCH_MAIN; diff --git a/module/execution/js/common.js b/module/execution/js/common.js index 8bb7171a8d..fd74c903dd 100644 --- a/module/execution/js/common.js +++ b/module/execution/js/common.js @@ -155,7 +155,7 @@ function loadBranches(product) var projectID = (typeof(systemMode) != 'undefined' && systemMode == 'new') ? $('#project').val() : 0; var index = $inputgroup.find('select:first').attr('id').replace('products' , ''); - $.get(createLink('branch', 'ajaxGetBranches', "productID=" + $(product).val() + "&oldBranch=0¶m=active&projectID=" + projectID), function(data) + $.get(createLink('branch', 'ajaxGetBranches', "productID=" + $(product).val() + "&oldBranch=0¶m=active&projectID=" + projectID + "&addMainBranch="), function(data) { if(data) { From 8aaaeafcb3b95bfde26c5ee3444133f6048d0306 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Thu, 7 Apr 2022 17:22:15 +0800 Subject: [PATCH 2/2] * Modify review code. --- module/branch/control.php | 6 +++--- module/branch/model.php | 8 ++++---- module/execution/js/common.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/module/branch/control.php b/module/branch/control.php index 7398228c09..f779ad5497 100644 --- a/module/branch/control.php +++ b/module/branch/control.php @@ -253,16 +253,16 @@ class branch extends control * @param int $oldBranch * @param string $param * @param int $projectID - * @param bool $addMainBranch + * @param bool $withMainBranch * @access public * @return void */ - public function ajaxGetBranches($productID, $oldBranch = 0, $param = 'all', $projectID = 0, $addMainBranch = true) + public function ajaxGetBranches($productID, $oldBranch = 0, $param = 'all', $projectID = 0, $withMainBranch = true) { $product = $this->loadModel('product')->getById($productID); if(empty($product) or $product->type == 'normal') return; - $branches = $this->loadModel('branch')->getList($productID, $projectID, $param, 'order', null, $addMainBranch); + $branches = $this->loadModel('branch')->getList($productID, $projectID, $param, 'order', null, $withMainBranch); $branchOption = array(); $branchTagOption = array(); foreach($branches as $branchInfo) diff --git a/module/branch/model.php b/module/branch/model.php index aa74a37642..9d60ac7372 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -43,11 +43,11 @@ class branchModel extends model * @param string $browseType * @param string $orderBy * @param object $pager - * @param bool $addMainBranch + * @param bool $withMainBranch * @access public * @return array */ - public function getList($productID, $executionID = 0, $browseType = 'active', $orderBy = 'order', $pager = null, $addMainBranch = true) + public function getList($productID, $executionID = 0, $browseType = 'active', $orderBy = 'order', $pager = null, $withMainBranch = true) { $executionBranches = array(); if($executionID) @@ -56,7 +56,7 @@ class branchModel extends model ->where('project')->eq($executionID) ->andWhere('product')->eq($productID) ->fetchPairs('branch'); - if(in_array(BRANCH_MAIN, $executionBranches)) $addMainBranch = true; + if(in_array(BRANCH_MAIN, $executionBranches)) $withMainBranch = true; if(empty($executionBranches)) return array(); } @@ -75,7 +75,7 @@ class branchModel extends model $defaultBranch = BRANCH_MAIN; foreach($branchList as $branch) $defaultBranch = $branch->default ? $branch->id : $defaultBranch; - if(!$addMainBranch) return $branchList; + if(!$withMainBranch) return $branchList; /* Display the main branch under all and active page. */ $mainBranch = new stdclass(); diff --git a/module/execution/js/common.js b/module/execution/js/common.js index fd74c903dd..95c24dca12 100644 --- a/module/execution/js/common.js +++ b/module/execution/js/common.js @@ -155,7 +155,7 @@ function loadBranches(product) var projectID = (typeof(systemMode) != 'undefined' && systemMode == 'new') ? $('#project').val() : 0; var index = $inputgroup.find('select:first').attr('id').replace('products' , ''); - $.get(createLink('branch', 'ajaxGetBranches', "productID=" + $(product).val() + "&oldBranch=0¶m=active&projectID=" + projectID + "&addMainBranch="), function(data) + $.get(createLink('branch', 'ajaxGetBranches', "productID=" + $(product).val() + "&oldBranch=0¶m=active&projectID=" + projectID + "&withMainBranch="), function(data) { if(data) {