Modify responseAfterCreate function.
This commit is contained in:
songchenxuan
2023-05-11 07:53:58 +00:00
committed by qixinzhi
parent 2853b8801b
commit 58c5c54df3
3 changed files with 27 additions and 66 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ $config->bug->form->create['module'] = array('required' => false, 'type' =>
$config->bug->form->create['project'] = array('required' => false, 'type' => 'int', 'default' => 0);
$config->bug->form->create['execution'] = array('required' => false, 'type' => 'int', 'default' => 0);
$config->bug->form->create['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->bug->form->create['deadline'] = array('required' => false, 'type' => 'date', 'default' => '');
$config->bug->form->create['deadline'] = array('required' => false, 'type' => 'date', 'default' => null);
$config->bug->form->create['feedbackBy'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->bug->form->create['notifyEmail'] = array('required' => false, 'type' => 'string', 'default' => '');
$config->bug->form->create['type'] = array('required' => false, 'type' => 'string', 'default' => '');
+3 -16
View File
@@ -337,8 +337,6 @@ class bug extends control
if(!empty($_POST))
{
$response['result'] = 'success';
$data = form::data($this->config->bug->form->create);
$bug = $this->bugZen->prepareCreateExtras($data, $this->post->uid);
@@ -349,7 +347,7 @@ class bug extends control
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
/* Set from param if there is a object to transfer bug. */
setcookie('lastBugModule', (int)$formData->data->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true);
setcookie('lastBugModule', (int)$data->data->module, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true);
$bug = $this->bug->getByID($bugID);
@@ -362,19 +360,8 @@ class bug extends control
$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())
{
$response = $this->getOnlyBodyRes4Create($formData, $output);
return $this->send($response);
}
$location = $this->bugZen->getLocation4Create($formData, $output, $bugID, $branch);
$response = array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $location);
$executionID = $bug->execution ? $bug->execution : zget($output, 'executionID', $this->session->execution);
$response = $this->bugZen->responseAfterCreate($bugID, (int)$executionID, $output);
return $this->send($response);
}
+23 -49
View File
@@ -14,13 +14,13 @@ class bugZen extends bug
protected function prepareCreateExtras(object $data, string $uid): object
{
$now = helper::now();
$bug = $formData->setDefault('openedBy', $this->app->user->account)
$bug = $data->setDefault('openedBy', $this->app->user->account)
->setDefault('openedDate', $now)
->setIF($this->lang->navGroup->bug != 'qa', 'project', $this->session->project)
->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)
->setIF($data->data->assignedTo != '', 'assignedDate', $now)
->setIF($data->data->story != false, 'storyVersion', $this->loadModel('story')->getVersion($data->data->story))
->setIF(strpos($this->config->bug->create->requiredFields, 'deadline') !== false, 'deadline', $data->data->deadline)
->setIF(strpos($this->config->bug->create->requiredFields, 'execution') !== false, 'execution', $data->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')
@@ -327,64 +327,39 @@ class bugZen extends bug
}
/**
* 获得create方法的发生错误时的返回。
* Get response for create function when error happened.
* 获得create方法的response。
* Get response for create.
*
* @param array $bugResult
* @param array $response
* @param int $bugID
* @param int $executionID
* @param array $output
* @return array
*/
protected function getErrorRes4Create(array $bugResult): array
protected function responseAfterCreate(int $bugID, int $executionID, array $output): array
{
$hasError = false;
$response = array();
/* Return bug id when call the API. */
if($this->viewType == 'json') return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $bugID);
if(defined('RUN_MODE') && RUN_MODE == 'api') return array('status' => 'success', 'data' => $bugID);
if(!$bugResult or dao::isError())
{
$hasError = true;
$response['result'] = 'fail';
$response['message'] = dao::getError();
}
if(isonlybody()) return $this->responseInModal($executionID);
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;
$this->responseInModal($executionID);
$location = $this->getLocation4Create($bugID, $executionID, $output);
return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $location);
}
/**
* 获得create方法的返回url。
* Get response url for create.
*
* @param object $formData
* @param array $output
* @param int $bugID
* @param int $executionID
* @param string $branch
* @return string
*/
protected function getLocation4Create(object $formData, array $output, int $bugID, string $branch): string
protected function getLocation4Create(int $bugID, int $executionID, array $output): string
{
$bug = $this->bug->getByID($bugID);
if($this->app->tab == 'execution')
{
if(!preg_match("/(m=|\/)execution(&f=|-)bug(&|-|\.)?/", $this->session->bugList))
@@ -393,8 +368,7 @@ class bugZen extends bug
}
else
{
$executionID = $formData->data->execution ? $formData->data->execution : zget($output, 'executionID', $this->session->execution);
$location = $this->createLink('execution', 'bug', "executionID=$executionID");
$location = $this->createLink('execution', 'bug', "executionID=$executionID");
}
}
@@ -405,7 +379,7 @@ class bugZen extends bug
else
{
setcookie('bugModule', '0', 0, $this->config->webRoot, '', $this->config->cookieSecure, true);
$location = $this->createLink('bug', 'browse', "productID={$formData->data->product}&branch=$branch&browseType=byModule&param={$formData->data->module}&orderBy=id_desc");
$location = $this->createLink('bug', 'browse', "productID={$bug->product}&branch=$bug->branch&browseType=byModule&param={$bug->module}&orderBy=id_desc");
}
if($this->app->getViewType() == 'xhtml') $location = $this->createLink('bug', 'view', "bugID=$bugID", 'html');