From 4e87c46502a21b0673c7759028a054513762c48b Mon Sep 17 00:00:00 2001 From: daitingting Date: Wed, 10 May 2023 08:49:04 +0000 Subject: [PATCH 1/2] * Rebuild delete function of control. --- module/bug/control.php | 59 ++++++++++++++---------------------------- module/bug/zen.php | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 39 deletions(-) diff --git a/module/bug/control.php b/module/bug/control.php index c5d7047a60..537de877bb 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1542,55 +1542,36 @@ class bug extends control } /** + * 删除 bug。 * Delete a bug. * - * @param int $bugID - * @param string $confirm yes|no + * @param string $bugID + * @param string $confirm yes|no + * @param string $from taskkanban * @access public * @return void */ - public function delete($bugID, $confirm = 'no', $from = '') + public function delete(string $bugID, string $confirm = 'no', string $from = '') { - $bug = $this->bug->getById($bugID); - if($confirm == 'no') + if($confirm == 'no') return $this->send(array('result' => 'success', 'load' => array('confirm' => $this->lang->bug->confirmDelete, 'confirmed' =>inlink('delete', "bugID=$bugID&confirm=yes&from=$from")))); + + $bug = $this->bug->getByID($bugID); + + $this->bug->delete(TABLE_BUG, $bugID); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + /* 如果 bug 转任务,删除 bug 时确认是否更新任务状态。*/ + /* If the bug has been transfered to a task, confirm to update task when delete the bug. */ + if($bug->toTask) { - return print(js::confirm($this->lang->bug->confirmDelete, inlink('delete', "bugID=$bugID&confirm=yes&from=$from"))); + $result = $this->bugZen->confirm2UpdateTask($bugID, $bug->toTask); + if(is_array($result)) return $this->send($result); } - else - { - $this->bug->delete(TABLE_BUG, $bugID); - if($bug->toTask != 0) - { - $task = $this->task->getById($bug->toTask); - if(!$task->deleted) - { - $confirmURL = $this->createLink('task', 'view', "taskID=$bug->toTask"); - unset($_GET['onlybody']); - $cancelURL = $this->createLink('bug', 'view', "bugID=$bugID"); - return print(js::confirm(sprintf($this->lang->bug->remindTask, $bug->toTask), $confirmURL, $cancelURL, 'parent', 'parent.parent')); - } - } - $this->executeHooks($bugID); + $this->executeHooks($bugID); - if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); - - if(isonlybody()) return print(js::reload('parent.parent')); - - if($from == 'taskkanban') - { - $laneType = $this->session->executionLaneType ? $this->session->executionLaneType : 'all'; - $groupBy = $this->session->executionGroupBy ? $this->session->executionGroupBy : 'default'; - $taskSearchValue = $this->session->taskSearchValue ? $this->session->taskSearchValue : ''; - $kanbanData = $this->loadModel('kanban')->getExecutionKanban($bug->execution, $laneType, $groupBy, $taskSearchValue); - $kanbanType = $laneType == 'all' ? 'bug' : key($kanbanData); - $kanbanData = json_encode($kanbanData[$kanbanType]); - return print(js::closeModal('parent', '', "parent.updateKanban(\"bug\", $kanbanData)")); - } - - $locateLink = $this->session->bugList ? $this->session->bugList : inlink('browse', "productID={$bug->product}"); - return print(js::locate($locateLink, 'parent')); - } + return $this->send($this->bugZen->responseAfterDelete($bug, $from)); } /** diff --git a/module/bug/zen.php b/module/bug/zen.php index afeb86d5cf..61d889c3d5 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -967,6 +967,60 @@ class bugZen extends bug return $assignedToPairs; } + /** + * 确认是否更新 bug 状态。 + * Confirm to update task. + * + * @param int $bugID + * @param int $taskID + * @access protected + * @return array|true + */ + protected function confirm2UpdateTask(int $bugID, int $taskID): array + { + $task = $this->task->getByID($taskID); + if($task->deleted) return true; + + $confirmURL = $this->createLink('task', 'view', "taskID=$bug->toTask"); + unset($_GET['onlybody']); + $cancelURL = $this->createLink('bug', 'view', "bugID=$bugID"); + return array('result' => 'success', 'load' => array('confirm' => $this->lang->bug->remindTask, 'confirmed' => $confirmURL, 'canceled' => $cancelURL)); + } + + /** + * 删除 bug 后不同的返回结果。 + * respond after deleting. + * + * @param object $bug + * @param string $from + * @access protected + * @return array + */ + protected function responseAfterDelete(object $bug, string $from): array + { + if($this->viewType == 'json') return array('result' => 'success', 'message' => $this->lang->saveSuccess); + + /* 在弹窗中删除 bug 时的返回。*/ + /* Respond when delete bug in modal.。*/ + if(isonlybody()) return array('result' => 'success', 'load' => true); + + /* 在任务看板中删除 bug 时的返回。*/ + /* Respond when delete in task kanban. */ + if($from == 'taskkanban') + { + $laneType = $this->session->executionLaneType ? $this->session->executionLaneType : 'all'; + $groupBy = $this->session->executionGroupBy ? $this->session->executionGroupBy : 'default'; + $searchValue = $this->session->taskSearchValue ? $this->session->taskSearchValue : ''; + $kanbanData = $this->loadModel('kanban')->getExecutionKanban($bug->execution, $laneType, $groupBy, $searchValue); + $kanbanType = $laneType == 'all' ? 'bug' : key($kanbanData); + $kanbanData = json_encode($kanbanData[$kanbanType]); + + return array('result' => 'success', 'closeModal' => true, 'callback' => "updateKanban(\"bug\", $kanbanData)"); + } + + return array('result' => 'success', 'load' => $this->session->bugList ? $this->session->bugList : inlink('browse', "productID={$bug->product}")); + } + /** * 如果不是弹窗,调用该方法为查看bug设置导航。 * If it's not a iframe, call this method to set menu for view bug page. From 707747a906120bbf3ae34c5513257e8c39c011fe Mon Sep 17 00:00:00 2001 From: daitingting Date: Wed, 10 May 2023 10:17:46 +0000 Subject: [PATCH 2/2] * Use shorthand. --- module/bug/zen.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/bug/zen.php b/module/bug/zen.php index 61d889c3d5..d3e25406cf 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -1008,9 +1008,9 @@ class bugZen extends bug /* Respond when delete in task kanban. */ if($from == 'taskkanban') { - $laneType = $this->session->executionLaneType ? $this->session->executionLaneType : 'all'; - $groupBy = $this->session->executionGroupBy ? $this->session->executionGroupBy : 'default'; - $searchValue = $this->session->taskSearchValue ? $this->session->taskSearchValue : ''; + $laneType = $this->session->executionLaneType ?: 'all'; + $groupBy = $this->session->executionGroupBy ?: 'default'; + $searchValue = $this->session->taskSearchValue ?: ''; $kanbanData = $this->loadModel('kanban')->getExecutionKanban($bug->execution, $laneType, $groupBy, $searchValue); $kanbanType = $laneType == 'all' ? 'bug' : key($kanbanData); $kanbanData = json_encode($kanbanData[$kanbanType]); @@ -1018,7 +1018,7 @@ class bugZen extends bug return array('result' => 'success', 'closeModal' => true, 'callback' => "updateKanban(\"bug\", $kanbanData)"); } - return array('result' => 'success', 'load' => $this->session->bugList ? $this->session->bugList : inlink('browse', "productID={$bug->product}")); + return array('result' => 'success', 'load' => $this->session->bugList ?: inlink('browse', "productID={$bug->product}")); } /**