From e167c296910c40310efee8f392fb6ffe89798103 Mon Sep 17 00:00:00 2001 From: zhaoke Date: Wed, 24 May 2023 20:52:49 +0800 Subject: [PATCH] * Refactore batchAssignTo function. --- module/task/control.php | 10 +++------- module/task/model.php | 11 +++++++---- module/task/zen.php | 1 + 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/module/task/control.php b/module/task/control.php index 240d4cfbcd..fa2fd25094 100755 --- a/module/task/control.php +++ b/module/task/control.php @@ -287,20 +287,16 @@ class task extends control { if(!is_array($this->post->taskIDList)) return print(js::locate($this->createLink('execution', 'task', "executionID={$executionID}"), 'parent')); - $this->loadModel('action'); $taskData = $this->taskZen->buildTasksForBatchAssignTo($this->post->taskIDList, $this->post->assignedTo); - foreach($taskData as $taskID => $task) + foreach($taskData as $task) { /* Assign task. */ - $changes = $this->task->assign($task); + $this->task->assign($task); if(dao::isError()) return print(js::error(dao::getError())); - - /* Record log. */ - $actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo); - $this->action->logHistory($actionID, $changes); } if(!dao::isError()) $this->loadModel('score')->create('ajax', 'batchOther'); + return print(js::reload('parent')); } } diff --git a/module/task/model.php b/module/task/model.php index d154387d6f..25dc730110 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -392,6 +392,7 @@ class taskModel extends model } /** + * 更新父任务的状态. * Update parent status by taskID. * * @param $taskID @@ -401,7 +402,7 @@ class taskModel extends model */ public function updateParentStatus($taskID, $parentID = 0, $createAction = true) { - $childTask = $this->dao->select('*')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch(); + $childTask = $this->dao->select('id,assignedTo,parent')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch(); if(empty($parentID)) $parentID = $childTask->parent; if($parentID <= 0) return true; @@ -1131,7 +1132,7 @@ class taskModel extends model $oldTask = $this->getById($task->id); /* Check task left. */ - if($oldTask->status != 'done' and $oldTask->status != 'closed' and isset($task->left) and $task->left == 0) + if(!in_array($oldTask->status, array('done', 'closed')) && isset($task->left) && $task->left == 0) { dao::$errors['left'] = sprintf($this->lang->error->notempty, $this->lang->task->left); return false; @@ -1149,11 +1150,13 @@ class taskModel extends model if(dao::isError()) return false; + $changes = common::createChanges($oldTask, $task); + /* Record log. */ - $actionID = $this->loadModel('action')->create('task', $taskID, 'Assigned', $this->post->comment, $task->assignedTo); + $actionID = $this->loadModel('action')->create('task', $task->id, 'Assigned', $this->post->comment, $task->assignedTo); $this->action->logHistory($actionID, $changes); - return common::createChanges($oldTask, $task); + return $changes; } /** diff --git a/module/task/zen.php b/module/task/zen.php index 9601f5c06c..5d1fa5dd06 100644 --- a/module/task/zen.php +++ b/module/task/zen.php @@ -424,6 +424,7 @@ class taskZen extends task $prepareTasks[] = clone $prepareTask; } + return $prepareTasks; }