From 6dad2f8c3f8be95ca16f134d73768f95103e0d55 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Sat, 12 Oct 2024 17:07:27 +0800 Subject: [PATCH] + [task#130251,doing,0.5h] add taskModel::syncStoryToChildren. --- module/task/model.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/module/task/model.php b/module/task/model.php index 9ae64a600d..5906c37768 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -175,6 +175,8 @@ class taskModel extends model $feedbacks[$oldTask->feedback] = $oldTask->feedback; $this->feedback->updateStatus('task', $oldTask->feedback, $task->status, $oldTask->status); } + + if(!empty($task->story) && !empty($task->parent) && $task->parent == '-1' && $this->post->syncChildren) $this->syncStoryToChildren($task); } return !dao::isError(); @@ -397,6 +399,8 @@ class taskModel extends model if(!empty($task->parent)) $this->updateParent($task, $isParentChanged); if($this->config->edition != 'open' && $oldTask->feedback) $this->loadModel('feedback')->updateStatus('task', $oldTask->feedback, $task->status, $oldTask->status); if(!empty($oldTask->mode) && empty($task->mode)) $this->dao->delete()->from(TABLE_TASKTEAM)->where('task')->eq($task->id)->exec(); + + if(!empty($task->story) && $this->post->syncChildren) $this->syncStoryToChildren($task); } /** @@ -3367,6 +3371,21 @@ class taskModel extends model return $this->dao->select('id,name')->from(TABLE_TASK)->where('execution')->eq($execution)->andWhere('status')->ne('closed')->andWhere('deleted')->eq('0')->fetchPairs(); } + public function syncStoryToChildren(object $task): bool + { + $nonStoryTasks = $this->dao->select('id,story')->from(TABLE_TASK)->where('parent')->eq($task->id)->andWhere('deleted')->eq('0')->andWhere('story')->eq(0)->fetchPairs(); + $taskStory = $this->loadModel('story')->fetchByID($task->story); + $this->loadModel('action'); + foreach($nonStoryTasks as $id => $story) + { + $this->dao->update(TABLE_TASK)->set('story')->eq($task->story)->set('storyVersion')->eq($taskStory->version)->where('id')->eq($id)->exec(); + + $changes = array(array('field' => 'story', 'old' => $story, 'new' => $task->story, 'diff' => '')); + $actionID = $this->action->create('task', $id, 'syncStoryByParentTask'); + $this->action->logHistory($actionID, $changes); + } + } + /** * 获取子任务 * Get child tasks