From 74326a333103a5d83fdd3d461484f2a80ce60e53 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Tue, 1 Mar 2022 14:40:00 +0800 Subject: [PATCH] * Optimize the code. --- module/story/control.php | 30 ++++++++------ module/story/model.php | 53 ++++++++++++------------ module/story/view/batchedit.html.php | 16 +------- module/testcase/control.php | 54 ++++++++++++------------- module/testcase/view/batchedit.html.php | 47 +++------------------ module/testtask/control.php | 9 +++-- module/testtask/view/batchrun.html.php | 20 +-------- 7 files changed, 81 insertions(+), 148 deletions(-) diff --git a/module/story/control.php b/module/story/control.php index 95be333976..227242b916 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -718,17 +718,7 @@ class story extends control $this->story->replaceURLang($story->type); /* Process the module when branch products are switched to normal products. */ - if($product->type == 'normal' and !empty($story->branch)) - { - $storyModule = '/'; - $modulePath = $this->tree->getParents($story->module); - foreach($modulePath as $key => $module) - { - $storyModule .= $module->name; - if(isset($modulePath[$key + 1])) $storyModule .= '/'; - } - $this->view->moduleOptionMenu += array($story->module => $storyModule); - } + if($product->type == 'normal' and !empty($story->branch)) $this->view->moduleOptionMenu += $this->tree->getModulesName($story->module); $this->view->title = $this->lang->story->edit . "STORY" . $this->lang->colon . $this->view->story->title; $this->view->position[] = $this->lang->story->edit; @@ -877,8 +867,6 @@ class story extends control if($storyProduct->type != 'normal') $branchProduct = true; } } - $this->view->branchTagOption = $branchTagOption; - $this->view->modules = $modules; /* Set ditto option for users. */ $users = $this->loadModel('user')->getPairs('nodeleted'); @@ -902,6 +890,20 @@ class story extends control $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars); if($showSuhosinInfo) $this->view->suhosinInfo = extension_loaded('suhosin') ? sprintf($this->lang->suhosinInfo, $countInputVars) : sprintf($this->lang->maxVarsInfo, $countInputVars); + /* Append module when change product type. */ + $moduleList = array(0 => '/'); + foreach($stories as $story) + { + if(isset($modules[$story->product][$story->branch])) + { + $moduleList[$story->id] = $modules[$story->product][$story->branch]; + } + else + { + $moduleList[$story->id] = $modules[$story->product][0] + $this->tree->getModulesName($story->module); + } + } + $this->view->position[] = $this->lang->story->common; $this->view->position[] = $this->lang->story->batchEdit; $this->view->title = $this->lang->story->batchEdit; @@ -919,6 +921,8 @@ class story extends control $this->view->storyType = $storyType; $this->view->stories = $stories; $this->view->executionID = $executionID; + $this->view->branchTagOption = $branchTagOption; + $this->view->moduleList = $moduleList; $this->display(); } diff --git a/module/story/model.php b/module/story/model.php index 9c24455077..50b943ef82 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -2277,38 +2277,35 @@ class storyModel extends model $normalProducts[$product->id] = $product->id; } - if(!empty($normalProducts)) - { - $stories += $this->dao->select('*')->from(TABLE_STORY) - ->where('product')->in($normalProducts) - ->beginIF(!$hasParent)->andWhere("parent")->ge(0)->fi() - ->beginIF(!empty($moduleIdList))->andWhere('module')->in($moduleIdList)->fi() - ->beginIF(!empty($excludeStories))->andWhere('id')->notIN($excludeStories)->fi() - ->beginIF($status and $status != 'all')->andWhere('status')->in($status)->fi() - ->andWhere('type')->eq($type) - ->andWhere('deleted')->eq(0) - ->orderBy($orderBy) - ->page($pager) - ->fetchAll('id'); - } - + $productQuery = '('; + if(!empty($normalProducts)) $productQuery .= '`product` ' . helper::dbIN(array_keys($normalProducts)); if(!empty($branchProducts)) { - if(is_array($branch)) $branch = join(',', $branch); + if(!empty($normalProducts)) $productQuery .= " OR "; + $productQuery .= "(`product` " . helper::dbIN(array_keys($branchProducts)); - $stories += $this->dao->select('*')->from(TABLE_STORY) - ->where('product')->in($branchProducts) - ->beginIF(!$hasParent)->andWhere("parent")->ge(0)->fi() - ->beginIF($branch !== 'all')->andWhere("branch")->in($branch)->fi() - ->beginIF(!empty($moduleIdList))->andWhere('module')->in($moduleIdList)->fi() - ->beginIF(!empty($excludeStories))->andWhere('id')->notIN($excludeStories)->fi() - ->beginIF($status and $status != 'all')->andWhere('status')->in($status)->fi() - ->andWhere('type')->eq($type) - ->andWhere('deleted')->eq(0) - ->orderBy($orderBy) - ->page($pager) - ->fetchAll('id'); + if($branch !== 'all') + { + if(is_array($branch)) $branch = join(',', $branch); + $productQuery .= " AND `branch` " . helper::dbIN($branch); + } + $productQuery .= ')'; } + if(empty($normalProducts) and empty($branchProducts)) $productQuery .= '1 = 1'; + $productQuery .= ') '; + + $stories = $this->dao->select('*')->from(TABLE_STORY) + ->where('product')->in($productID) + ->andWhere($productQuery) + ->beginIF(!$hasParent)->andWhere("parent")->ge(0)->fi() + ->beginIF(!empty($moduleIdList))->andWhere('module')->in($moduleIdList)->fi() + ->beginIF(!empty($excludeStories))->andWhere('id')->notIN($excludeStories)->fi() + ->beginIF($status and $status != 'all')->andWhere('status')->in($status)->fi() + ->andWhere('type')->eq($type) + ->andWhere('deleted')->eq(0) + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); return $this->mergePlanTitle($productID, $stories, $branch, $type); } diff --git a/module/story/view/batchedit.html.php b/module/story/view/batchedit.html.php index 7ef476774b..68dc1de905 100644 --- a/module/story/view/batchedit.html.php +++ b/module/story/view/batchedit.html.php @@ -77,21 +77,7 @@ foreach(explode(',', $showFields) as $field) '> - product]; - if($products[$story->product]->type == 'normal' and !empty($story->branch)) - { - $storyModule = '/'; - $modulePath = $this->tree->getParents($story->module); - foreach($modulePath as $key => $module) - { - $storyModule .= $module->name; - if(isset($modulePath[$key + 1])) $storyModule .= '/'; - } - $moduleList[$story->branch] = $modules[$story->product][0] + array($story->module => $storyModule); - } - ?> - branch]) ? $moduleList[$story->branch] : array(0 => '/'), $story->module, "class='form-control chosen'");?> + id, array(0 => '/')), $story->module, "class='form-control chosen'");?> '> product][$story->branch]) ? array('' => '') + $plans[$story->product][$story->branch] : '', $story->plan, "class='form-control chosen'");?> diff --git a/module/testcase/control.php b/module/testcase/control.php index e34a74d96c..cd09abb4d3 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -875,17 +875,7 @@ class testcase extends control } } - if(!isset($moduleOptionMenu[$case->module])) - { - $caseModule = '/'; - $modulePath = $this->tree->getParents($case->module); - foreach($modulePath as $key => $module) - { - $caseModule .= $module->name; - if(isset($modulePath[$key + 1])) $caseModule .= '/'; - } - $moduleOptionMenu[$case->module] = $caseModule; - } + if(!isset($moduleOptionMenu[$case->module])) $moduleOptionMenu += $this->tree->getModulesName($case->module); /* Get product and branches. */ $product = $this->product->getById($productID); @@ -976,7 +966,6 @@ class testcase extends control /* Set modules. */ $modules[$productID][$branch] = $this->tree->getOptionMenu($libID, 'caselib', 0, $branch); - $this->view->modules = $modules; $this->view->title = $libraries[$libID] . $this->lang->colon . $this->lang->testcase->batchEdit; $this->view->position[] = html::a($this->createLink('caselib', 'browse', "libID=$libID"), $libraries[$libID]); } @@ -1008,8 +997,7 @@ class testcase extends control $modules[$productID][BRANCH_MAIN] = $this->tree->getOptionMenu($productID, 'case'); } - $this->view->branchTagOption = $branchTagOption; - $this->view->modules = $modules; + $this->view->branchTagOption = array($productID => $branchTagOption); $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; @@ -1037,31 +1025,27 @@ class testcase extends control $productIdList = array(); foreach($cases as $case) $productIdList[$case->product] = $case->product; - $products = $this->product->getByIdList($productIdList); + $branches = 0; + $branchTagOption = array(); + $products = $this->product->getByIdList($productIdList); foreach($products as $product) { if($product->type != 'normal') { + $branches = $this->loadModel('branch')->getList($product->id, 0, 'all'); + foreach($branches as $branchInfo) $branchTagOption[$product->id][$branchInfo->id] = '/' . $product->name . '/' . $branchInfo->name . ($branchInfo->status == 'closed' ? ' (' . $this->lang->branch->statusList['closed'] . ')' : ''); + $branches = array_keys($branches); $branchProduct = true; - break; } - } - if($this->app->tab == 'project') - { - $productBranches = $this->loadModel('execution')->getBranchByProduct(array_keys($products), $this->session->project, 'all'); - } - else - { - $productBranches = $this->loadModel('branch')->getByProducts(array_keys($products), 'ignoreNormal'); + $modulePairs = $this->tree->getOptionMenu($product->id, 'case', 0, $branches); + $modules[$product->id] = $product->type != 'normal' ? $modulePairs : array(0 => $modulePairs); } $this->view->products = $products; - $this->view->productBranches = $productBranches; + $this->view->branchTagOption = $branchTagOption; } - // if(!$this->testcase->forceNotReview()) unset($this->lang->testcase->statusList['wait']); /* Bug#1343 */ - /* Judge whether the editedCases is too large and set session. */ $countInputVars = count($cases) * (count(explode(',', $this->config->testcase->custom->batchEditFields)) + 3); $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars); @@ -1075,6 +1059,21 @@ class testcase extends control $this->view->customFields = $customFields; $this->view->showFields = $this->config->testcase->custom->batchEditFields; + /* Append module when change product type. */ + $modulePairs = array(0 => '/'); + foreach($cases as $case) + { + $caseProduct = $type == 'lib' ? $productID : $case->product; + if(isset($modules[$caseProduct][$case->branch])) + { + $modulePairs[$case->id] = $modules[$caseProduct][$case->branch]; + } + else + { + $modulePairs[$case->id] = $modules[$caseProduct][0] + $this->tree->getModulesName($case->module); + } + } + /* Assign. */ $this->view->position[] = $this->lang->testcase->common; $this->view->position[] = $this->lang->testcase->batchEdit; @@ -1085,6 +1084,7 @@ class testcase extends control $this->view->typeList = array('' => '', 'ditto' => $this->lang->testcase->ditto) + $this->lang->testcase->typeList; $this->view->cases = $cases; $this->view->forceNotReview = $this->testcase->forceNotReview(); + $this->view->modulePairs = $modulePairs; $this->display(); } diff --git a/module/testcase/view/batchedit.html.php b/module/testcase/view/batchedit.html.php index eb39ab9f5d..8917eb5884 100644 --- a/module/testcase/view/batchedit.html.php +++ b/module/testcase/view/batchedit.html.php @@ -66,44 +66,7 @@ - branch) ? $cases[$caseID]->branch : 0; - if(!$productID and !$cases[$caseID]->lib) - { - $caseProductID = $cases[$caseID]->product; - $product = $products[$caseProductID]; - $branchTagOption = array(); - if($product->type != 'normal') - { - $branches = $this->loadModel('branch')->getList($product->id, 0, 'all'); - foreach($branches as $branchInfo) - { - $branchTagOption[$branchInfo->id] = $branchInfo->name . ($branchInfo->status == 'closed' ? ' (' . $this->lang->branch->statusList['closed'] . ')' : ''); - } - foreach($branchTagOption as $branchID => $branchName) $branchTagOption[$branchID] = '/' . $product->name . '/' . $branchName; - - $modules[$caseProductID][$caseBranch] = $this->tree->getOptionMenu($cases[$caseID]->product, 'case', 0, $caseBranch); - } - else - { - $modules[$caseProductID][0] = $this->tree->getOptionMenu($cases[$caseID]->product, 'case'); - } - } - $caseProductID = isset($caseProductID) ? $caseProductID : $productID; - $moduleList = $modules[$caseProductID]; - if(!isset($moduleList[$caseBranch])) - { - $caseModule = '/'; - $modulePath = $this->tree->getParents($cases[$caseID]->module); - foreach($modulePath as $key => $module) - { - $caseModule .= $module->name; - if(isset($modulePath[$key + 1])) $caseModule .= '/'; - } - $moduleList[$caseBranch] = $modules[$caseProductID][0] + array($cases[$caseID]->module => $caseModule); - } - ?> + '> pri, 'class=form-control');?> @@ -122,12 +85,12 @@ - id;?> - type == 'normal') ? "disabled='disabled'" : '';?> - type == 'normal' ? '' : $cases[$caseID]->branch, "class='form-control chosen' onchange='loadBranches($branchProductID, this.value, $caseID)', $disabled");?> + product;?> + + branch : '', "class='form-control chosen' onchange='loadBranches($branchProductID, this.value, $caseID)', $disabled");?> - ' style='overflow:visible'>module, "class='form-control chosen' onchange='loadStories($productID, this.value, $caseID)'");?> + ' style='overflow:visible'> '/')), $cases[$caseID]->module, "class='form-control chosen' onchange='loadStories($productID, this.value, $caseID)'");?> ' style='overflow:visible'>story, "class='form-control chosen'");?>
diff --git a/module/testtask/control.php b/module/testtask/control.php index c63bef95ac..911ef8af1a 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -1246,7 +1246,6 @@ class testtask extends control { $this->loadModel('qa')->setMenu($this->products, $productID, $taskID); } - $this->view->moduleOptionMenu = $this->tree->getOptionMenu($productID, 'case', 0, 'all'); $cases = $this->dao->select('*')->from(TABLE_CASE)->where('id')->in($caseIDList)->fetchAll('id'); } @@ -1269,11 +1268,13 @@ class testtask extends control ->leftJoin(TABLE_TESTRUN)->alias('t2')->on('t1.id = t2.case') ->where('t2.id')->in($caseIDList) ->fetchAll('id'); - - $caseIDList = array(); - foreach($cases as $case) $caseIDList[] = $case->id; } + /* Set modules. */ + $moduleOptionMenu = array(0 => '/'); + foreach($cases as $case) $moduleOptionMenu += $this->tree->getModulesName($case->module); + $this->view->moduleOptionMenu = $moduleOptionMenu; + /* If case has changed and not confirmed, remove it. */ if($from == 'testtask') { diff --git a/module/testtask/view/batchrun.html.php b/module/testtask/view/batchrun.html.php index f0836aa3c3..13dab61fc0 100644 --- a/module/testtask/view/batchrun.html.php +++ b/module/testtask/view/batchrun.html.php @@ -28,27 +28,9 @@ testcase->stepDesc . '/' . $lang->testcase->stepExpect?> - $case):?> status == 'wait') continue;?> - id]", $caseID); - if(!isset($moduleOptionMenu[$case->module])) $moduleOptionMenu += $this->tree->getOptionMenu($case->product, 'case', 0, $case->branch); - } - if(!isset($moduleOptionMenu[$case->module])) - { - $caseModule = '/'; - $modulePath = $this->tree->getParents($cases[$caseID]->module); - foreach($modulePath as $key => $module) - { - $caseModule .= $module->name; - if(isset($modulePath[$key + 1])) $caseModule .= '/'; - } - $moduleOptionMenu[$case->module] = $caseModule; - } - ?> + id]", $caseID); ?> version)?> module] . "'>" . $moduleOptionMenu[$case->module] . ""?>