* [perf story #69501] set task relation for child.
This commit is contained in:
@@ -374,7 +374,7 @@ class taskModel extends model
|
||||
$isParentChanged = $task->parent != $oldTask->parent;
|
||||
|
||||
/* If there is a parent task before updating the task, update the parent. */
|
||||
if($task->parent > 0) $this->updateParent($task, $isParentChanged);
|
||||
$this->updateParent($task, $isParentChanged);
|
||||
if($isParentChanged && $oldTask->parent > 0)
|
||||
{
|
||||
$oldParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($oldTask->parent)->fetch();
|
||||
@@ -3223,11 +3223,12 @@ class taskModel extends model
|
||||
public function updateParent(object $task, bool $isParentChanged): void
|
||||
{
|
||||
$oldTask = $this->fetchByID($task->id);
|
||||
$parentTask = $this->fetchByID((int)$task->parent);
|
||||
$path = $parentTask->path . $task->id . ',';
|
||||
$parentTask = empty($task->parent) ? null : $this->fetchByID((int)$task->parent);
|
||||
$parentPath = $parentTask ? $parentTask->path : ',';
|
||||
$path = $parentPath . $task->id . ',';
|
||||
|
||||
$this->dao->update(TABLE_TASK)->set('path')->eq($path)->where('id')->eq($task->id)->exec();
|
||||
if(!$parentTask->isParent) $this->dao->update(TABLE_TASK)->set('isParent')->eq(1)->where('id')->eq((int)$task->parent)->exec();
|
||||
if($parentTask && !$parentTask->isParent) $this->dao->update(TABLE_TASK)->set('isParent')->eq(1)->where('id')->eq((int)$task->parent)->exec();
|
||||
|
||||
/* 更新所有子任务的path. */
|
||||
$childIdList = $this->getAllChildId($task->id, false);
|
||||
@@ -3242,9 +3243,10 @@ class taskModel extends model
|
||||
}
|
||||
|
||||
$this->updateParentStatus($task->id, $task->parent, !$isParentChanged);
|
||||
$this->computeBeginAndEnd($task->parent);
|
||||
if($task->parent) $this->computeBeginAndEnd($task->parent);
|
||||
|
||||
if($isParentChanged)
|
||||
$this->taskTao->updateRelation((int)$task->id, (int)$task->parent);
|
||||
if($isParentChanged && $task->parent)
|
||||
{
|
||||
$this->loadModel('action')->create('task', $task->id, 'linkParentTask', '', $task->parent, '', false);
|
||||
$actionID = $this->action->create('task', $task->parent, 'linkChildTask', '', $task->id, '', false);
|
||||
|
||||
@@ -1055,4 +1055,43 @@ class taskTao extends taskModel
|
||||
|
||||
if($task->mode == 'linear' && empty($record->order)) $this->updateEffortOrder($effortID, $currentTeam->order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新父子任务关系。
|
||||
* Update relation of parent and child.
|
||||
*
|
||||
* @param int $childID
|
||||
* @param int $parentID
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function updateRelation(int $childID, int $parentID = 0): void
|
||||
{
|
||||
if(empty($childID)) return;
|
||||
|
||||
$relation = $this->dao->select('*')->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->fetch();
|
||||
if($relation)
|
||||
{
|
||||
if($parentID && $relation->BID == $parentID) return;
|
||||
|
||||
$this->dao->delete()->from(TABLE_RELATION)->where('BID')->eq($childID)->andWhere('relation')->eq('subdivideinto')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec();
|
||||
$this->dao->delete()->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec();
|
||||
}
|
||||
|
||||
if(empty($parentID)) return;
|
||||
|
||||
$data = new stdclass();
|
||||
$data->AType = 'task';
|
||||
$data->BType = 'task';
|
||||
$data->AID = $childID;
|
||||
$data->BID = $parentID;
|
||||
$data->relation = 'subdividefrom';
|
||||
$this->dao->insert(TABLE_RELATION)->data($data)->exec();
|
||||
|
||||
$data->AID = $parentID;
|
||||
$data->BID = $childID;
|
||||
$data->relation = 'subdivideinto';
|
||||
$this->dao->insert(TABLE_RELATION)->data($data)->exec();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2246,4 +2246,22 @@ class taskTest
|
||||
foreach($childTasks as $key => $value) $result .= $key . ':' . $value . ';';
|
||||
return rtrim($result, ';');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 updateRelation 方法
|
||||
* Test updateRelationq
|
||||
*
|
||||
* @param int $childID
|
||||
* @param int $parentID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateRelationTest(int $childID, int $parentID = 0)
|
||||
{
|
||||
$this->objectModel->updateRelation($childID, $parentID);
|
||||
$relation = $this->objectModel->dao->select('*')->from(TABLE_RELATION)->where('AID')->eq($childID)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->fetch();
|
||||
|
||||
if(empty($relation)) return 'null';
|
||||
return $relation->BID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/task.unittest.class.php';
|
||||
|
||||
/**
|
||||
|
||||
title=taskTao->updateRelation();
|
||||
cid=0
|
||||
|
||||
- 都传入空参数 @null
|
||||
- childID传入空参数 @null
|
||||
- 传入正常参数 @1
|
||||
- 修改关联父任务 @3
|
||||
- 解除关联 @null
|
||||
|
||||
*/
|
||||
|
||||
zenData('relation')->gen(0);
|
||||
|
||||
$task = new taskTest();
|
||||
|
||||
r($task->updateRelationTest(0, 0)) && p() && e('null'); //都传入空参数
|
||||
r($task->updateRelationTest(0, 1)) && p() && e('null'); //childID传入空参数
|
||||
r($task->updateRelationTest(2, 1)) && p() && e('1'); //传入正常参数
|
||||
r($task->updateRelationTest(2, 3)) && p() && e('3'); //修改关联父任务
|
||||
r($task->updateRelationTest(2, 0)) && p() && e('null'); //解除关联
|
||||
@@ -105,6 +105,7 @@ $config->upgrade->execFlow['20_5'] = array('functions' => 'fixWorkflowFie
|
||||
$config->upgrade->execFlow['20_6'] = array('functions' => 'processDemandFiles,processSqlbuilderTables');
|
||||
$config->upgrade->execFlow['20_7'] = array('functions' => 'upgradeMyDocSpace');
|
||||
$config->upgrade->execFlow['20_8'] = array('functions' => 'processWorkflowGroups');
|
||||
$config->upgrade->execFlow['20_9'] = array('functions' => 'initTaskRelation');
|
||||
|
||||
if(!empty($config->isINT))
|
||||
{
|
||||
|
||||
@@ -10451,4 +10451,37 @@ class upgradeModel extends model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化任务关联。
|
||||
* Init task relation.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initTaskRelation()
|
||||
{
|
||||
$childTasks = $this->dao->select('id,parent')->from(TABLE_TASK)->where('parent')->gt(0)->fetchPairs('id', 'parent');
|
||||
if(empty($childTasks)) return;
|
||||
|
||||
$childIdList = array_keys($childTasks);
|
||||
$this->dao->delete()->from(TABLE_RELATION)->where('BID')->in($childIdList)->andWhere('relation')->eq('subdivideinto')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec();
|
||||
$this->dao->delete()->from(TABLE_RELATION)->where('AID')->in($childIdList)->andWhere('relation')->eq('subdividefrom')->andWhere('AType')->eq('task')->andWhere('BType')->eq('task')->exec();
|
||||
|
||||
$data = new stdclass();
|
||||
$data->AType = 'task';
|
||||
$data->BType = 'task';
|
||||
foreach($childTasks as $taskID => $parentID)
|
||||
{
|
||||
$data->AID = $taskID;
|
||||
$data->BID = $parentID;
|
||||
$data->relation = 'subdividefrom';
|
||||
$this->dao->insert(TABLE_RELATION)->data($data)->exec();
|
||||
|
||||
$data->AID = $parentID;
|
||||
$data->BID = $taskID;
|
||||
$data->relation = 'subdivideinto';
|
||||
$this->dao->insert(TABLE_RELATION)->data($data)->exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user