* Fix code review.

This commit is contained in:
qixinzhi
2023-05-04 11:52:50 +00:00
2 changed files with 548 additions and 295 deletions
+64 -286
View File
@@ -320,7 +320,6 @@ 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'] : '';
@@ -332,335 +331,114 @@ class bug extends control
$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&param={$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);
}
/* Get product, then set menu. */
$this->bugZen->setMenu4Create($productID, $branch, $output);
$productID = $this->product->saveState($productID, $this->products);
$currentProduct = $this->product->getById($productID);
if($branch === '') $branch = (int)$this->cookie->preBranch;
/* Init vars. */
$projectID = 0;
$moduleID = 0;
$executionID = 0;
$taskID = 0;
$storyID = 0;
$buildID = 0;
$caseID = 0;
$runID = 0;
$testtask = 0;
$version = 0;
$title = $from == 'sonarqube' ? $_COOKIE['sonarqubeIssue'] : '';
$steps = $this->lang->bug->tplStep . $this->lang->bug->tplResult . $this->lang->bug->tplExpect;
$os = '';
$browser = '';
$assignedTo = isset($currentProduct->QD) ? $currentProduct->QD : '';
$deadline = '';
$mailto = '';
$keywords = '';
$severity = 3;
$type = 'codeerror';
$pri = 3;
$color = '';
$feedbackBy = '';
$notifyEmail = '';
/* Init bug tpl, give tpl as many variables as possible, except for extract variables */
$bugTpl = $this->bugZen->initBugTemplete();
if($runID and $resultID) extract($this->bug->getBugInfoFromResult($resultID, 0, 0, isset($stepIdList) ? $stepIdList : ''));// If set runID and resultID, get the result info by resultID as template.
if(!$runID and $caseID) extract($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.
/* If bugID setted, use this bug as template. */
if(isset($bugID))
/* Set bug productID,branch,title,assignedTo, and handle copy bug, from runID,caseID,resultID, from testtask, from todo. */
$tplFields = array('productID' => $productID, 'branch' => $branch, 'title' => ($from == 'sonarqube' ? $_COOKIE['sonarqubeIssue'] : ''), 'assignedTo' => (isset($currentProduct->QD) ? $currentProduct->QD : ''));
$bugTpl = $this->bugZen->updateBugTemplete($bugTpl, $tplFields);
if(isset($runID) and $runID and isset($resultID) and $resultID)
{
$tplFields = $this->bug->getBugInfoFromResult($resultID, 0, 0, isset($stepIdList) ? $stepIdList : '');// If set runID and resultID, get the result info by resultID as template.
$bugTpl = $this->bugZen->updateBugTemplete($bugTpl, $tplFields);
}
if(isset($runID) and !$runID and isset($caseID) and $caseID)
{
$tplFields = $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.
$bugTpl = $this->bugZen->updateBugTemplete($bugTpl, $tplFields);
}
if(isset($bugID) and $bugID)
{
$bug = $this->bug->getById($bugID);
extract((array)$bug);
$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($pri == 0) $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));
if($testtask)
$bugTpl = $this->bugZen->updateBugTemplete($bugTpl, $tplFields);
}
if(isset($testtask) and $testtask)
{
$testtask = $this->loadModel('testtask')->getById($testtask);
$buildID = $testtask->build;
$bugTpl = $this->bugZen->updateBugTemplete($bugTpl, array('buildID' => $testtask->build));
}
if(isset($todoID) and $todoID)
{
$todo = $this->loadModel('todo')->getById($todoID);
$bugTpl = $this->bugZen->updateBugTemplete($bugTpl, array('title' => $todo->name, 'steps' => $todo->desc, 'pri' => $todo->pri));
}
if(isset($todoID))
{
$todo = $this->loadModel('todo')->getById($todoID);
$title = $todo->name;
$steps = $todo->desc;
$pri = $todo->pri;
}
/* Get branches. */
if($this->app->tab == 'execution' or $this->app->tab == 'project')
{
$objectID = $this->app->tab == 'project' ? $projectID : $executionID;
$productBranches = $currentProduct->type != 'normal' ? $this->loadModel('execution')->getBranchByProduct($productID, $objectID, 'noclosed|withMain') : array();
$branches = isset($productBranches[$productID]) ? $productBranches[$productID] : array();
$branch = key($branches);
}
else
{
$branches = $currentProduct->type != 'normal' ? $this->loadModel('branch')->getPairs($productID, 'active') : array();
}
/* If executionID is setted, get builds and stories of this execution. */
if($executionID)
{
$builds = $this->loadModel('build')->getBuildPairs($productID, $branch, 'noempty,noterminate,nodone,noreleased', $executionID, 'execution');
$stories = $this->story->getExecutionStoryPairs($executionID);
if(!$projectID) $projectID = $this->dao->select('project')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('project');
}
else
{
$moduleID = $moduleID ? $moduleID : 0;
$builds = $this->loadModel('build')->getBuildPairs($productID, $branch, 'noempty,noterminate,nodone,withbranch,noreleased');
$stories = $this->story->getProductStoryPairs($productID, $branch, $moduleID, 'all','id_desc', 0, 'full', 'story', false);
}
$moduleOwner = $this->bug->getModuleOwner($moduleID, $productID);
$bugTpl = $this->bugZen->getBranches4Create($bugTpl, $currentProduct);
$bugTpl = $this->bugZen->getBuildsAndStories4Create($bugTpl);
/* Get all project team members linked with this product. */
$productMembers = $this->bug->getProductMemberPairs($productID, $branch);
$productMembers = array_filter($productMembers);
if(empty($productMembers)) $productMembers = $this->view->users;
$moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'bug', $startModuleID = 0, ($branch === 'all' or !isset($branches[$branch])) ? 0 : $branch);
if(empty($moduleOptionMenu)) return print(js::locate(helper::createLink('tree', 'browse', "productID=$productID&view=story")));
$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")));
/* Get project. */
if($bugTpl->projectID) $bugTpl = $this->bugZen->updateBugTemplete($bugTpl, array('project' => $this->loadModel('project')->getByID($projectID)));
/* Get products and projects. */
$products = $this->config->CRProduct ? $this->products : $this->product->getPairs('noclosed', 0, '', 'all');
$projects = array(0 => '');
if($executionID)
{
$products = array();
$linkedProducts = $this->loadModel('product')->getProducts($executionID);
foreach($linkedProducts as $product) $products[$product->id] = $product->name;
}
elseif($projectID)
{
$products = array();
$productList = $this->config->CRProduct ? $this->product->getOrderedProducts('all', 40, $projectID) : $this->product->getOrderedProducts('normal', 40, $projectID);
foreach($productList as $product) $products[$product->id] = $product->name;
/* Set project menu. */
if($this->app->tab == 'project') $this->project->setMenu($projectID);
}
else
{
$projects += $this->product->getProjectPairsByProduct($productID, $branch);
}
$projectModel = '';
if($projectID)
{
$project = $this->loadModel('project')->getByID($projectID);
if($project)
{
if(empty($bugID) or $this->app->tab != 'qa') $projects += array($projectID => $project->name);
/* Replace language. */
if(!empty($project->model) and $project->model == 'waterfall') $this->lang->bug->execution = str_replace($this->lang->executionCommon, $this->lang->project->stage, $this->lang->bug->execution);
$projectModel = $project->model;
if(!$project->multiple) $executionID = $this->loadModel('execution')->getNoMultipleID($projectID);
}
}
/* Link all projects to product when copying bug under qa.*/
if(!empty($bugID) and $this->app->tab == 'qa') $projects += $this->product->getProjectPairsByProduct($productID, $branch);
/* Get block id of assinge to me. */
$blockID = 0;
if(isonlybody())
{
$blockID = $this->dao->select('id')->from(TABLE_BLOCK)
->where('block')->eq('assingtome')
->andWhere('module')->eq('my')
->andWhere('account')->eq($this->app->user->account)
->orderBy('order_desc')
->fetch('id');
}
$bugTpl = $this->bugZen->getProductsAndProjects4Create($bugTpl);
/* Append projects. */
$bugTpl = $this->bugZen->appendProjects4Create($bugTpl, (isset($bugID) ? $bugID : 0));
/* Get project model. */
$bugTpl = $this->bugZen->getProjectModel4Create($bugTpl);
/* Get executions. */
$executions = array(0 => '');
if(isset($projects[$projectID])) $executions += $this->product->getExecutionPairsByProduct($productID, $branch ? "0,$branch" : 0, 'id_desc', $projectID, !$projectID ? 'multiple|stagefilter' : 'stagefilter');
$execution = $executionID ? $this->loadModel('execution')->getByID($executionID) : '';
$executions = isset($executions[$executionID]) ? $executions : $executions + array($executionID => $execution->name);
$bugTpl = $this->bugZen->getExecutions4Create($bugTpl);
/* Set custom. */
foreach(explode(',', $this->config->bug->list->customCreateFields) as $field) $customFields[$field] = $this->lang->bug->$field;
$this->view->title = isset($this->products[$productID]) ? $this->products[$productID] . $this->lang->colon . $this->lang->bug->create : $this->lang->bug->create;
$this->view->customFields = $customFields;
$this->bugZen->extractBugTemplete($bugTpl);
$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;
$this->view->gobackLink = (isset($output['from']) and $output['from'] == 'global') ? $this->createLink('bug', 'browse', "productID=$productID") : '';
$this->view->products = $products;
$this->view->productID = $productID;
$this->view->productName = isset($this->products[$productID]) ? $this->products[$productID] : '';
$this->view->gobackLink = (isset($output['from']) and $output['from'] == 'global') ? $this->createLink('bug', 'browse', "productID=$bugTpl->productID") : '';
$this->view->productName = isset($this->products[$bugTpl->productID]) ? $this->products[$bugTpl->productID] : '';
$this->view->moduleOptionMenu = $moduleOptionMenu;
$this->view->stories = $stories;
$this->view->projects = defined('TUTORIAL') ? $this->loadModel('tutorial')->getProjectPairs() : $projects;
$this->view->projectExecutionPairs = $this->loadModel('project')->getProjectExecutionPairs();
$this->view->executions = defined('TUTORIAL') ? $this->loadModel('tutorial')->getExecutionPairs() : $executions;
$this->view->builds = $builds;
$this->view->releasedBuilds = $this->loadModel('release')->getReleasedBuilds($productID, $branch);
$this->view->moduleID = (int)$moduleID;
$this->view->projectID = $projectID;
$this->view->projectModel = $projectModel;
$this->view->execution = $execution;
$this->view->taskID = $taskID;
$this->view->storyID = $storyID;
$this->view->buildID = $buildID;
$this->view->caseID = $caseID;
$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->runID = $runID;
$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 = $blockID;
$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->blockID = $this->bugZen->getBlockID4Create();
$this->view->issueKey = $from == 'sonarqube' ? $output['sonarqubeID'] . ':' . $output['issueKey'] : '';
$this->view->feedbackBy = $feedbackBy;
$this->view->notifyEmail = $notifyEmail;
$this->display();
}
+484 -9
View File
@@ -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)
{
$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,483 @@ 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)
{
$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&param={$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.
*
* @return object
*/
protected function initBugTemplete(): object
{
$bugTpl = new stdclass();
$bugTpl->projectID = 0;
$bugTpl->moduleID = 0;
$bugTpl->executionID = 0;
$bugTpl->productID = 0;
$bugTpl->taskID = 0;
$bugTpl->storyID = 0;
$bugTpl->buildID = 0;
$bugTpl->caseID = 0;
$bugTpl->runID = 0;
$bugTpl->testtask = 0;
$bugTpl->version = 0;
$bugTpl->title = '';
$bugTpl->steps = $this->lang->bug->tplStep . $this->lang->bug->tplResult . $this->lang->bug->tplExpect;
$bugTpl->os = '';
$bugTpl->browser = '';
$bugTpl->assignedTo = '';
$bugTpl->deadline = '';
$bugTpl->mailto = '';
$bugTpl->keywords = '';
$bugTpl->severity = 3;
$bugTpl->type = 'codeerror';
$bugTpl->pri = 3;
$bugTpl->color = '';
$bugTpl->feedbackBy = '';
$bugTpl->notifyEmail = '';
$bugTpl->project = '';
$bugTpl->branch = '';
$bugTpl->execution = '';
$bugTpl->projectModel = '';
$bugTpl->projects = array();
$bugTpl->executions = array();
$bugTpl->products = array();
$bugTpl->stories = array();
$bugTpl->builds = array();
$bugTpl->branches = array();
return $bugTpl;
}
/**
* 更新bug模板。
* Update bug templete.
*
* @param object $bugTpl
* @param array $fields
* @return object
*/
protected function updateBugTemplete(object $bugTpl, array $fields): object
{
foreach($fields as $field => $value) $bugTpl->$field = $value;
return $bugTpl;
}
/**
* 将$bugTpl对象的属性添加到view对象中。
* Add the prop of the $butTpl object to the view object
*
* @param object $bugTpl
* @return void
*/
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->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->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;
}
/**
* 获取bug创建页面的branches和branch,并绑定到bugTpl上。
* Get the branches and branch for the bug create page and bind them to bugTpl.
*
* @param object $bugTpl
* @param object $currentProduct
* @return object
*/
protected function getBranches4Create(object $bugTpl, object $currentProduct): object
{
$productID = $bugTpl->productID;
$branch = $bugTpl->branch;
if($this->app->tab == 'execution' or $this->app->tab == 'project')
{
$objectID = $this->app->tab == 'project' ? $bugTpl->projectID : $bugTpl->executionID;
$productBranches = $currentProduct->type != 'normal' ? $this->loadModel('execution')->getBranchByProduct($productID, $objectID, 'noclosed|withMain') : array();
$branches = isset($productBranches[$productID]) ? $productBranches[$productID] : array();
$branch = key($branches);
}
else
{
$branches = $currentProduct->type != 'normal' ? $this->loadModel('branch')->getPairs($productID, 'active') : array();
}
return $this->updateBugTemplete($bugTpl, array('branches' => $branches, 'branch' => $branch));
}
/**
* 获取bug创建页面的builds和stories,并绑定到bugTpl上。
* Get the builds and stories for the bug create page and bind them to bugTpl.
*
* @param object $bugTpl
* @return object
*/
protected function getBuildsAndStories4Create(object $bugTpl): object
{
$this->loadModel('build');
$productID = $bugTpl->productID;
$branch = $bugTpl->branch;
$projectID = $bugTpl->projectID;
$executionID = $bugTpl->executionID;
$moduleID = $bugTpl->moduleID ? $bugTpl->moduleID : 0;
if($executionID)
{
$builds = $this->build->getBuildPairs($productID, $branch, 'noempty,noterminate,nodone,noreleased', $executionID, 'execution');
$stories = $this->story->getExecutionStoryPairs($executionID);
if(!$projectID) $projectID = $this->dao->select('project')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('project');
}
else
{
$builds = $this->build->getBuildPairs($productID, $branch, 'noempty,noterminate,nodone,withbranch,noreleased');
$stories = $this->story->getProductStoryPairs($productID, $branch, $moduleID, 'all','id_desc', 0, 'full', 'story', false);
}
return $this->updateBugTemplete($bugTpl, array('stories' => $stories, 'builds' => $builds));
}
/**
* 获取bug创建页面的产品成员。
* Get the product members for bug create page.
*
* @param object $bugTpl
* @return array
*/
protected function getProductMembers4Create(object $bugTpl): array
{
$productMembers = $this->bug->getProductMemberPairs($bugTpl->productID, $bugTpl->branch);
$productMembers = array_filter($productMembers);
if(empty($productMembers)) $productMembers = $this->view->users;
return $productMembers;
}
/**
* 获取bug创建页面的products和projects,并绑定到bugTpl上。
* Get the products and projects for the bug create page and bind them to bugTpl.
*
* @param object $bugTpl
* @return object
*/
protected function getProductsAndProjects4Create(object $bugTpl): object
{
$productID = $bugTpl->productID;
$branch = $bugTpl->branch;
$projectID = $bugTpl->projectID;
$executionID = $bugTpl->executionID;
$projects = array(0 => '');
$products = $this->config->CRProduct ? $this->products : $this->product->getPairs('noclosed', 0, '', 'all');
if($executionID)
{
$products = array();
$linkedProducts = $this->product->getProducts($executionID);
foreach($linkedProducts as $product) $products[$product->id] = $product->name;
}
elseif($projectID)
{
$products = array();
$productList = $this->config->CRProduct ? $this->product->getOrderedProducts('all', 40, $projectID) : $this->product->getOrderedProducts('normal', 40, $projectID);
foreach($productList as $product) $products[$product->id] = $product->name;
/* Set project menu. */
if($this->app->tab == 'project') $this->project->setMenu($projectID);
}
else
{
$projects += $this->product->getProjectPairsByProduct($productID, $branch);
}
return $this->updateBugTemplete($bugTpl, array('products' => $products, 'projects' => $projects));
}
/**
* 追加bug创建页面的products和projects,并绑定到bugTpl上。
* Append the products and projects for the bug create page and bind them to bugTpl.
*
* @param object $bugTpl
* @param int $bugID
* @return object
*/
protected function appendProjects4Create(object $bugTpl, int $bugID): object
{
$productID = $bugTpl->productID;
$branch = $bugTpl->branch;
$projects = $bugTpl->projects;
$projectID = $bugTpl->projectID;
$project = $bugTpl->project;
if($projectID and $project)
{
if(!$bugID or $this->app->tab != 'qa') $projects += array($projectID => $project->name);
}
/* Link all projects to product when copying bug under qa.*/
if($bugID and $this->app->tab == 'qa') $projects += $this->product->getProjectPairsByProduct($productID, $branch);
return $this->updateBugTemplete($bugTpl, array('projects' => $projects));
}
/**
* 获得项目的模式。
* Get project model.
*
* @param object $bugTpl
* @return object
*/
protected function getProjectModel4Create(object $bugTpl): object
{
$projectID = $bugTpl->projectID;
$executionID = $bugTpl->executionID;
$project = $bugTpl->project;
$projectModel = '';
if($projectID and $project)
{
if(!empty($project->model) and $project->model == 'waterfall') $this->lang->bug->execution = str_replace($this->lang->executionCommon, $this->lang->project->stage, $this->lang->bug->execution);
$projectModel = $project->model;
if(!$project->multiple) $executionID = $this->loadModel('execution')->getNoMultipleID($projectID);
}
return $this->updateBugTemplete($bugTpl, array('projectModel' => $projectModel, 'executionID' => $executionID));
}
/**
* 获得指派给我的blockID。
* Get block id of assigned to me.
*
* @return int
*/
protected function getBlockID4Create(): int
{
/* Get block id of assinge to me. */
if(!isonlybody()) return 0;
return $this->dao->select('id')->from(TABLE_BLOCK)
->where('block')->eq('assingtome')
->andWhere('module')->eq('my')
->andWhere('account')->eq($this->app->user->account)
->orderBy('order_desc')
->fetch('id');
}
/**
* 获得指派给我的blockID。
* Get block id of assigned to me.
*
* @return array
*/
protected function getCustomFields4Create(): array
{
$customFields = array();
foreach(explode(',', $this->config->bug->list->customCreateFields) as $field)
{
$customFields[$field] = $this->lang->bug->$field;
}
return $customFields;
}
/**
* 获得bug创建页面的products和projects,并绑定到bugTpl上。
* Get the executions and projects for the bug create page and bind them to bugTpl.
*
* @param object $bugTpl
* @return object
*/
protected function getExecutions4Create(object $bugTpl): object
{
$productID = $bugTpl->productID;
$branch = $bugTpl->branch;
$projectID = $bugTpl->projectID;
$executionID = $bugTpl->executionID;
$projects = $bugTpl->projects;
$executions = array(0 => '');
if(isset($projects[$projectID])) $executions += $this->product->getExecutionPairsByProduct($productID, $branch ? "0,$branch" : 0, 'id_desc', $projectID, !$projectID ? 'multiple|stagefilter' : 'stagefilter');
$execution = $executionID ? $this->loadModel('execution')->getByID($executionID) : '';
$executions = isset($executions[$executionID]) ? $executions : $executions + array($executionID => $execution->name);
return $this->updateBugTemplete($bugTpl, array('executions' => $executions, 'execution' => $execution));
}
/**
* 为创建bug设置导航数据。
* Set menu for create bug page.