* [perf story #69170] Adjust cancel parent task and cancel children tasks.

This commit is contained in:
wangyidong
2024-11-08 14:16:56 +08:00
committed by 孙广明
parent 4023defab4
commit e2bd232bcc
5 changed files with 9 additions and 112 deletions
+2 -6
View File
@@ -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);
+7 -27
View File
@@ -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;
}
-29
View File
@@ -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.
@@ -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.
-26
View File
@@ -1,26 +0,0 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/task.unittest.class.php';
zenData('user')->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'); // 测试取消子任务