* Optimized the code for the bug create function.
This commit is contained in:
+21
-25
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
global $lang;
|
||||
global $lang, $app;
|
||||
|
||||
$config->bug->form = new stdclass();
|
||||
|
||||
$config->bug->form->create = array();
|
||||
$config->bug->form->create['title'] = array('required' => true, 'type' => 'string', 'filter' => 'trim');
|
||||
$config->bug->form->create['openedBuild'] = array('required' => true, 'type' => 'array', 'filter' => 'join');
|
||||
|
||||
$config->bug->form->create['title'] = array('required' => true, 'type' => 'string', 'filter' => 'trim');
|
||||
$config->bug->form->create['openedBuild'] = array('required' => true, 'type' => 'array', 'filter' => 'join');
|
||||
$config->bug->form->create['product'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['branch'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['module'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
@@ -18,27 +17,24 @@ $config->bug->form->create['deadline'] = array('required' => false, 'type' =>
|
||||
$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' => '');
|
||||
|
||||
$config->bug->form->create['os'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->bug->form->create['browser'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->bug->form->create['color'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['severity'] = array('required' => false, 'type' => 'int', 'default' => 3);
|
||||
$config->bug->form->create['pri'] = array('required' => false, 'type' => 'int', 'default' => 3);
|
||||
$config->bug->form->create['steps'] = array('required' => false, 'type' => 'string', 'default' => $lang->bug->tplStep . $lang->bug->tplResult . $lang->bug->tplExpect);
|
||||
|
||||
$config->bug->form->create['story'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['task'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['oldTaskID'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['case'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['caseVersion'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['result'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['testtask'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
|
||||
$config->bug->form->create['mailto'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->bug->form->create['keywords'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['status'] = array('required' => false, 'type' => 'string', 'default' => 'active');
|
||||
$config->bug->form->create['issueKey'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['uid'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['os'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->bug->form->create['browser'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->bug->form->create['color'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['severity'] = array('required' => false, 'type' => 'int', 'default' => 3);
|
||||
$config->bug->form->create['pri'] = array('required' => false, 'type' => 'int', 'default' => 3);
|
||||
$config->bug->form->create['steps'] = array('required' => false, 'type' => 'string', 'default' => $lang->bug->tplStep . $lang->bug->tplResult . $lang->bug->tplExpect);
|
||||
$config->bug->form->create['story'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['task'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['case'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['caseVersion'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['result'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['testtask'] = array('required' => false, 'type' => 'int', 'default' => 0);
|
||||
$config->bug->form->create['mailto'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join');
|
||||
$config->bug->form->create['keywords'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['status'] = array('required' => false, 'type' => 'string', 'default' => 'active');
|
||||
$config->bug->form->create['issueKey'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
$config->bug->form->create['openedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account);
|
||||
$config->bug->form->create['openedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now());
|
||||
|
||||
$config->bug->form->edit = array();
|
||||
$config->bug->form->edit['title'] = array('required' => true, 'type' => 'string', 'filter' => 'trim');
|
||||
|
||||
+25
-10
@@ -201,32 +201,47 @@ class bug extends control
|
||||
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$data = form::data($this->config->bug->form->create);
|
||||
$bug = $this->bugZen->prepareCreateExtras($data, $this->post->uid);
|
||||
$bug = form::data($this->config->bug->form->create)
|
||||
->setIF($this->lang->navGroup->bug != 'qa', 'project', $this->session->project)
|
||||
->setIF($this->post->assignedTo != '', 'assignedDate', helper::now())
|
||||
->setIF($this->post->story !== false, 'storyVersion', $this->loadModel('story')->getVersion($this->post->story))
|
||||
->get();
|
||||
|
||||
if(empty($bug->deadline)) unset($bug->deadline);
|
||||
|
||||
$bug = $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->create['id'], $this->post->uid);
|
||||
|
||||
$checkExist = $this->bugZen->checkExistBug($bug);
|
||||
if($checkExist['status'] == 'exists') $this->send(array('result' => 'success', 'id' => $checkExist['id'], 'message' => sprintf($this->lang->duplicate, $this->lang->bug->common), 'locate' => $this->createLink('bug', 'view', "bugID={$checkExist['id']}")));
|
||||
|
||||
$bugID = $this->bug->create($bug);
|
||||
$action = $from == 'sonarqube' ? 'fromSonarqube' : 'Opened';
|
||||
$bugID = $this->bug->create($bug, $action);
|
||||
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
/* Set from param if there is a object to transfer bug. */
|
||||
helper::setcookie('lastBugModule', (string)$data->data->module);
|
||||
helper::setcookie('lastBugModule', (string)$bug->module);
|
||||
|
||||
$bug = $this->bug->getByID($bugID);
|
||||
|
||||
$this->bugZen->updateFileAfterCreate($bugID, $data->data);
|
||||
list($laneID, $columnID) = $this->bugZen->getKanbanVariable($data->data, $output);
|
||||
$this->bugZen->updateFileAfterCreate($bugID);
|
||||
list($laneID, $columnID) = $this->bugZen->getKanbanVariable($output);
|
||||
$this->bugZen->updateKanbanAfterCreate($bug, $laneID, $columnID, $from);
|
||||
|
||||
$this->bugZen->addAction4Create($bug, $output, $from);
|
||||
|
||||
$message = $this->executeHooks($bugID);
|
||||
if($message) $this->lang->saveSuccess = $message;
|
||||
if(!$message) $message = $this->lang->saveSuccess;
|
||||
|
||||
$executionID = $bug->execution ? $bug->execution : zget($output, 'executionID', $this->session->execution);
|
||||
$response = $this->bugZen->responseAfterCreate($bugID, (int)$executionID, $output);
|
||||
return $this->send($response);
|
||||
$executionID = $bug->execution ? $bug->execution : (int)zget($output, 'executionID', $this->session->execution);
|
||||
|
||||
/* Return bug id when call the API. */
|
||||
if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $message, 'id' => $bugID));
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'data' => $bugID));
|
||||
|
||||
if(isonlybody()) return $this->send($this->responseInModal($executionID));
|
||||
|
||||
$location = $this->getLocation4Create($bugID, $executionID, $output);
|
||||
return $this->send(array('result' => 'success', 'message' => $message, 'load' => $location));
|
||||
}
|
||||
|
||||
$productID = $this->product->saveVisitState($productID, $this->products);
|
||||
|
||||
@@ -54,7 +54,7 @@ class bugModel extends model
|
||||
* @access public
|
||||
* @return int|false
|
||||
*/
|
||||
public function create(object $bug): int|false
|
||||
public function create(object $bug, string $action = 'Opened'): int|false
|
||||
{
|
||||
$this->dao->insert(TABLE_BUG)->data($bug)
|
||||
->autoCheck()
|
||||
@@ -63,8 +63,13 @@ class bugModel extends model
|
||||
->checkFlow()
|
||||
->exec();
|
||||
|
||||
if(!dao::isError()) return $this->dao->lastInsertID();
|
||||
return false;
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$bugID = $this->dao->lastInsertID();
|
||||
|
||||
$this->loadModel('action')->create('bug', $bugID, $action);
|
||||
|
||||
return $bugID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+22
-73
@@ -253,35 +253,6 @@ class bugZen extends bug
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用表单数据构造一个bug对象。
|
||||
* Prepare a bug object from form data.
|
||||
*
|
||||
* @param object $data
|
||||
* @param string $uid
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function prepareCreateExtras(object $data, string $uid): object
|
||||
{
|
||||
$now = helper::now();
|
||||
$bug = $data->setDefault('openedBy', $this->app->user->account)
|
||||
->setDefault('openedDate', $now)
|
||||
->setIF($this->lang->navGroup->bug != 'qa', 'project', $this->session->project)
|
||||
->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')
|
||||
->get();
|
||||
|
||||
if(empty($bug->deadline)) unset($bug->deadline);
|
||||
|
||||
return $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->create['id'], $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查bug是否已经存在。
|
||||
* Check whether bug is exist.
|
||||
@@ -304,18 +275,17 @@ class bugZen extends bug
|
||||
* Save files after create a bug.
|
||||
*
|
||||
* @param int $bugID
|
||||
* @param object $rawdata
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
protected function updateFileAfterCreate(int $bugID, object $rawdata): void
|
||||
protected function updateFileAfterCreate(int $bugID): bool
|
||||
{
|
||||
if(isset($rawdata->resultFiles))
|
||||
if(isset($this->post->resultFiles))
|
||||
{
|
||||
$resultFiles = $rawdata->resultFiles;
|
||||
if(isset($rawdata->deleteFiles))
|
||||
$resultFiles = $this->post->resultFiles;
|
||||
if(isset($this->post->deleteFiles))
|
||||
{
|
||||
foreach($rawdata->deleteFiles as $deletedCaseFileID) $resultFiles = trim(str_replace(",$deletedCaseFileID,", ',', ",$resultFiles,"), ',');
|
||||
foreach($this->post->deleteFiles as $deletedCaseFileID) $resultFiles = trim(str_replace(",$deletedCaseFileID,", ',', ",$resultFiles,"), ',');
|
||||
}
|
||||
$files = $this->dao->select('*')->from(TABLE_FILE)->where('id')->in($resultFiles)->fetchAll('id');
|
||||
foreach($files as $file)
|
||||
@@ -327,23 +297,24 @@ class bugZen extends bug
|
||||
}
|
||||
}
|
||||
|
||||
$this->file->updateObjectID($rawdata->uid, $bugID, 'bug');
|
||||
$this->loadModel('file')->updateObjectID($this->post->uid, $bugID, 'bug');
|
||||
$this->file->saveUpload('bug', $bugID);
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过$_POST的值和解析出来的$output,获得看板的laneID和columnID。
|
||||
* Get kanban laneID and columnID from $_POST and $output from extra().
|
||||
*
|
||||
* @param object $rawdata
|
||||
* @param array $output
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getKanbanVariable(object $rawdata, array $output): array
|
||||
protected function getKanbanVariable(array $output): array
|
||||
{
|
||||
$laneID = isset($output['laneID']) ? $output['laneID'] : 0;
|
||||
if(!empty($rawdata->lane)) $laneID = $rawdata->lane;
|
||||
if(!empty($this->post->lane)) $laneID = $this->post->lane;
|
||||
|
||||
$columnID = $this->loadModel('kanban')->getColumnIDByLaneID($laneID, 'unconfirmed');
|
||||
if(empty($columnID)) $columnID = isset($output['columnID']) ? $output['columnID'] : 0;
|
||||
@@ -534,16 +505,13 @@ class bugZen extends bug
|
||||
* @param array $output
|
||||
* @param string $from
|
||||
* @access protected
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
protected function addAction4Create(object $bug, array $output, string $from): void
|
||||
protected function addAction4Create(object $bug, array $output, string $from): bool
|
||||
{
|
||||
$bugID = $bug->id;
|
||||
$todoID = isset($output['todoID']) ? $output['todoID'] : 0;
|
||||
|
||||
$action = $from == 'sonarqube' ? 'fromSonarqube' : 'Opened';
|
||||
$this->action->create('bug', $bugID, $action);
|
||||
|
||||
/* Add score for create. */
|
||||
if(empty($bug->case))
|
||||
{
|
||||
@@ -554,36 +522,17 @@ class bugZen extends bug
|
||||
$this->loadModel('score')->create('bug', 'createFormCase', $bug->case);
|
||||
}
|
||||
|
||||
if(!$todoID) return;
|
||||
$this->dao->update(TABLE_TODO)->set('status')->eq('done')->where('id')->eq($todoID)->exec();
|
||||
$this->action->create('todo', $todoID, 'finished', '', "BUG:$bugID");
|
||||
if($this->config->edition == 'biz' || $this->config->edition == 'max')
|
||||
if($todoID)
|
||||
{
|
||||
$todo = $this->dao->select('type, idvalue')->from(TABLE_TODO)->where('id')->eq($todoID)->fetch();
|
||||
if($todo->type == 'feedback' && $todo->idvalue) $this->loadModel('feedback')->updateStatus('todo', $todo->idvalue, 'done');
|
||||
$this->dao->update(TABLE_TODO)->set('status')->eq('done')->where('id')->eq($todoID)->exec();
|
||||
$this->action->create('todo', $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($todoID)->fetch();
|
||||
if($todo->type == 'feedback' && $todo->idvalue) $this->loadModel('feedback')->updateStatus('todo', $todo->idvalue, 'done');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得create方法的response。
|
||||
* Get response for create.
|
||||
*
|
||||
* @param int $bugID
|
||||
* @param int $executionID
|
||||
* @param array $output
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function responseAfterCreate(int $bugID, int $executionID, array $output): 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(isonlybody()) return $this->responseInModal($executionID);
|
||||
|
||||
$location = $this->getLocation4Create($bugID, $executionID, $output);
|
||||
return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $location);
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user