diff --git a/module/bug/control.php b/module/bug/control.php index 0eac61f486..4764c66222 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -320,129 +320,46 @@ class bug extends control $extras = str_replace(array(',', ' '), array('&', ''), $extras); parse_str($extras, $output); extract($output); - $this->bugZen->setMenu4Create($productID, $branch, $output); $from = isset($output['from']) ? $output['from'] : ''; if(!empty($_POST)) { - $response['result'] = 'success'; - $formData = form::data($this->config->bug->createform); $bug = $this->bugZen->beforeCreate($formData); $bugResult = $this->bugZen->doCreate($bug); + list($hasError, $response) = $this->getErrorRes4Create($bugResult); + if($hasError) return $this->send($response); + /* Set from param if there is a object to transfer bug. */ - setcookie('lastBugModule', (int)$this->formData->data->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); - if(!$bugResult or dao::isError()) - { - $response['result'] = 'fail'; - $response['message'] = dao::getError(); - return $this->send($response); - } + setcookie('lastBugModule', (int)$formData->data->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); + $bugID = $bugResult['id']; - if($bugResult['status'] == 'exists') - { - $response['message'] = sprintf($this->lang->duplicate, $this->lang->bug->common); - $response['locate'] = $this->createLink('bug', 'view', "bugID=$bugID"); - $response['id'] = $bugResult['id']; - return $this->send($response); - } - - $bug->id = $bugID; - $this->bugZen->afterCreate($bug, $formData, $extras); - - /* Record related action, for example FromSonarqube. */ - $createAction = $from == 'sonarqube' ? 'fromSonarqube' : 'Opened'; - $actionID = $this->action->create('bug', $bugID, $createAction); - - $extras = str_replace(array(',', ' '), array('&', ''), $extras); - parse_str($extras, $output); - extract($output); - if(isset($output['todoID'])) - { - $this->dao->update(TABLE_TODO)->set('status')->eq('done')->where('id')->eq($output['todoID'])->exec(); - $this->action->create('todo', $output['todoID'], 'finished', '', "BUG:$bugID"); - - if($this->config->edition == 'biz' || $this->config->edition == 'max') - { - $todo = $this->dao->select('type, idvalue')->from(TABLE_TODO)->where('id')->eq($output['todoID'])->fetch(); - if($todo->type == 'feedback' && $todo->idvalue) $this->loadModel('feedback')->updateStatus('todo', $todo->idvalue, 'done'); - } - } + $bug = $this->bug->getByID($bugID); + $this->bugZen->afterCreate($bug, $formData, $from, $output); + $this->bugZen->addAction4Create($bugID, $from, $output); $message = $this->executeHooks($bugID); if($message) $this->lang->saveSuccess = $message; /* Return bug id when call the API. */ if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $bugID)); + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'data' => $bugID)); /* If link from no head then reload. */ if(isonlybody()) { - $executionID = isset($output['executionID']) ? $output['executionID'] : $this->session->execution; - $executionID = $this->formData->data->execution ? $this->formData->data->execution : $executionID; - $execution = $this->loadModel('execution')->getByID($executionID); - if($this->app->tab == 'execution') - { - $execLaneType = $this->session->execLaneType ? $this->session->execLaneType : 'all'; - $execGroupBy = $this->session->execGroupBy ? $this->session->execGroupBy : 'default'; - - if($execution->type == 'kanban') - { - $rdSearchValue = $this->session->rdSearchValue ? $this->session->rdSearchValue : ''; - $kanbanData = $this->loadModel('kanban')->getRDKanban($executionID, $execLaneType, 'id_desc', 0, $execGroupBy, $rdSearchValue); - $kanbanData = json_encode($kanbanData); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "parent.updateKanban($kanbanData, 0)")); - } - else - { - $taskSearchValue = $this->session->taskSearchValue ? $this->session->taskSearchValue : ''; - $kanbanData = $this->loadModel('kanban')->getExecutionKanban($executionID, $execLaneType, $execGroupBy, $taskSearchValue); - $kanbanType = $execLaneType == 'all' ? 'bug' : key($kanbanData); - $kanbanData = $kanbanData[$kanbanType]; - $kanbanData = json_encode($kanbanData); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "parent.updateKanban(\"bug\", $kanbanData)")); - } - } - else - { - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'locate' => 'parent')); - } + $response = $this->getOnlyBodyRes4Create($formData, $output); + return $this->send($response); } - if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); - if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'data' => $bugID)); - - if($this->app->tab == 'execution') - { - if(!preg_match("/(m=|\/)execution(&f=|-)bug(&|-|\.)?/", $this->session->bugList)) - { - $location = $this->session->bugList; - } - else - { - $executionID = $this->formData->data->execution ? $this->formData->data->execution : zget($output, 'executionID', $this->session->execution); - $location = $this->createLink('execution', 'bug', "executionID=$executionID"); - } - - } - elseif($this->app->tab == 'project') - { - $location = $this->createLink('project', 'bug', "projectID=" . zget($output, 'projectID', $this->session->project)); - } - else - { - setcookie('bugModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); - $location = $this->createLink('bug', 'browse', "productID={$this->formData->data->product}&branch=$branch&browseType=byModule¶m={$this->formData->data->module}&orderBy=id_desc"); - } - if($this->app->getViewType() == 'xhtml') $location = $this->createLink('bug', 'view', "bugID=$bugID", 'html'); - $response['message'] = $this->lang->saveSuccess; - $response['locate'] = $location; + $location = $this->bugZen->getLocation4Create($formData, $output, $bugID, $branch); + $response = array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $location); return $this->send($response); } - $this->loadModel('project'); + $this->bugZen->setMenu4Create($productID, $branch, $output); $productID = $this->product->saveState($productID, $this->products); $currentProduct = $this->product->getById($productID); @@ -468,10 +385,10 @@ class bug extends control { $bug = $this->bug->getById($bugID); - $tplFields = array('executionID' => $bug->execution, 'moduleID' => $bug->module, 'taskID' => $bug->task, 'storyID' => $bug->story, 'buildID' => $bug->openedBuild, - 'severity' => $bug->severity, 'type' => $bug->type, 'assignedTo' => $bug->assignedTo, 'deadline' => (helper::isZeroDate($bug->deadline) ? '' : $bug->deadline), - 'color' => $bug->color, 'testtask' => $bug->testtask, 'feedbackBy' => $bug->feedbackBy, 'notifyEmail' => $bug->notifyEmail); - if($bugTpl->pri == 0) $tplFields['pri'] = '3'; + $tplFields = array('projectID' => $bug->project, 'moduleID' => $bug->module, 'executionID' => $bug->execution, 'productID' => $bug->product, 'taskID' => $bug->task, 'storyID' => $bug->story, 'buildID' => $bug->openedBuild, + 'caseID' => $bug->case, 'title' => $bug->title, 'steps' => $bug->steps, 'severity' => $bug->severity, 'type' => $bug->type, 'assignedTo' => $bug->assignedTo, 'deadline' => (helper::isZeroDate($bug->deadline) ? '' : $bug->deadline), + 'os' => $bug->os, 'browser' => $bug->browser, 'mailto' => $bug->mailto, 'keywords' => $bug->keywords, 'color' => $bug->color, 'testtask' => $bug->testtask, 'feedbackBy' => $bug->feedbackBy, 'notifyEmail' => $bug->notifyEmail, + 'pri' => ($bug->pri == 0 ? 3 : $bug->pri)); $bugTpl = $this->bugZen->updateBugTemplete($bugTpl, $tplFields); } @@ -490,7 +407,7 @@ class bug extends control $bugTpl = $this->bugZen->getBuildsAndStories4Create($bugTpl); /* Get all project team members linked with this product. */ - $productMembers = $this->bugZen->getBuildsAndStories4Create($bugTpl); + $productMembers = $this->bugZen->getProductMembers4Create($bugTpl); $moduleOptionMenu = $this->tree->getOptionMenu($bugTpl->productID, 'bug', 0, ($bugTpl->branch === 'all' or !isset($bugTpl->branches[$bugTpl->branch])) ? 0 : $bugTpl->branch); if(empty($moduleOptionMenu)) return print(js::locate(helper::createLink('tree', 'browse', "productID={$bugTpl->productID}&view=story"))); @@ -506,7 +423,7 @@ class bug extends control $bugTpl = $this->bugZen->getExecutions4Create($bugTpl); $this->bugZen->extractBugTemplete($bugTpl); - $this->view->title = isset($this->products[$productID]) ? $this->products[$productID] . $this->lang->colon . $this->lang->bug->create : $this->lang->bug->create; + $this->view->title = isset($this->products[$bugTpl->productID]) ? $this->products[$bugTpl->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; @@ -514,33 +431,12 @@ class bug extends control $this->view->productName = isset($this->products[$bugTpl->productID]) ? $this->products[$bugTpl->productID] : ''; $this->view->moduleOptionMenu = $moduleOptionMenu; $this->view->projectExecutionPairs = $this->loadModel('project')->getProjectExecutionPairs(); - $this->view->releasedBuilds = $this->loadModel('release')->getReleasedBuilds($productID, $branch); - + $this->view->releasedBuilds = $this->loadModel('release')->getReleasedBuilds($bugTpl->productID, $bugTpl->branch); $this->view->resultFiles = (!empty($resultID) and !empty($stepIdList)) ? $this->loadModel('file')->getByObject('stepResult', $resultID, str_replace('_', ',', $stepIdList)) : array(); - $this->view->version = $version; - $this->view->testtask = $testtask; - $this->view->bugTitle = $title; - $this->view->pri = $pri; - $this->view->steps = htmlSpecialString($steps); - $this->view->os = $os; - $this->view->browser = $browser; $this->view->productMembers = $productMembers; - $this->view->assignedTo = $assignedTo; - $this->view->deadline = $deadline; - $this->view->mailto = $mailto; - $this->view->keywords = $keywords; - $this->view->severity = $severity; - $this->view->type = $type; $this->view->product = $currentProduct; - $this->view->branch = $branch; - $this->view->branches = $branches; $this->view->blockID = $this->bugZen->getBlockID4Create(); - $this->view->color = $color; - $this->view->stepsRequired = strpos($this->config->bug->create->requiredFields, 'steps'); - $this->view->isStepsTemplate = $steps == $this->lang->bug->tplStep . $this->lang->bug->tplResult . $this->lang->bug->tplExpect ? true : false; $this->view->issueKey = $from == 'sonarqube' ? $output['sonarqubeID'] . ':' . $output['issueKey'] : ''; - $this->view->feedbackBy = $feedbackBy; - $this->view->notifyEmail = $notifyEmail; $this->display(); } diff --git a/module/bug/zen.php b/module/bug/zen.php index 8693f85892..5f07a31756 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -16,10 +16,10 @@ class bugZen extends bug $bug = $formData->setDefault('openedBy', $this->app->user->account) ->setDefault('openedDate', $now) ->setIF($this->lang->navGroup->bug != 'qa', 'project', $this->session->project) - ->setIF($this->formData->data->assignedTo != '', 'assignedDate', $now) - ->setIF($this->formData->data->story != false, 'storyVersion', $this->loadModel('story')->getVersion($this->formData->data->story)) - ->setIF(strpos($this->config->bug->create->requiredFields, 'deadline') !== false, 'deadline', $this->formData->data->deadline) - ->setIF(strpos($this->config->bug->create->requiredFields, 'execution') !== false, 'execution', $this->formData->data->execution) + ->setIF($formData->data->assignedTo != '', 'assignedDate', $now) + ->setIF($formData->data->story != false, 'storyVersion', $this->loadModel('story')->getVersion($formData->data->story)) + ->setIF(strpos($this->config->bug->create->requiredFields, 'deadline') !== false, 'deadline', $formData->data->deadline) + ->setIF(strpos($this->config->bug->create->requiredFields, 'execution') !== false, 'execution', $formData->data->execution) ->stripTags($this->config->bug->editor->create['id'], $this->config->allowedTags) ->cleanInt('product,execution,module,severity') ->remove('files,labels,uid,oldTaskID,contactListMenu,region,lane,ticket,deleteFiles,resultFiles') @@ -53,15 +53,13 @@ class bugZen extends bug * * @param object $bug * @param object $formData - * @param string $extra + * @param string $from + * @param array $output * @return void */ - protected function afterCreate(object $bug, object $formData, string $extras): void + protected function afterCreate(object $bug, object $formData, string $from, array $output): void { $bugID = $bug->id; - $extras = str_replace(array(',', ' '), array('&', ''), $extras); - parse_str($extras, $output); - $from = isset($output['from']) ? $output['from'] : ''; if(isset($formData->rawdata->resultFiles)) { @@ -102,6 +100,145 @@ class bugZen extends bug if($from && is_callable(array($this, $this->config->bug->fromObjects[$from]['callback']))) call_user_func(array($this, $this->config->bug->fromObjects[$from]['callback']), $bugID); } + /** + * 为create方法添加动态。 + * Add action for create function. + * + * @param int $bugID + * @param string $from + * @param array $output + * @return void + */ + protected function addAction4Create(int $bugID, string $from, array $output): void + { + $createAction = $from == 'sonarqube' ? 'fromSonarqube' : 'Opened'; + $actionID = $this->action->create('bug', $bugID, $createAction); + + if(isset($output['todoID'])) + { + $this->dao->update(TABLE_TODO)->set('status')->eq('done')->where('id')->eq($output['todoID'])->exec(); + $this->action->create('todo', $output['todoID'], 'finished', '', "BUG:$bugID"); + + if($this->config->edition == 'biz' || $this->config->edition == 'max') + { + $todo = $this->dao->select('type, idvalue')->from(TABLE_TODO)->where('id')->eq($output['todoID'])->fetch(); + if($todo->type == 'feedback' && $todo->idvalue) $this->loadModel('feedback')->updateStatus('todo', $todo->idvalue, 'done'); + } + } + } + + /** + * 获得create方法的发生错误时的返回。 + * Get response for create function when error happened. + * + * @param array $bugResult + * @param array $response + * @return array + */ + protected function getErrorRes4Create(array $bugResult): array + { + $hasError = false; + $response = array(); + + if(!$bugResult or dao::isError()) + { + $hasError = true; + $response['result'] = 'fail'; + $response['message'] = dao::getError(); + } + + if($bugResult['status'] == 'exists') + { + $hasError = true; + $bugID = $bugResult['id']; + $response['message'] = sprintf($this->lang->duplicate, $this->lang->bug->common); + $response['locate'] = $this->createLink('bug', 'view', "bugID=$bugID"); + $response['id'] = $bugID; + } + + return array($hasError, $response); + } + + /** + * 获得create方法的onlybody返回。 + * Get onlybody response for create. + * + * @param array $bugResult + * @param array $response + * @return array + */ + protected function getOnlyBodyRes4Create(object $formData, array $output): array + { + $executionID = isset($output['executionID']) ? $output['executionID'] : $this->session->execution; + $executionID = $formData->data->execution ? $formData->data->execution : $executionID; + $execution = $this->loadModel('execution')->getByID($executionID); + if($this->app->tab == 'execution') + { + $execLaneType = $this->session->execLaneType ? $this->session->execLaneType : 'all'; + $execGroupBy = $this->session->execGroupBy ? $this->session->execGroupBy : 'default'; + + if($execution->type == 'kanban') + { + $rdSearchValue = $this->session->rdSearchValue ? $this->session->rdSearchValue : ''; + $kanbanData = $this->loadModel('kanban')->getRDKanban($executionID, $execLaneType, 'id_desc', 0, $execGroupBy, $rdSearchValue); + $kanbanData = json_encode($kanbanData); + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "parent.updateKanban($kanbanData, 0)"); + } + else + { + $taskSearchValue = $this->session->taskSearchValue ? $this->session->taskSearchValue : ''; + $kanbanData = $this->loadModel('kanban')->getExecutionKanban($executionID, $execLaneType, $execGroupBy, $taskSearchValue); + $kanbanType = $execLaneType == 'all' ? 'bug' : key($kanbanData); + $kanbanData = $kanbanData[$kanbanType]; + $kanbanData = json_encode($kanbanData); + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "parent.updateKanban(\"bug\", $kanbanData)"); + } + } + else + { + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'locate' => 'parent'); + } + } + + /** + * 获得create方法的返回url。 + * Get response url for create. + * + * @param object $formData + * @param array $output + * @param int $bugID + * @param string $branch + * @return string + */ + protected function getLocation4Create(object $formData, array $output, int $bugID, string $branch): string + { + if($this->app->tab == 'execution') + { + if(!preg_match("/(m=|\/)execution(&f=|-)bug(&|-|\.)?/", $this->session->bugList)) + { + $location = $this->session->bugList; + } + else + { + $executionID = $formData->data->execution ? $formData->data->execution : zget($output, 'executionID', $this->session->execution); + $location = $this->createLink('execution', 'bug', "executionID=$executionID"); + } + + } + elseif($this->app->tab == 'project') + { + $location = $this->createLink('project', 'bug', "projectID=" . zget($output, 'projectID', $this->session->project)); + } + else + { + setcookie('bugModule', '0', 0, $this->config->webRoot, '', $this->config->cookieSecure, false); + $location = $this->createLink('bug', 'browse', "productID={$formData->data->product}&branch=$branch&browseType=byModule¶m={$formData->data->module}&orderBy=id_desc"); + } + if($this->app->getViewType() == 'xhtml') $location = $this->createLink('bug', 'view', "bugID=$bugID", 'html'); + + return $location; + } + /** * 初始化一个默认的bug模板。 * Init a default bug templete. @@ -175,26 +312,42 @@ class bugZen extends bug */ protected function extractBugTemplete(object $bugTpl): void { - $this->view->projectID = $bugTpl->projectID; - $this->view->moduleID = $bugTpl->moduleID; - $this->view->productID = $bugTpl->productID; - $this->view->products = $bugTpl->products; - $this->view->stories = $bugTpl->stories; - $this->view->projects = defined('TUTORIAL') ? $this->loadModel('tutorial')->getProjectPairs() : $bugTpl->projects; - $this->view->executions = defined('TUTORIAL') ? $this->loadModel('tutorial')->getExecutionPairs() : $bugTpl->executions; - $this->view->builds = $bugTpl->builds; - $this->view->execution = $bugTpl->execution; - $this->view->taskID = $bugTpl->taskID; - $this->view->storyID = $bugTpl->storyID; - $this->view->buildID = $bugTpl->buildID; - $this->view->caseID = $bugTpl->caseID; + $this->view->projectID = $bugTpl->projectID; + $this->view->moduleID = $bugTpl->moduleID; + $this->view->productID = $bugTpl->productID; + $this->view->products = $bugTpl->products; + $this->view->stories = $bugTpl->stories; + $this->view->projects = defined('TUTORIAL') ? $this->loadModel('tutorial')->getProjectPairs() : $bugTpl->projects; + $this->view->executions = defined('TUTORIAL') ? $this->loadModel('tutorial')->getExecutionPairs() : $bugTpl->executions; + $this->view->builds = $bugTpl->builds; + $this->view->execution = $bugTpl->execution; + $this->view->taskID = $bugTpl->taskID; + $this->view->storyID = $bugTpl->storyID; + $this->view->buildID = $bugTpl->buildID; + $this->view->caseID = $bugTpl->caseID; + $this->view->runID = $bugTpl->runID; + $this->view->version = $bugTpl->version; + $this->view->testtask = $bugTpl->testtask; + $this->view->bugTitle = $bugTpl->title; + $this->view->pri = $bugTpl->pri; + $this->view->steps = htmlSpecialString($bugTpl->steps); + $this->view->os = $bugTpl->os; + $this->view->browser = $bugTpl->browser; + $this->view->assignedTo = $bugTpl->assignedTo; + $this->view->deadline = $bugTpl->deadline; + $this->view->mailto = $bugTpl->mailto; + $this->view->keywords = $bugTpl->keywords; + $this->view->severity = $bugTpl->severity; + $this->view->type = $bugTpl->type; + $this->view->branch = $bugTpl->branch; + $this->view->branches = $bugTpl->branches; + $this->view->color = $bugTpl->color; + $this->view->feedbackBy = $bugTpl->feedbackBy; + $this->view->notifyEmail = $bugTpl->notifyEmail; - $this->view->runID = $runID; - $this->view->version = $version; - $this->view->runID = $runID; - $this->view->runID = $runID; - - $this->view->projectModel = $bugTpl->projectModel; + $this->view->projectModel = $bugTpl->projectModel; + $this->view->stepsRequired = strpos($this->config->bug->create->requiredFields, 'steps'); + $this->view->isStepsTemplate = $bugTpl->steps == $this->lang->bug->tplStep . $this->lang->bug->tplResult . $this->lang->bug->tplExpect ? true : false; } /**