diff --git a/module/task/model.php b/module/task/model.php index 1495931efa..dd7686340f 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -3226,49 +3226,39 @@ class taskModel extends model public function updateParentStatus(int $taskID, int $parentID = 0, bool $createAction = true) :void { /* Get child task info. */ - $childTask = $this->dao->select('id,assignedTo,parent')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch(); + $childTask = $this->dao->select('id,assignedTo,parent,path')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch(); if(empty($childTask)) return; - $oldParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($parentID)->fetch(); + if(empty($parentID)) $parentID = $childTask->parent; + if($parentID <= 0) return; - /* Compute parent task hours and status. */ - $this->computeWorkingHours($parentID); - $status = $this->taskTao->getParentStatusById($parentID); - if(empty($status)) - { - $this->dao->update(TABLE_TASK)->set('parent')->eq('0')->where('id')->eq($parentID)->exec(); - return; - } + $parentTasks = $this->dao->select('*')->from(TABLE_TASK)->where('id')->in($childTask->path)->andWhere('id')->ne($taskID)->fetchAll('id'); + if(empty($parentTasks)) return; - /* Get new task info. */ - $parentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($parentID)->andWhere('deleted')->eq(0)->fetch(); - if(empty($parentTask)) + $this->loadModel('story'); + foreach($parentTasks as $parentID => $parentTask) { - $this->dao->update(TABLE_TASK)->set('parent')->eq('0')->where('id')->eq($taskID)->exec(); - return; - } - - if($parentTask->status == $status) - { - if(dao::isError()) return; - $changes = common::createChanges($oldParentTask, $parentTask); - if($changes) + /* Compute parent task hours and status. */ + $this->computeWorkingHours($parentID); + $status = $this->taskTao->getParentStatusById($parentID); + if(empty($status)) { - $actionID = $this->loadModel('action')->create('task', $parentID, 'Edited', '', '', '', false); - $this->action->logHistory($actionID, $changes); + $this->dao->update(TABLE_TASK)->set('parent')->eq('0')->set('path')->eq(",{$parentID},")->where('id')->eq($parentID)->exec(); + continue; } - return; + if(!in_array($status, array('doing', 'done'))) continue; + if($parentTask->status == $status) continue; + + /* Update task status. */ + $this->taskTao->updateTaskByChildAndStatus($parentTask, $childTask, $status); + if(dao::isError() || !$createAction) return; + + if($parentTask->story) $this->story->setStage($parentTask->story); + + /* Create action record. */ + $this->taskTao->createUpdateParentTaskAction($parentTask); + if($this->config->edition != 'open' && $parentTask->feedback) $this->loadModel('feedback')->updateStatus('task', $parentTask->feedback, $status, $parentTask->status); } - - /* Update task status. */ - $this->taskTao->updateTaskByChildAndStatus($parentTask, $childTask, $status); - if(dao::isError() || !$createAction) return; - - if($parentTask->story) $this->loadModel('story')->setStage($parentTask->story); - - /* Create action record. */ - $this->taskTao->createUpdateParentTaskAction($oldParentTask); - if($this->config->edition != 'open' && $oldParentTask->feedback) $this->loadModel('feedback')->updateStatus('task', $oldParentTask->feedback, $status, $oldParentTask->status); } /** diff --git a/module/task/tao.php b/module/task/tao.php index 527e55fbec..e69db214b8 100644 --- a/module/task/tao.php +++ b/module/task/tao.php @@ -717,11 +717,9 @@ class taskTao extends taskModel protected function getParentStatusById(int $taskID) :string { $children = $this->dao->select('id,status,closedReason,parent')->from(TABLE_TASK)->where('parent')->eq($taskID)->andWhere('deleted')->eq('0')->fetchAll(); - if(empty($children)) return ''; $childrenStatus = $childrenClosedReason = array(); - foreach($children as $task) { $childrenStatus[$task->status] = $task->status; @@ -731,9 +729,7 @@ class taskTao extends taskModel if(count($childrenStatus) == 1) return current($childrenStatus); if(isset($childrenStatus['doing']) || isset($childrenStatus['pause'])) return 'doing'; - if((isset($childrenStatus['done']) || isset($childrenClosedReason['done'])) && isset($childrenStatus['wait'])) return 'doing'; - if(isset($childrenStatus['wait'])) return 'wait'; if(isset($childrenStatus['done'])) return 'done'; if(isset($childrenStatus['closed'])) return 'closed'; @@ -1056,7 +1052,6 @@ class taskTao extends taskModel $task->lastEditedBy = $this->app->user->account; $task->lastEditedDate = $now; - $task->parent = '-1'; $this->dao->update(TABLE_TASK)->data($task)->where('id')->eq($parentTask->id)->exec(); }