From e2bd232bcc577e1f49db00c1f74647f255a40934 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 8 Nov 2024 14:12:58 +0800 Subject: [PATCH] * [perf story #69170] Adjust cancel parent task and cancel children tasks. --- module/task/control.php | 8 ++--- module/task/model.php | 34 ++++---------------- module/task/tao.php | 29 ----------------- module/task/test/lib/task.unittest.class.php | 24 -------------- module/task/test/tao/cancelparenttask.php | 26 --------------- 5 files changed, 9 insertions(+), 112 deletions(-) delete mode 100755 module/task/test/tao/cancelparenttask.php diff --git a/module/task/control.php b/module/task/control.php index 2ffdc1e0e0..e1025adf85 100755 --- a/module/task/control.php +++ b/module/task/control.php @@ -875,14 +875,10 @@ class task extends control if(!empty($_POST)) { - $this->loadModel('action'); - $oldTask = $this->task->getByID($taskID); $task = $this->taskZen->buildTaskForCancel($oldTask); - $laneID = isset($output['laneID']) ? $output['laneID'] : ''; - $this->task->cancel($task, (string)$laneID); - - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + $result = $this->task->cancel($oldTask, $task, $output); + if(!$result) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->executeHooks($taskID); diff --git a/module/task/model.php b/module/task/model.php index 294ecf221f..864309ef36 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -628,43 +628,23 @@ class taskModel extends model * 取消一个任务。 * Cancel a task. * + * @param object $oldTask * @param object $task - * @param string $extra + * @param array $output * @access public * @return bool */ - public function cancel(object $task, string $extra = ''): bool + public function cancel(object $oldTask, object $task, array $output = array()): bool { - $oldTask = $this->getByID($task->id); - $this->dao->update(TABLE_TASK)->data($task) - ->autoCheck() - ->checkFlow() - ->where('id')->eq($task->id) - ->exec(); - + $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->checkFlow()->where('id')->eq($oldTask->id)->exec(); if(dao::isError()) return false; - if($oldTask->fromBug) $this->dao->update(TABLE_BUG)->set('toTask')->eq(0)->where('id')->eq($oldTask->fromBug)->exec(); - if($oldTask->parent > 0) $this->updateParentStatus($task->id); + if(!empty($oldTask->mode)) $this->dao->update(TABLE_TASKTEAM)->set('status')->eq($task->status)->where('task')->eq($oldTask->id)->exec(); + if(!empty($oldTask->fromBug)) $this->dao->update(TABLE_BUG)->set('toTask')->eq(0)->where('id')->eq($oldTask->fromBug)->exec(); /* Cancel a parent task. */ - if($oldTask->isParent) $this->taskTao->cancelParentTask($task); - - if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story); - - $extra = str_replace(array(',', ' '), array('&', ''), $extra); - parse_str($extra, $output); - - $this->updateKanbanCell($oldTask->id, $output, $oldTask->execution); - if(!empty($oldTask->mode)) $this->dao->update(TABLE_TASKTEAM)->set('status')->eq($task->status)->where('task')->eq($task->id)->exec(); - $changes = common::createChanges($oldTask, $task); - if($changes || $this->post->comment != '') - { - $actionID = $this->loadModel('action')->create('task', $oldTask->id, 'Canceled', $this->post->comment); - $this->action->logHistory($actionID, $changes); - } - + $this->afterChangeStatus($oldTask, $changes, 'Canceled', $output); return true; } diff --git a/module/task/tao.php b/module/task/tao.php index 909f4bada2..bd0ac29ab6 100644 --- a/module/task/tao.php +++ b/module/task/tao.php @@ -186,35 +186,6 @@ class taskTao extends taskModel return $workhour; } - /** - * 取消父任务更新子任务。 - * Update a child task when cancel its parent task. - * - * @param object $task - * @access protected - * @return void - */ - protected function cancelParentTask(object $task): void - { - $taskID = $task->id; - unset($task->assignedTo); - unset($task->id); - - $oldChildrenTasks = $this->dao->select('*')->from(TABLE_TASK)->where('parent')->eq($taskID)->fetchAll('id'); - $this->dao->update(TABLE_TASK)->data($task)->autoCheck()->where('parent')->eq((int)$taskID)->exec(); - $this->dao->update(TABLE_TASK)->set('assignedTo=openedBy')->where('parent')->eq((int)$taskID)->exec(); - - if(!dao::isError() && count($oldChildrenTasks) > 0) - { - $this->loadModel('action'); - foreach($oldChildrenTasks as $oldChildrenTask) - { - $actionID = $this->action->create('task', $oldChildrenTask->id, 'Canceled', $this->post->comment); - $this->action->logHistory($actionID, common::createChanges($oldChildrenTask, $task)); - } - } - } - /** * 编辑日志时,检查输入是否合法。 * When editing a effort, check that the input is legal. diff --git a/module/task/test/lib/task.unittest.class.php b/module/task/test/lib/task.unittest.class.php index 7c4e50d969..bf9c5ae089 100755 --- a/module/task/test/lib/task.unittest.class.php +++ b/module/task/test/lib/task.unittest.class.php @@ -1945,30 +1945,6 @@ class taskTest return $this->objectModel->dao->select('action')->from(TABLE_ACTION)->where('objectType')->eq('task')->andWhere('objectID')->eq($oldParentTask->id)->orderBy('`id` desc')->fetch();; } - /** - * 取消父任务更新子任务。。 - * Update a child task when cancel its parent task. - * - * @param int $taskID - * @access public - * @return object|false - */ - public function cancelParentTaskTest(int $taskID): object|false - { - $task = $this->objectModel->getByID($taskID); - - $data = new stdclass(); - $data->id = $task->id; - $data->name = $task->name; - $data->pri = $task->pri; - $data->status = $task->status; - $data->execution = $task->execution; - $this->objectModel->cancelParentTask($data); - - $childID = $this->objectModel->dao->select('id')->from(TABLE_TASK)->where('parent')->eq($taskID)->fetch('id'); - return $this->objectModel->dao->select('action')->from(TABLE_ACTION)->where('objectType')->eq('task')->andWhere('objectID')->eq($childID)->orderBy('id_desc')->fetch(); - } - /** * 获取报表的查询语句。 * Get report condition from session. diff --git a/module/task/test/tao/cancelparenttask.php b/module/task/test/tao/cancelparenttask.php deleted file mode 100755 index 2caddce3c3..0000000000 --- a/module/task/test/tao/cancelparenttask.php +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env php -gen(5); -su('admin'); - -zenData('project')->loadYaml('project')->gen(10); -zenData('task')->loadYaml('task')->gen(10); - -/** - -title=taskModel->cancelParentTask(); -timeout=0 -cid=2 - -*/ - -$taskIdList = array(1, 6, 7); - -$taskTester = new taskTest(); - -r($taskTester->cancelParentTaskTest($taskIdList[0])) && p() && e('0'); // 测试取消普通任务 -r($taskTester->cancelParentTaskTest($taskIdList[1])) && p('action') && e('canceled'); // 测试取消父任务 -r($taskTester->cancelParentTaskTest($taskIdList[2])) && p() && e('0'); // 测试取消子任务