diff --git a/module/branch/control.php b/module/branch/control.php index 8ee38ee492..a7e98d6937 100644 --- a/module/branch/control.php +++ b/module/branch/control.php @@ -217,6 +217,8 @@ class branch extends control if(empty($product) or $product->type == 'normal') die(); $branches = $this->branch->getPairs($productID, $param); + + /* Remove unlinked branches of the project. */ if($projectID) { $projectProducts = $this->loadModel('project')->getBranchesByProject($projectID); diff --git a/module/execution/control.php b/module/execution/control.php index 487489c04b..145a068a2a 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -1275,25 +1275,17 @@ class execution extends control $productPlans = array(); if($copyExecutionID) { - $copyExecution = $this->dao->select('*')->from(TABLE_EXECUTION)->where('id')->eq($copyExecutionID)->fetch(); - $name = $copyExecution->name; - $code = $copyExecution->code; - $team = $copyExecution->team; - $acl = $copyExecution->acl; - $whitelist = $copyExecution->whitelist; - $projectID = $copyExecution->project; - $products = $this->execution->getProducts($copyExecutionID); - $branches = $this->project->getBranchesByProject($copyExecutionID); - $plans = $this->loadModel('productplan')->getGroupByProduct(array_keys($products)); - $projectProducts = $this->loadModel('project')->getBranchesByProject($projectID); - $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), 'noclosed'); - foreach($branchGroups as $productID => $branchPairs) - { - foreach($branchPairs as $branchID => $branchName) - { - if(!isset($projectProducts[$productID][$branchID])) unset($branchGroups[$productID][$branchID]); - } - } + $copyExecution = $this->dao->select('*')->from(TABLE_EXECUTION)->where('id')->eq($copyExecutionID)->fetch(); + $name = $copyExecution->name; + $code = $copyExecution->code; + $team = $copyExecution->team; + $acl = $copyExecution->acl; + $whitelist = $copyExecution->whitelist; + $projectID = $copyExecution->project; + $products = $this->execution->getProducts($copyExecutionID); + $branches = $this->project->getBranchesByProject($copyExecutionID); + $plans = $this->loadModel('productplan')->getGroupByProduct(array_keys($products)); + $branchGroups = $this->execution->getBranchByProduct(array_keys($products), $projectID); $linkedBranches = array(); foreach($products as $productID => $product) @@ -1401,7 +1393,7 @@ class execution extends control $this->view->whitelist = $whitelist; $this->view->copyExecutionID = $copyExecutionID; $this->view->branchGroups = isset($branchGroups) ? $branchGroups : $this->loadModel('branch')->getByProducts(array_keys($products), 'noclosed'); - $this->view->poUsers = $poUsers; + $this->view->poUsers = $poUsers; $this->view->pmUsers = $pmUsers; $this->view->qdUsers = $qdUsers; $this->view->rdUsers = $rdUsers; @@ -1502,15 +1494,7 @@ class execution extends control $branches = $this->project->getBranchesByProject($executionID); $plans = $this->productplan->getGroupByProduct(array_keys($linkedProducts)); $executionStories = $this->project->getStoriesByProject($executionID); - $projectProducts = $this->loadModel('project')->getBranchesByProject($execution->project); - $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($linkedProducts), 'noclosed'); - foreach($branchGroups as $productID => $branchPairs) - { - foreach($branchPairs as $branchID => $branchName) - { - if(!isset($projectProducts[$productID][$branchID])) unset($branchGroups[$productID][$branchID]); - } - } + $branchGroups = $this->execution->getByProducts(array_keys($linkedProducts), $execution->project); /* If the story of the product which linked the execution, you don't allow to remove the product. */ $unmodifiableProducts = array(); @@ -2292,15 +2276,7 @@ class execution extends control $linkedBranches = array(); $branches = $this->project->getBranchesByProject($executionID); $executionStories = $this->project->getStoriesByProject($executionID); - $projectProducts = $this->loadModel('project')->getBranchesByProject($execution->project); - $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($linkedProducts), 'noclosed'); - foreach($branchGroups as $productID => $branchPairs) - { - foreach($branchPairs as $branchID => $branchName) - { - if(!isset($projectProducts[$productID][$branchID])) unset($branchGroups[$productID][$branchID]); - } - } + $branchGroups = $this->execution->getBranchByProduct(array_keys($linkedProducts), $execution->project); /* If the story of the product which linked the execution, you don't allow to remove the product. */ $unmodifiableProducts = array(); diff --git a/module/execution/model.php b/module/execution/model.php index 1e7529bed9..54c37ce3e8 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1655,6 +1655,28 @@ class executionModel extends model return $query->fetchAll('id'); } + /** + * Get branch pairs by product id list. + * + * @param array $products + * @param int $projectID + * @access public + * @return array + */ + public function getBranchByProduct($products, $projectID) + { + $branchGroups = $this->loadModel('branch')->getByProducts($products, 'noclosed'); + $projectProducts = $this->loadModel('project')->getBranchesByProject($projectID); + foreach($branchGroups as $productID => $branchPairs) + { + foreach($branchPairs as $branchID => $branchName) + { + if(!isset($projectProducts[$productID][$branchID])) unset($branchGroups[$productID][$branchID]); + } + } + return $branchGroups; + } + /** * Get ordered executions. *