From 9e11a39dfdee0b54fd0846b0996e288bb22241eb Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Thu, 11 May 2023 21:00:53 +0800 Subject: [PATCH] * Move create control code to zen, add two function: extractObjectFromExtras, buildCreateForm. --- module/bug/control.php | 83 +++--------------------------- module/bug/zen.php | 113 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 76 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index 3945be35ff..40fc8cdce9 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -189,6 +189,7 @@ class bug extends control public function create(string $productID, string $branch = '', string $extras = '') { $productID = (int)$productID; + if($branch === '') $branch = (int)$this->cookie->preBranch; $extras = str_replace(array(',', ' '), array('&', ''), $extras); parse_str($extras, $output); @@ -226,87 +227,19 @@ class bug extends control return $this->send($response); } - $this->bugZen->setMenu4Create($productID, $branch, $output); - $productID = $this->product->saveVisitState($productID, $this->products); $currentProduct = $this->product->getById($productID); - if($branch === '') $branch = (int)$this->cookie->preBranch; + $this->bugZen->setMenu4Create($productID, $branch, $output); - /* Init bug tpl, give tpl as many variables as possible, except for extract variables */ - $bug = $this->bugZen->initBug(); - - /* Set bug productID,branch,title,assignedTo, and handle copy bug, from runID,caseID,resultID, from testtask, from todo. */ + /* Init bug tpl, give bug as many variables as possible, except for extract variables */ $fields = array('productID' => $productID, 'branch' => $branch, 'title' => ($from == 'sonarqube' ? $_COOKIE['sonarqubeIssue'] : ''), 'assignedTo' => (isset($currentProduct->QD) ? $currentProduct->QD : '')); - $bug = $this->bugZen->updateBug($bug, $fields); + $bug = $this->bugZen->initBug($fields); - if(isset($runID) and $runID and isset($resultID) and $resultID) - { - $fields = $this->bug->getBugInfoFromResult($resultID, 0, 0, isset($stepIdList) ? $stepIdList : '');// If set runID and resultID, get the result info by resultID as template. - $bug = $this->bugZen->updateBug($bug, $fields); - } - if(isset($runID) and !$runID and isset($caseID) and $caseID) - { - $fields = $this->bug->getBugInfoFromResult($resultID, $caseID, $version, isset($stepIdList) ? $stepIdList : '');// If not set runID but set caseID, get the result info by resultID and case info. - $bug = $this->bugZen->updateBug($bug, $fields); - } - if(isset($bugID) and $bugID) - { - $bugInfo = $this->bug->getById($bugID); + /* Handle copy bug, bug from case, testtask, todo. */ + $bug = $this->bugZen->extractObjectFromExtras($bug, $output); - $fields = array('projectID' => $bugInfo->project, 'moduleID' => $bugInfo->module, 'executionID' => $bugInfo->execution, 'productID' => $bugInfo->product, 'taskID' => $bugInfo->task, 'storyID' => $bugInfo->story, 'buildID' => $bugInfo->openedBuild, - 'caseID' => $bugInfo->case, 'title' => $bugInfo->title, 'steps' => $bugInfo->steps, 'severity' => $bugInfo->severity, 'type' => $bugInfo->type, 'assignedTo' => $bugInfo->assignedTo, 'deadline' => (helper::isZeroDate($bugInfo->deadline) ? '' : $bugInfo->deadline), - 'os' => $bugInfo->os, 'browser' => $bugInfo->browser, 'mailto' => $bugInfo->mailto, 'keywords' => $bugInfo->keywords, 'color' => $bugInfo->color, 'testtask' => $bugInfo->testtask, 'feedbackBy' => $bugInfo->feedbackBy, 'notifyEmail' => $bugInfo->notifyEmail, - 'pri' => ($bugInfo->pri == 0 ? 3 : $bugInfo->pri)); - - $bug = $this->bugZen->updateBug($bug, $fields); - } - if(isset($testtask) and $testtask) - { - $testtask = $this->loadModel('testtask')->getById($testtask); - $bug = $this->bugZen->updateBug($bug, array('buildID' => $testtask->build)); - } - if(isset($todoID) and $todoID) - { - $todo = $this->loadModel('todo')->getById($todoID); - $bug = $this->bugZen->updateBug($bug, array('title' => $todo->name, 'steps' => $todo->desc, 'pri' => $todo->pri)); - } - - $bug = $this->bugZen->getBranches4Create($bug, $currentProduct); - $bug = $this->bugZen->getBuildsAndStories4Create($bug); - - /* Get all project team members linked with this product. */ - $productMembers = $this->bugZen->getProductMembers4Create($bug); - $moduleOptionMenu = $this->tree->getOptionMenu($bug->productID, 'bug', 0, ($bug->branch === 'all' or !isset($bug->branches[$bug->branch])) ? 0 : $bug->branch); - if(empty($moduleOptionMenu)) return print(js::locate(helper::createLink('tree', 'browse', "productID={$bug->productID}&view=story"))); - - /* Get project. */ - if($bug->projectID) $bug = $this->bugZen->updateBugTemplete($bug, array('project' => $this->loadModel('project')->getByID($projectID))); - /* Get products and projects. */ - $bug = $this->bugZen->getProductsAndProjects4Create($bug); - /* Append projects. */ - $bug = $this->bugZen->appendProjects4Create($bug, (isset($bugID) ? $bugID : 0)); - /* Get project model. */ - $bug = $this->bugZen->getProjectModel4Create($bug); - /* Get executions. */ - $bug = $this->bugZen->getExecutions4Create($bug); - - $this->bugZen->extractBugTemplete($bug); - $this->view->title = isset($this->products[$bug->productID]) ? $this->products[$bug->productID] . $this->lang->colon . $this->lang->bug->create : $this->lang->bug->create; - $this->view->customFields = $this->bugZen->getCustomFields4Create(); - $this->view->showFields = $this->config->bug->custom->createFields; - - $this->view->gobackLink = (isset($output['from']) and $output['from'] == 'global') ? $this->createLink('bug', 'browse', "productID=$bug->productID") : ''; - $this->view->productName = isset($this->products[$bug->productID]) ? $this->products[$bug->productID] : ''; - $this->view->moduleOptionMenu = $moduleOptionMenu; - $this->view->projectExecutionPairs = $this->loadModel('project')->getProjectExecutionPairs(); - $this->view->releasedBuilds = $this->loadModel('release')->getReleasedBuilds($bug->productID, $bug->branch); - $this->view->resultFiles = (!empty($resultID) and !empty($stepIdList)) ? $this->loadModel('file')->getByObject('stepResult', $resultID, str_replace('_', ',', $stepIdList)) : array(); - $this->view->productMembers = $productMembers; - $this->view->product = $currentProduct; - $this->view->blockID = $this->bugZen->getBlockID4Create(); - $this->view->issueKey = $from == 'sonarqube' ? $output['sonarqubeID'] . ':' . $output['issueKey'] : ''; - - $this->display(); + /* Get branches, builds, stories, project, projects, executions, products, project model and build create form. */ + $this->bugZen->buildCreateForm($bug, $output, $from); } /** diff --git a/module/bug/zen.php b/module/bug/zen.php index 0a7c226016..bb61ceac53 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -652,9 +652,10 @@ class bugZen extends bug * 初始化一个默认的bug模板。 * Init a default bug templete. * + * @param array $fields * @return object */ - protected function initBug(): object + protected function initBug($fields): object { $bug = new stdclass(); $bug->projectID = 0; @@ -694,6 +695,8 @@ class bugZen extends bug $bug->builds = array(); $bug->branches = array(); + if(!empty($fields)) $bug = $this->updateBug($bug, $fields); + return $bug; } @@ -712,6 +715,114 @@ class bugZen extends bug return $bug; } + /** + * 解析extras,如果bug来源于某个对象(bug, case, testtask, todo),使用对象的一些属性对bug赋值。 + * Extract extras, if bug come from an object(bug, case, testtask, todo), get some value from object. + * + * @param object $bug + * @param array $output + * @return object + */ + protected function extractObjectFromExtras(object $bug, array $output): object + { + extract($output); + + /* Get title, steps, storyID, moduleID, version, executionID from case. */ + if(isset($runID) and $runID and isset($resultID) and $resultID) + { + $fields = $this->bug->getBugInfoFromResult($resultID, 0, 0, isset($stepIdList) ? $stepIdList : '');// If set runID and resultID, get the result info by resultID as template. + $bug = $this->updateBug($bug, $fields); + } + if(isset($runID) and !$runID and isset($caseID) and $caseID) + { + $fields = $this->bug->getBugInfoFromResult($resultID, $caseID, $version, isset($stepIdList) ? $stepIdList : '');// If not set runID but set caseID, get the result info by resultID and case info. + $bug = $this->updateBug($bug, $fields); + } + + /* Get projectID, moduleID, executionID, productID, taskID, storyID, buildID, caseID, title, steps, severity, type, assignedTo, deadline, os, browser, mailto, keywords, color, testtask, feedbackBy, notifyEmail, pri from case. */ + if(isset($bugID) and $bugID) + { + $bugInfo = $this->bug->getById((int)$bugID); + + $fields = array('projectID' => $bugInfo->project, 'moduleID' => $bugInfo->module, 'executionID' => $bugInfo->execution, 'productID' => $bugInfo->product, 'taskID' => $bugInfo->task, 'storyID' => $bugInfo->story, 'buildID' => $bugInfo->openedBuild, + 'caseID' => $bugInfo->case, 'title' => $bugInfo->title, 'steps' => $bugInfo->steps, 'severity' => $bugInfo->severity, 'type' => $bugInfo->type, 'assignedTo' => $bugInfo->assignedTo, 'deadline' => (helper::isZeroDate($bugInfo->deadline) ? '' : $bugInfo->deadline), + 'os' => $bugInfo->os, 'browser' => $bugInfo->browser, 'mailto' => $bugInfo->mailto, 'keywords' => $bugInfo->keywords, 'color' => $bugInfo->color, 'testtask' => $bugInfo->testtask, 'feedbackBy' => $bugInfo->feedbackBy, 'notifyEmail' => $bugInfo->notifyEmail, + 'pri' => ($bugInfo->pri == 0 ? 3 : $bugInfo->pri)); + + $bug = $this->updateBug($bug, $fields); + } + + /* Get buildID from testtask. */ + if(isset($testtask) and $testtask) + { + $testtask = $this->loadModel('testtask')->getById((int)$testtask); + $bug = $this->updateBug($bug, array('buildID' => $testtask->build)); + } + + /* Get title, steps, pri from todo. */ + if(isset($todoID) and $todoID) + { + $todo = $this->loadModel('todo')->getById((int)$todoID); + $bug = $this->updateBug($bug, array('title' => $todo->name, 'steps' => $todo->desc, 'pri' => $todo->pri)); + } + + return $bug; + } + + /** + * + * 构建创建bug页面数据。 + * Build form fields for create bug. + * + * @param object $bug + * @param array $output + * @param string $from + * @return void + */ + protected function buildCreateForm(object $bug, array $output, string $from) + { + extract($output); + $currentProduct = $this->product->getById($bug->productID); + + /* Get branches, if moduleOptionMenu is empty, return. */ + $bug = $this->getBranches4Create($bug, $currentProduct); + $moduleOptionMenu = $this->tree->getOptionMenu($bug->productID, 'bug', 0, ($bug->branch === 'all' or !isset($bug->branches[$bug->branch])) ? 0 : $bug->branch); + /* TODO: 返回方式应该返回一个数组,暂时不知道怎么返回。 */ + if(empty($moduleOptionMenu)) return print(js::locate(helper::createLink('tree', 'browse', "productID={$bug->productID}&view=story"))); + + /* Get builds and stroies. */ + $bug = $this->getBuildsAndStories4Create($bug); + /* Get project,. */ + if($bug->projectID) $bug = $this->updateBug($bug, array('project' => $this->loadModel('project')->getByID($projectID))); + /* Get products and projects. */ + $bug = $this->getProductsAndProjects4Create($bug); + /* Append projects. */ + $bug = $this->appendProjects4Create($bug, (isset($bugID) ? $bugID : 0)); + /* Get project model. */ + $bug = $this->getProjectModel4Create($bug); + /* Get executions. */ + $bug = $this->getExecutions4Create($bug); + + $this->extractBugTemplete($bug); + + $this->view->title = isset($this->products[$bug->productID]) ? $this->products[$bug->productID] . $this->lang->colon . $this->lang->bug->create : $this->lang->bug->create; + $this->view->customFields = $this->getCustomFields4Create(); + $this->view->showFields = $this->config->bug->custom->createFields; + + $this->view->productMembers = $this->getProductMembers4Create($bug); + $this->view->gobackLink = (isset($output['from']) and $output['from'] == 'global') ? $this->createLink('bug', 'browse', "productID=$bug->productID") : ''; + $this->view->productName = isset($this->products[$bug->productID]) ? $this->products[$bug->productID] : ''; + $this->view->moduleOptionMenu = $moduleOptionMenu; + $this->view->projectExecutionPairs = $this->loadModel('project')->getProjectExecutionPairs(); + $this->view->releasedBuilds = $this->loadModel('release')->getReleasedBuilds($bug->productID, $bug->branch); + $this->view->resultFiles = (!empty($resultID) and !empty($stepIdList)) ? $this->loadModel('file')->getByObject('stepResult', $resultID, str_replace('_', ',', $stepIdList)) : array(); + $this->view->product = $currentProduct; + $this->view->blockID = $this->getBlockID4Create(); + $this->view->issueKey = $from == 'sonarqube' ? $output['sonarqubeID'] . ':' . $output['issueKey'] : ''; + + $this->display(); + } + /** * 将$bug对象的属性添加到view对象中。 * Add the prop of the $butTpl object to the view object