diff --git a/module/task/model.php b/module/task/model.php index 05b5d7b213..a66c40d6fc 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -708,11 +708,10 @@ class taskModel extends model * Update a task. * * @param object $task - * @param object $postData * @access public * @return array|string|false */ - public function update(object $task, object $postData): array|string|false + public function update(object $task): array|string|false { $taskID = $task->id; if($taskID <= 0) return false; @@ -720,10 +719,9 @@ class taskModel extends model $oldTask = $this->getByID($taskID); /* When the selected parent task is a common task and has consumption, select other parent tasks. */ - if($postData->parent > 0) + if($task->parent > 0) { - $taskConsumed = 0; - $taskConsumed = $this->dao->select('consumed')->from(TABLE_TASK)->where('id')->eq($postData->parent)->andWhere('parent')->eq(0)->fetch('consumed'); + $taskConsumed = $this->dao->select('consumed')->from(TABLE_TASK)->where('id')->eq($task->parent)->andWhere('parent')->eq(0)->fetch('consumed'); if($taskConsumed > 0) { dao::$errors[] = $this->lang->task->error->alreadyConsumed; @@ -737,7 +735,7 @@ class taskModel extends model return false; } - if($postData->team and count(array_filter($postData->team)) > 1) + if($this->post->team and count(array_filter($this->post->team)) > 1) { $teams = $this->manageTaskTeam($oldTask->mode, $taskID, $task->status); if(!empty($teams)) $task = $this->computeMultipleHours($oldTask, $task, array(), false); @@ -746,67 +744,66 @@ class taskModel extends model $requiredFields = $this->taskTao->getRequiredFields4Edit($task); $this->taskTao->doUpdate($task, $oldTask, $requiredFields); - if(!dao::isError()) + if(dao::isError()) return false; + + if($task->mode == 'single') $this->dao->delete()->from(TABLE_TASKTEAM)->where('task')->eq($taskID)->exec(); + + if(isset($task->version) && $task->version > $oldTask->version) $this->taskTao->recordTaskVersion($task); + + if($task->story != $oldTask->story) { - if($task->mode == 'single') $this->dao->delete()->from(TABLE_TASKTEAM)->where('task')->eq($taskID)->exec(); - - if(isset($task->version) && $task->version > $oldTask->version) $this->taskTao->recordTaskVersion($task); - - if($postData->story != $oldTask->story) - { - $this->loadModel('story')->setStage($postData->story); - $this->story->setStage($oldTask->story); - } - if($task->status == 'done') $this->loadModel('score')->create('task', 'finish', $taskID); - if($task->status == 'closed') $this->loadModel('score')->create('task', 'close', $taskID); - if($task->status != $oldTask->status) $this->loadModel('kanban')->updateLane($task->execution, 'task', $taskID); - - $this->loadModel('action'); - $isParentChanged = $task->parent != $oldTask->parent; - if($oldTask->parent > 0) - { - $oldParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($oldTask->parent)->fetch(); - $this->updateParentStatus($taskID, $oldTask->parent, !$isParentChanged); - $this->computeBeginAndEnd($oldTask->parent); - - if($isParentChanged) - { - $oldChildCount = $this->dao->select('count(*) as count')->from(TABLE_TASK)->where('parent')->eq($oldTask->parent)->fetch('count'); - if(!$oldChildCount) $this->dao->update(TABLE_TASK)->set('parent')->eq(0)->where('id')->eq($oldTask->parent)->exec(); - $this->dao->update(TABLE_TASK)->set('lastEditedBy')->eq($this->app->user->account)->set('lastEditedDate')->eq(helper::now())->where('id')->eq($oldTask->parent)->exec(); - $this->action->create('task', $taskID, 'unlinkParentTask', '', $oldTask->parent, '', false); - - $actionID = $this->action->create('task', $oldTask->parent, 'unLinkChildrenTask', '', $taskID, '', false); - - $newParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($oldTask->parent)->fetch(); - - $changes = common::createChanges($oldParentTask, $newParentTask); - if(!empty($changes)) $this->action->logHistory($actionID, $changes); - } - } - - if(!empty($task->parent)) $this->updateParent($task, $isParentChanged); - - unset($oldTask->parent, $task->parent); - - if(($this->config->edition == 'biz' || $this->config->edition == 'max') && $oldTask->feedback) $this->loadModel('feedback')->updateStatus('task', $oldTask->feedback, $task->status, $oldTask->status); - if(isset($oldTask->team)) - { - $users = $this->loadModel('user')->getPairs('noletter|noempty'); - $oldTeams = $oldTask->team; - $oldTask->team = ''; - foreach($oldTeams as $team) $oldTask->team .= "{$this->lang->task->teamMember}: " . zget($users, $team->account) . ", {$this->lang->task->estimateAB}: " . (float)$team->estimate . ", {$this->lang->task->consumedAB}: " . (float)$team->consumed . ", {$this->lang->task->leftAB}: " . (float)$team->left . "\n"; - $task->team = ''; - foreach($postData->team as $i => $account) - { - if(empty($account)) continue; - $task->team .= "{$this->lang->task->teamMember}: " . zget($users, $account) . ", {$this->lang->task->estimateAB}: " . zget($postData->teamEstimate, $i, 0) . ", {$this->lang->task->consumedAB}: " . zget($postData->teamConsumed, $i, 0) . ", {$this->lang->task->leftAB}: " . zget($postData->teamLeft, $i, 0) . "\n"; - } - } - - $this->file->processFile4Object('task', $oldTask, $task); - return common::createChanges($oldTask, $task); + $this->loadModel('story')->setStage($task->story); + $this->story->setStage($oldTask->story); } + + if($task->status == 'done') $this->loadModel('score')->create('task', 'finish', $taskID); + if($task->status == 'closed') $this->loadModel('score')->create('task', 'close', $taskID); + if($task->status != $oldTask->status) $this->loadModel('kanban')->updateLane($task->execution, 'task', $taskID); + + $isParentChanged = $task->parent != $oldTask->parent; + if($oldTask->parent > 0) + { + $oldParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($oldTask->parent)->fetch(); + $this->updateParentStatus($taskID, $oldTask->parent, !$isParentChanged); + $this->computeBeginAndEnd($oldTask->parent); + + if($isParentChanged) + { + $oldChildCount = $this->dao->select('count(*) as count')->from(TABLE_TASK)->where('parent')->eq($oldTask->parent)->fetch('count'); + if(!$oldChildCount) $this->dao->update(TABLE_TASK)->set('parent')->eq(0)->where('id')->eq($oldTask->parent)->exec(); + $this->dao->update(TABLE_TASK)->set('lastEditedBy')->eq($this->app->user->account)->set('lastEditedDate')->eq(helper::now())->where('id')->eq($oldTask->parent)->exec(); + $this->loadModel('action')->create('task', $taskID, 'unlinkParentTask', '', $oldTask->parent, '', false); + + $actionID = $this->action->create('task', $oldTask->parent, 'unLinkChildrenTask', '', $taskID, '', false); + + $newParentTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($oldTask->parent)->fetch(); + + $changes = common::createChanges($oldParentTask, $newParentTask); + if(!empty($changes)) $this->action->logHistory($actionID, $changes); + } + } + + if(!empty($task->parent)) $this->updateParent($task, $isParentChanged); + + unset($oldTask->parent, $task->parent); + + if($this->config->edition != 'open' && $oldTask->feedback) $this->loadModel('feedback')->updateStatus('task', $oldTask->feedback, $task->status, $oldTask->status); + if(isset($oldTask->team)) + { + $users = $this->loadModel('user')->getPairs('noletter|noempty'); + $oldTeams = $oldTask->team; + $oldTask->team = ''; + foreach($oldTeams as $team) $oldTask->team .= "{$this->lang->task->teamMember}: " . zget($users, $team->account) . ", {$this->lang->task->estimateAB}: " . (float)$team->estimate . ", {$this->lang->task->consumedAB}: " . (float)$team->consumed . ", {$this->lang->task->leftAB}: " . (float)$team->left . "\n"; + $task->team = ''; + foreach($this->post->team as $i => $account) + { + if(empty($account)) continue; + $task->team .= "{$this->lang->task->teamMember}: " . zget($users, $account) . ", {$this->lang->task->estimateAB}: " . zget($this->post->teamEstimate, $i, 0) . ", {$this->lang->task->consumedAB}: " . zget($this->post->teamConsumed, $i, 0) . ", {$this->lang->task->leftAB}: " . zget($this->post->teamLeft, $i, 0) . "\n"; + } + } + + $this->file->processFile4Object('task', $oldTask, $task); + return common::createChanges($oldTask, $task); } /**