From 56ab6327c2ef646cd02e5577e4575c21824c8b3e Mon Sep 17 00:00:00 2001 From: tianshujie Date: Wed, 24 May 2023 13:57:12 +0800 Subject: [PATCH] * Refactor batch create method and add test case for batch create task. --- module/task/config/form.php | 31 +-- module/task/control.php | 64 ++--- module/task/model.php | 169 +++++-------- module/task/tao.php | 60 +++-- module/task/test/model/afterbatchcreate.php | 25 ++ module/task/test/model/aftersplittask.php | 14 +- module/task/test/model/afterstart.php | 0 module/task/test/model/batchcreate.php | 223 ++++-------------- module/task/test/model/canoperateeffort.php | 0 .../model/checkeeststartedanddeadline.php | 0 .../test/model/checkrequired4batchcreate.php | 198 ---------------- module/task/test/model/createmultitask.php | 0 module/task/test/model/createtaskofaffair.php | 0 module/task/test/model/createtaskoftest.php | 0 module/task/test/model/getteambyaccount.php | 0 .../test/model/updatekanban4batchcreate.php | 33 --- module/task/test/model/updatekanbancell.php | 0 module/task/test/model/updatekanbandata.php | 0 .../test/model/updatekanbanforbatchcreate.php | 33 +++ module/task/test/model/updateteam.php | 0 .../test/model/yaml/activate/kanbancell.yaml | 0 .../model/yaml/activate/kanbancolumn.yaml | 0 .../test/model/yaml/activate/kanbanlane.yaml | 0 .../model/yaml/activate/kanbanregion.yaml | 0 .../model/yaml/afterbatchcreate/project.yaml | 19 ++ .../model/yaml/afterbatchcreate/task.yaml | 22 ++ .../model/yaml/aftersplittask/action.yaml | 0 .../test/model/yaml/aftersplittask/task.yaml | 2 + .../model/yaml/afterstart/kanbancell.yaml | 0 .../model/yaml/afterstart/kanbancolumn.yaml | 0 .../model/yaml/afterstart/kanbanlane.yaml | 0 .../model/yaml/afterstart/kanbanregion.yaml | 0 .../yaml/batchchangemodule/execution.yaml | 0 .../model/yaml/batchchangemodule/task.yaml | 0 .../model/yaml/batchcreate/kanbancell.yaml | 14 +- .../model/yaml/batchcreate/kanbancolumn.yaml | 20 ++ .../model/yaml/batchcreate/kanbanlane.yaml | 22 ++ .../test/model/yaml/batchcreate/project.yaml | 88 +------ .../test/model/yaml/batchcreate/task.yaml | 22 ++ .../checkrequired4batchcreate/project.yaml | 31 --- .../task_computebeginandend.yaml | 0 .../task_computeworkinghours.yaml | 0 .../model/yaml/createmultitask/project.yaml | 0 .../yaml/createtaskofaffair/project.yaml | 0 .../model/yaml/createtaskoftest/project.yaml | 0 .../model/yaml/createtaskoftest/story.yaml | 0 .../project_isnostoryexecution.yaml | 0 .../managetaskteam/effort_managetaskteam.yaml | 0 .../taskteam_managetaskteam.yaml | 0 .../updatekanban4batchcreate/kanbancell.yaml | 0 .../kanbancolumn.yaml | 0 .../updatekanban4batchcreate/project.yaml | 0 .../yaml/updatekanban4batchcreate/task.yaml | 0 .../kanbancell_updatekanbancell.yaml | 0 .../kanbancolumn_updatekanbancell.yaml | 0 .../kanbanlane_updatekanbancell.yaml | 0 .../kanbanregion_updatekanbancell.yaml | 0 .../yaml/updatekanbandata/kanbancell.yaml | 0 .../yaml/updatekanbandata/kanbancolumn.yaml | 0 .../yaml/updatekanbandata/kanbanlane.yaml | 0 .../model/yaml/updatekanbandata/project.yaml | 0 .../model/yaml/updatekanbandata/task.yaml | 0 module/task/test/tao/copytaskdata.php | 25 ++ module/task/test/tao/setteammember.php | 0 module/task/test/tao/splitconsumedtask.php | 25 -- .../task_checkhaschildren.yaml | 0 .../effort.yaml | 0 .../task.yaml | 0 .../effort_managetaskteammember.yaml | 0 .../taskteam_managetaskteammember.yaml | 0 module/task/test/task.class.php | 136 ++++++----- module/task/zen.php | 219 +++++++++-------- test/data/kanbancolumn.yaml | 2 +- test/data/kanbanlane.yaml | 2 - test/data/taskspec.yaml | 14 -- 75 files changed, 583 insertions(+), 930 deletions(-) create mode 100644 module/task/test/model/afterbatchcreate.php mode change 100644 => 100755 module/task/test/model/afterstart.php mode change 100644 => 100755 module/task/test/model/canoperateeffort.php mode change 100644 => 100755 module/task/test/model/checkeeststartedanddeadline.php delete mode 100755 module/task/test/model/checkrequired4batchcreate.php mode change 100644 => 100755 module/task/test/model/createmultitask.php mode change 100644 => 100755 module/task/test/model/createtaskofaffair.php mode change 100644 => 100755 module/task/test/model/createtaskoftest.php mode change 100644 => 100755 module/task/test/model/getteambyaccount.php delete mode 100755 module/task/test/model/updatekanban4batchcreate.php mode change 100644 => 100755 module/task/test/model/updatekanbancell.php mode change 100644 => 100755 module/task/test/model/updatekanbandata.php create mode 100755 module/task/test/model/updatekanbanforbatchcreate.php mode change 100644 => 100755 module/task/test/model/updateteam.php mode change 100644 => 100755 module/task/test/model/yaml/activate/kanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/activate/kanbancolumn.yaml mode change 100644 => 100755 module/task/test/model/yaml/activate/kanbanlane.yaml mode change 100644 => 100755 module/task/test/model/yaml/activate/kanbanregion.yaml create mode 100755 module/task/test/model/yaml/afterbatchcreate/project.yaml create mode 100755 module/task/test/model/yaml/afterbatchcreate/task.yaml mode change 100644 => 100755 module/task/test/model/yaml/aftersplittask/action.yaml mode change 100644 => 100755 module/task/test/model/yaml/aftersplittask/task.yaml mode change 100644 => 100755 module/task/test/model/yaml/afterstart/kanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/afterstart/kanbancolumn.yaml mode change 100644 => 100755 module/task/test/model/yaml/afterstart/kanbanlane.yaml mode change 100644 => 100755 module/task/test/model/yaml/afterstart/kanbanregion.yaml mode change 100644 => 100755 module/task/test/model/yaml/batchchangemodule/execution.yaml mode change 100644 => 100755 module/task/test/model/yaml/batchchangemodule/task.yaml mode change 100644 => 100755 module/task/test/model/yaml/batchcreate/kanbancell.yaml create mode 100755 module/task/test/model/yaml/batchcreate/kanbancolumn.yaml create mode 100755 module/task/test/model/yaml/batchcreate/kanbanlane.yaml mode change 100644 => 100755 module/task/test/model/yaml/batchcreate/project.yaml create mode 100755 module/task/test/model/yaml/batchcreate/task.yaml delete mode 100644 module/task/test/model/yaml/checkrequired4batchcreate/project.yaml mode change 100644 => 100755 module/task/test/model/yaml/computebeginandend/task_computebeginandend.yaml mode change 100644 => 100755 module/task/test/model/yaml/computeworkinghours/task_computeworkinghours.yaml mode change 100644 => 100755 module/task/test/model/yaml/createmultitask/project.yaml mode change 100644 => 100755 module/task/test/model/yaml/createtaskofaffair/project.yaml mode change 100644 => 100755 module/task/test/model/yaml/createtaskoftest/project.yaml mode change 100644 => 100755 module/task/test/model/yaml/createtaskoftest/story.yaml mode change 100644 => 100755 module/task/test/model/yaml/isnostoryexecution/project_isnostoryexecution.yaml mode change 100644 => 100755 module/task/test/model/yaml/managetaskteam/effort_managetaskteam.yaml mode change 100644 => 100755 module/task/test/model/yaml/managetaskteam/taskteam_managetaskteam.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanban4batchcreate/kanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanban4batchcreate/kanbancolumn.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanban4batchcreate/project.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanban4batchcreate/task.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbancell/kanbancell_updatekanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbancell/kanbancolumn_updatekanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbancell/kanbanlane_updatekanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbancell/kanbanregion_updatekanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbandata/kanbancell.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbandata/kanbancolumn.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbandata/kanbanlane.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbandata/project.yaml mode change 100644 => 100755 module/task/test/model/yaml/updatekanbandata/task.yaml create mode 100755 module/task/test/tao/copytaskdata.php mode change 100644 => 100755 module/task/test/tao/setteammember.php delete mode 100755 module/task/test/tao/splitconsumedtask.php mode change 100644 => 100755 module/task/test/tao/yaml/checkhaschildren/task_checkhaschildren.yaml rename module/task/test/tao/yaml/{splitconsumedtask => copytaskdata}/effort.yaml (100%) mode change 100644 => 100755 rename module/task/test/tao/yaml/{splitconsumedtask => copytaskdata}/task.yaml (100%) mode change 100644 => 100755 mode change 100644 => 100755 module/task/test/tao/yaml/managetaskteammember/effort_managetaskteammember.yaml mode change 100644 => 100755 module/task/test/tao/yaml/managetaskteammember/taskteam_managetaskteammember.yaml mode change 100644 => 100755 module/task/test/task.class.php diff --git a/module/task/config/form.php b/module/task/config/form.php index 7985d2127d..4be16c61bc 100644 --- a/module/task/config/form.php +++ b/module/task/config/form.php @@ -106,20 +106,23 @@ $config->task->form->batchEdit['closedReasons'] = array('type' => 'array', 'requ $config->task->form->batchEdit['deadlines'] = array('type' => 'array', 'required' => false, 'default' => array()); $config->task->form->batchEdit['pris'] = array('type' => 'array', 'required' => false, 'default' => array()); -$config->task->form->batchCreate = common::formConfig('task', 'batchCreate'); -$config->task->form->batchCreate['module'] = array('type' => 'int', 'required' => false, 'default' => 0); -$config->task->form->batchCreate['parent'] = array('type' => 'int', 'required' => false, 'default' => 0); -$config->task->form->batchCreate['story'] = array('type' => 'int', 'required' => false, 'default' => 0); -$config->task->form->batchCreate['name'] = array('type' => 'string', 'required' => false, 'default' => '', 'base' => true); -$config->task->form->batchCreate['color'] = array('type' => 'string', 'required' => false, 'default' => ''); -$config->task->form->batchCreate['type'] = array('type' => 'string', 'required' => false, 'default' => ''); -$config->task->form->batchCreate['version'] = array('type' => 'int', 'required' => false, 'default' => 1); -$config->task->form->batchCreate['assignedTo'] = array('type' => 'string', 'required' => false, 'default' => ''); -$config->task->form->batchCreate['estimate'] = array('type' => 'float', 'required' => false, 'default' => 0); -$config->task->form->batchCreate['estStarted'] = array('type' => 'date', 'required' => false, 'default' => ''); -$config->task->form->batchCreate['deadline'] = array('type' => 'date', 'required' => false, 'default' => ''); -$config->task->form->batchCreate['desc'] = array('type' => 'string', 'required' => false, 'default' => ''); -$config->task->form->batchCreate['pri'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->task->form->batchcreate = common::formConfig('task', 'batchCreate'); +$config->task->form->batchcreate['module'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->task->form->batchcreate['parent'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->task->form->batchcreate['story'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->task->form->batchcreate['name'] = array('type' => 'string', 'required' => false, 'default' => '', 'base' => true); +$config->task->form->batchcreate['color'] = array('type' => 'string', 'required' => false, 'default' => ''); +$config->task->form->batchcreate['type'] = array('type' => 'string', 'required' => false, 'default' => ''); +$config->task->form->batchcreate['version'] = array('type' => 'int', 'required' => false, 'default' => 1); +$config->task->form->batchcreate['assignedTo'] = array('type' => 'string', 'required' => false, 'default' => ''); +$config->task->form->batchcreate['estimate'] = array('type' => 'float', 'required' => false, 'default' => 0); +$config->task->form->batchcreate['estStarted'] = array('type' => 'date', 'required' => false, 'default' => null); +$config->task->form->batchcreate['deadline'] = array('type' => 'date', 'required' => false, 'default' => null); +$config->task->form->batchcreate['desc'] = array('type' => 'string', 'required' => false, 'default' => ''); +$config->task->form->batchcreate['pri'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->task->form->batchcreate['laneID'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->task->form->batchcreate['openedBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account); +$config->task->form->batchcreate['openedDate'] = array('type' => 'string', 'required' => false, 'default' => $now); $config->task->form->pause = array(); $config->task->form->pause['lastEditedBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account); diff --git a/module/task/control.php b/module/task/control.php index 084390dc57..4572e5eb6b 100755 --- a/module/task/control.php +++ b/module/task/control.php @@ -54,41 +54,37 @@ class task extends control $execution = $this->execution->getById($executionID); /* Check whether the execution has permission to create tasks. */ - $limitedExecutions = (string)$this->execution->getLimitedExecution(); - if(strpos(",{$limitedExecutions},", ",{$executionID},") !== false) - { - return $this->send(array('load' => $this->createLink('execution', 'task', "executionID={$executionID}"), 'message' => $this->lang->task->createDenied)); - } + if($this->taskZen->isLimitedInExecution($executionID)) return $this->send(array('load' => $this->createLink('execution', 'task', "executionID={$executionID}"), 'message' => $this->lang->task->createDenied)); /* Submit the data process after create the task form. */ if(!empty($_POST)) { - $task = $this->taskZen->buildTaskForCreate($executionID); + $taskData = $this->taskZen->buildTaskForCreate($this->post->execution); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); /* Check whether a task with the same name is created within the specified time. */ - $duplicateTaskID = $this->taskZen->checkDuplicateName($task); + $duplicateTaskID = $this->taskZen->checkDuplicateName($taskData); if($duplicateTaskID) return $this->send(array('result' => 'success', 'message' => sprintf($this->lang->duplicate, $this->lang->task->common), 'load' => $this->createLink('task', 'view', "taskID={$duplicateTaskID}"))); $this->dao->begin(); if($this->post->type == 'test') { /* Prepare to create the data for the test subtask and to check the data format. */ - $testTasks = $this->taskZen->buildTestTasksForCreate($task->execution); - $taskIdList = $this->task->createTaskOfTest($task, $testTasks); + $testTasks = $this->taskZen->buildTestTasksForCreate($taskData->execution); + $taskIdList = $this->task->createTaskOfTest($taskData, $testTasks); } elseif($this->post->type == 'affair') { - $taskIdList = $this->task->createTaskOfAffair($task, $this->post->assignedTo); + $taskIdList = $this->task->createTaskOfAffair($taskData, $this->post->assignedTo); } elseif($this->post->multiple) { $teamData = form::data($config->task->form->team->create)->get(); - $taskIdList = $this->task->createMultiTask($task, $teamData); + $taskIdList = $this->task->createMultiTask($taskData, $teamData); } else { - $taskIdList = $this->task->create($task); + $taskIdList = $this->task->create($taskData); } if(dao::isError()) @@ -102,12 +98,12 @@ class task extends control $columnID = isset($output['columnID']) ? (int)$output['columnID'] : 0; $taskIdList = (array)$taskIdList; $task->id = current($taskIdList); - $this->task->afterCreate($task, $taskIdList, $bugID, $todoID); - $this->task->updateKanbanData($task->execution, $taskIdList, (int)$this->post->lane, $columnID); + $this->task->afterCreate($taskData, $taskIdList, $bugID, $todoID); + $this->task->updateKanbanData($taskData->execution, $taskIdList, (int)$this->post->lane, $columnID); helper::setcookie('lastTaskModule', (int)$this->post->module); /* Get the information returned after a task is created. */ - $response = $this->taskZen->responseAfterCreate($task, $execution, $this->post->after); + $response = $this->taskZen->responseAfterCreate($taskData, $execution, $this->post->after); return $this->send($response); } @@ -129,49 +125,33 @@ class task extends control */ public function batchCreate(int $executionID, int $storyID = 0, int $moduleID = 0, int $taskID = 0, string $cardPosition = '') { - /* Init vars. */ + /* Analytic parameter. */ $cardPosition = str_replace(array(',', ' '), array('&', ''), $cardPosition); parse_str($cardPosition, $output); - /* 判断不能访问的执行。 Judge execution without access. */ - if($this->taskZen->isLimitedInExecution($executionID)) - { - echo js::alert($this->lang->task->createDenied); - return print(js::locate($this->createLink('execution', 'task', "executionID=$executionID"))); - } + /* Check whether the execution has permission to create tasks. */ + if($this->taskZen->isLimitedInExecution($executionID)) return $this->send(array('load' => $this->createLink('execution', 'task', "executionID={$executionID}"), 'message' => $this->lang->task->createDenied)); $execution = $this->execution->getById($executionID); if(!empty($_POST)) { - /* 批量创建任务。 Batch create tasks. */ - $taskData = $this->taskZen->buildTasksForBatchCreate($executionID, $taskID); + /* Process the request data for the batch create tasks. */ + $taskData = $this->taskZen->buildTasksForBatchCreate($execution, $taskID, $output); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - $taskIdList = $this->task->batchCreate($execution, $taskData, $taskID, $output); + $taskIdList = $this->task->batchCreate($taskData, $output); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - /* 接口调用返回任务编号列表。 Return task id list when call the API. */ - if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $taskIdList)); + /* Update other data related to the task after it is created. */ + $this->task->afterBatchCreate($taskIdList); + if(!isset($output['laneID']) or !isset($output['columnID'])) $this->loadModel('kanban')->updateLane($executionID, 'task'); - /* 生成跳转链接。 Generate jump link. */ - $jumpLink = $this->taskZen->getJumpLink($execution); - if(!isonlybody()) return $this->send(array('result' => 'success', 'load' => $jumpLink)); - - /* 执行应用下或者在运营管理界面下更新看板数据。 */ - /* Update kanban data under the execution application or under the operation management interface. */ - if($this->app->tab == 'execution' or $this->config->vision == 'lite') - { - $kanbanData = $this->taskZen->getKanbanData($execution); - if($execution->type == 'kanban') return print(js::closeModal('parent.parent', '', "parent.parent.updateKanban($kanbanData, 0)")); - return print(js::closeModal('parent.parent', '', "parent.parent.updateKanban(\"task\", $kanbanData)")); - } - - return $this->send(array('result' => 'success', 'load' => 'true')); + $response = $this->taskZen->responseAfterbatchCreate($taskIdList, $execution); + return $this->send($response); } $this->taskZen->setMenu($executionID); - $this->taskZen->buildBatchCreateForm($execution, $storyID, $moduleID, $taskID, $output); } diff --git a/module/task/model.php b/module/task/model.php index bda4e88816..8ffc9e37e8 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -149,57 +149,71 @@ class taskModel extends model * 批量创建任务。 * Batch create tasks. * - * @param object $execution - * @param array $tasks - * @param int $parentID - * @param array $output + * @param array $tasks + * @param array $output * @access public * @return array|false */ - public function batchCreate(object $execution, array $tasks, int $parentID, array $output): array|false + public function batchCreate(array $tasks, array $output): array|false { - /* 检查必填项。 Check required fields. */ - $tasks = $this->checkRequired4BatchCreate($execution, $tasks); - if(!$tasks) return false; - - /* 加载模块。 Load module. */ $this->loadModel('story'); - $this->loadModel('score'); - $this->loadModel('action'); - $oldParentTask = $this->dao->findById((int)$parentID)->from(TABLE_TASK)->fetch(); - - $taskIdList = array(); + $parentID = !empty($tasks) ? current($tasks)->parent : 0; + $oldParentTask = $this->dao->findById($parentID)->from(TABLE_TASK)->fetch(); + $executionID = !empty($tasks) ? current($tasks)->execution : 0; + $execution = $this->loadModel('execution')->getById($executionID); + $taskIdList = array(); foreach($tasks as $task) { - /* 获取当前任务所属泳道并移除laneID属性。 Get the current laneID and remove the laneID from task object. */ - $laneID = isset($output['laneID']) ? $output['laneID'] : 0; - $laneID = isset($task->laneID) ? $task->laneID : $laneID; - if(isset($task->laneID)) unset($task->laneID); + /* Get the lane and column of the current task. */ + $laneID = $task->laneID; + $columnID = isset($output['columnID']) ? $output['columnID'] : 0; + unset($task->laneID); - /* 将数据插入到任务表中。 Insert the tasks. */ + /* Create a task. */ $taskID = $this->create($task); if(!$taskID) return false; - /* 更新任务相关对象信息。 Update the related objects' info, such as story, kanban and so on. */ + /* Update Kanban and story stage. */ if($task->story) $this->story->setStage($task->story); - $columnID = isset($output['columnID']) ? $output['columnID'] : 0; - $this->updateKanban4BatchCreate($taskID, $execution->id, $laneID, $columnID); + $this->updateKanbanForBatchCreate($taskID, $executionID, $laneID, $columnID); - $this->executeHooks($taskID); $taskIdList[$taskID] = $taskID; } - if(!dao::isError()) $this->score->create('ajax', 'batchCreate'); // Updating scores for the first batch creation operation. - - /* 拆分任务后更新其他数据。 Process other data after split task. */ - $children = !empty($parentID) ? implode(',', $taskIdList) : ''; - if($parentID && $taskID) $this->afterSplitTask($oldParentTask, $children); - - /* 更新当前执行下的任务泳道。 Update the task lane under current execution. */ - if(!isset($output['laneID']) or !isset($output['columnID'])) $this->kanban->updateLane($execution->id, 'task'); return $taskIdList; } + /** + * 批量创建任务后的其他数据处理。 + * Other data process after task batch create. + * + * @param array $taskIdList + * @param int $parentID + * @access public + * @return bool + */ + public function afterBatchCreate(array $taskIdList, int $parentID = 0): bool + { + $this->loadModel('action'); + $this->loadModel('score'); + foreach($taskIdList as $taskID) + { + $this->executeHooks($taskID); + $this->action->create('task', $taskID, 'Opened', ''); + $this->score->create('task', 'create', $taskID); + } + + /* Process other data after split task. */ + if($parentID && empty($taskIdList)) + { + $childrenIdList = !empty($parentID) ? $taskIdList : array(); + $parentTask = $this->getByID($parentID); + $this->afterSplitTask($parentTask, $childrenIdList); + } + + return !dao::isError(); + } + /** * Create task from gitlab issue. * @@ -453,7 +467,7 @@ class taskModel extends model $task->assignedTo = $parentTask->openedBy; $task->assignedDate = $now; $task->finishedBy = ''; - $task->finishedDate = ''; + $task->finishedDate = null; $task->canceledBy = $this->app->user->account; $task->canceledDate = $now; } @@ -475,9 +489,9 @@ class taskModel extends model $task->assignedDate = $now; } $task->finishedBy = ''; - $task->finishedDate = ''; + $task->finishedDate = null; $task->closedBy = ''; - $task->closedDate = ''; + $task->closedDate = null; $task->closedReason = ''; } @@ -3662,62 +3676,6 @@ class taskModel extends model } } - /** - * 批量创建前检查必填项。 - * Check required fields before batch create tasks. - * - * @param object $execution - * @param object[] $data - * @access public - * @return object[]|false - */ - public function checkRequired4BatchCreate(object $execution, array $data): array|false - { - /* 设置必填项。 */ - $requiredFields = ',' . $this->config->task->create->requiredFields . ','; - if($this->taskTao->isNoStoryExecution($execution)) $requiredFields = str_replace(',story,', ',', $requiredFields); - $requiredFields = trim($requiredFields, ','); - $requiredFields = array_filter(explode(',', $requiredFields)); - - /* check data. */ - foreach($data as $task) - { - /* 检查任务是否开启了起止日期必填的配置(limitTaskDate)。 */ - if(!empty($this->config->limitTaskDate)) - { - $this->checkEstStartedAndDeadline($execution->id, $task->estStarted, $task->deadline); - if(dao::isError()) return false; - } - - /* 检查任务截止日期是否为空以及是否小于预计开始日期。 */ - if(!helper::isZeroDate($task->deadline) && $task->deadline < $task->estStarted) - { - dao::$errors['message'][] = $this->lang->task->error->deadlineSmall; - return false; - } - - /* 检查任务预计是否为数字类型。 */ - if($task->estimate && !preg_match("/^[0-9]+(.[0-9]{1,3})?$/", $task->estimate)) - { - dao::$errors['message'][] = $this->lang->task->error->estimateNumber; - return false; - } - - /* 验证必填字段。 */ - foreach($requiredFields as $field) - { - if(empty($task->$field)) - { - dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->task->$field); - return false; - } - } - if($task->estimate) $task->estimate = (float)$task->estimate; - } - - return $data; - } - /** * 创建任务后的其他数据处理。 * Other data process after task create. @@ -3774,32 +3732,34 @@ class taskModel extends model * Process other data after split task. * * @param object $oldParentTask - * @param string $children + * @param array $childrenIdList * @access public * @return bool */ - public function afterSplitTask(object $oldParentTask, string $children = ''): bool + public function afterSplitTask(object $oldParentTask, array $childrenIdList = array()): bool { - $parentID = (int)$oldParentTask->id; - $oneOfChildren = current(explode(',', $children)); + $parentID = (int)$oldParentTask->id; - /* 当一个普通任务有消耗时,拆分子任务并更新父任务状态。 */ /* When a normal task is consumed, create the subtask and update the parent task status. */ if($oldParentTask->parent == 0 && $oldParentTask->consumed > 0) { - $inheritTask = $this->taskTao->splitConsumedTask($oldParentTask); - if(!$inheritTask) return false; + $this->taskTao->copyTaskData($oldParentTask); + if(dao::isError()) return false; } - $this->updateParentStatus($oneOfChildren); + $this->updateParentStatus(current($childrenIdList)); $this->computeBeginAndEnd($parentID); - $newParentTask = $this->dao->findById($parentID)->from(TABLE_TASK)->fetch(); + /* Create a action. */ + $extra = implode(',', $childrenIdList); + $actionID = $this->action->create('task', $parentID, 'createChildren', '', trim($extra, ',')); + + /* Create a log history. */ + $newParentTask = $this->getByID($parentID); $changes = common::createChanges($oldParentTask, $newParentTask); - $actionID = $this->action->create('task', $parentID, 'createChildren', '', trim($children, ',')); if(!empty($changes)) $this->action->logHistory($actionID, $changes); - return true; + return !dao::isError(); } /** @@ -3811,9 +3771,9 @@ class taskModel extends model * @param int $laneID * @param int $columnID * @access public - * @return void + * @return bool */ - public function updateKanban4BatchCreate(int $taskID, int $executionID, int $laneID, int $columnID): void + public function updateKanbanForBatchCreate(int $taskID, int $executionID, int $laneID, int $columnID): bool { $this->loadModel('kanban'); @@ -3826,6 +3786,7 @@ class taskModel extends model $columnID = $this->kanban->getColumnIDByLaneID($laneID, 'wait'); if(!empty($laneID) && !empty($columnID)) $this->kanban->addKanbanCell($executionID, $laneID, $columnID, 'task', $taskID); } + return !dao::isError(); } /** diff --git a/module/task/tao.php b/module/task/tao.php index d910157403..2de4481fbe 100644 --- a/module/task/tao.php +++ b/module/task/tao.php @@ -199,6 +199,35 @@ class taskTao extends taskModel } } + /** + * 复制任务数据。 + * Copy the task data and update the effort to the new task. + * + * @param object $parentTask + * @access protected + * @return bool + */ + protected function copyTaskData(object $task): bool + { + /* 复制当前任务信息。 */ + /* Copy the current task to child task, and change the parent field value. */ + $copyTask = clone $task; + $copyTask->parent = $task->id; + unset($copyTask->id); + + $copyTaskID = $this->dao->insert(TABLE_TASK)->data($copyTask)->autoCheck()->exec(); + if(dao::isError()) return false; + + /* 将父任务的日志记录更新到子任务下。 */ + /* Update the logs of the parent task under the subtask. */ + $this->dao->update(TABLE_EFFORT)->set('objectID')->eq($copyTaskID) + ->where('objectID')->eq($task->id) + ->andWhere('objectType')->eq('task') + ->exec(); + + return !dao::isError(); + } + /** * 更新一个任务。 * Update a task. @@ -464,37 +493,6 @@ class taskTao extends taskModel return $teamInfoList; } - /** - * 拆分已消耗的任务。 - * Split the consumed task. - * - * @param object $parentTask - * @access protected - * @return false|int - */ - protected function splitConsumedTask(object $parentTask): false|int - { - /* 复制当前任务信息。 */ - /* Copy the current task to child task, and change the parent field value. */ - $childTask = clone $parentTask; - $childTask->parent = $parentTask->id; - unset($childTask->id); - - $this->dao->insert(TABLE_TASK)->data($childTask)->autoCheck()->exec(); - if(dao::isError()) return false; - - /* 将父任务的日志记录更新到子任务下。 */ - /* Update the logs of the parent task under the subtask. */ - $childTaskID = $this->dao->lastInsertID(); - $this->dao->update(TABLE_EFFORT)->set('objectID')->eq($childTaskID) - ->where('objectID')->eq($parentTask->id) - ->andWhere('objectType')->eq('task') - ->exec(); - if(dao::isError()) return false; - - return (int)$childTaskID; - } - /** * 维护团队成员信息。 * Maintain team member information. diff --git a/module/task/test/model/afterbatchcreate.php b/module/task/test/model/afterbatchcreate.php new file mode 100644 index 0000000000..29b1a8c332 --- /dev/null +++ b/module/task/test/model/afterbatchcreate.php @@ -0,0 +1,25 @@ +#!/usr/bin/env php +config('project')->gen('5'); +zdTable('task')->config('task')->gen(8); +zdTable('taskspec')->gen(0); + +/** + +title=测试taskModel->afterBatchCreate(); +timeout=0 +cid=1 + +*/ + +$taskIdList = array(array(1, 2), array(3, 4), array(5, 6)); + +$taskTester = new taskTest(); + +r($taskTester->afterBatchCreateObject($taskIdList[0])) && p() && e('1'); // 测试批量创建迭代下的任务后的数据处理 +r($taskTester->afterBatchCreateObject($taskIdList[1])) && p() && e('1'); // 测试批量创建阶段下的任务后的数据处理 +r($taskTester->afterBatchCreateObject($taskIdList[2])) && p() && e('1'); // 测试批量创建看板下的任务后的数据处理 diff --git a/module/task/test/model/aftersplittask.php b/module/task/test/model/aftersplittask.php index 5a9667d373..468e89cb87 100755 --- a/module/task/test/model/aftersplittask.php +++ b/module/task/test/model/aftersplittask.php @@ -9,18 +9,18 @@ zdTable('action')->config('action')->gen(1); /** -title=taskModel->updateKanban4BatchCreate(); +title=taskModel->afterSplitTask(); timeout=0 cid=2 */ -$parentIdList = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); +$parentIdList = array('1', '3'); $task = new taskTest(); -r($task->afterSplitTaskTest($parentIdList[1], '2', 'children')) && p('9') && e('9'); // 测试如果父任务有工时消耗时是否成功克隆子任务。 -r($task->afterSplitTaskTest($parentIdList[1], '2', 'parent')) && p('status') && e('doing'); // 测试父任务状态是否改变。 -r($task->afterSplitTaskTest($parentIdList[3], '4', 'parentAction')) && p('actionID') && e('5'); // 测试父任务动态是否创建成功。 -r($task->afterSplitTaskTest($parentIdList[3], '4', 'parentEstStarted')) && p() && e('2021-01-09'); // 测试父任务预计开始时间是否更新。 -r($task->afterSplitTaskTest($parentIdList[3], '4', 'parentDeadline')) && p() && e('2021-01-23'); // 测试父任务截止时间是否更新。 +r($task->afterSplitTaskTest($parentIdList[0], array('2'), 'children')) && p('9') && e('9'); // 测试如果父任务有工时消耗时是否成功克隆子任务。 +r($task->afterSplitTaskTest($parentIdList[0], array('2'), 'parent')) && p('status') && e('doing'); // 测试父任务状态是否改变。 +r($task->afterSplitTaskTest($parentIdList[1], array('4'), 'parentAction')) && p('actionID') && e('6'); // 测试父任务动态是否创建成功。 +r($task->afterSplitTaskTest($parentIdList[1], array('4'), 'parentEstStarted')) && p() && e('2021-01-09'); // 测试父任务预计开始时间是否更新。 +r($task->afterSplitTaskTest($parentIdList[1], array('4'), 'parentDeadline')) && p() && e('2021-01-23'); // 测试父任务截止时间是否更新。 diff --git a/module/task/test/model/afterstart.php b/module/task/test/model/afterstart.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/batchcreate.php b/module/task/test/model/batchcreate.php index 12d2da119f..432dc9847b 100755 --- a/module/task/test/model/batchcreate.php +++ b/module/task/test/model/batchcreate.php @@ -4,191 +4,68 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/task.class.php'; su('admin'); -zdTable('project')->config('project')->gen('10'); -zdTable('kanbancell')->config('kanbancell')->gen('10'); - -$story = zdTable('story'); -$story->id->range('1'); -$story->product->range('1'); -$story->title->range('需求1'); -$story->type->range('story'); -$story->version->range('1'); -$story->status->range('active'); -$story->stage->range('projected'); -$story->reviewedDate->range('(-1M)-(+1w):60m')->type('timestamp')->format('YY/MM/DD'); -$story->lastEditedDate->range('(-1M)-(+1w):60m')->type('timestamp')->format('YY/MM/DD'); -$story->gen('1'); - -$storyspec = zdTable('storyspec'); -$storyspec->story->range('1'); -$storyspec->version->range('1'); -$storyspec->title->range('需求1'); -$storyspec->spec->range('storyspec1'); -$storyspec->gen('1'); - -$task = zdTable('task'); -$task->id->range('1'); -$task->name->range('任务1'); -$task->execution->range('2'); -$task->type->range('devel'); -$task->status->range('wait'); -$task->parent->range("`-1`"); -$task->gen('1'); - -$taskspec = zdTable('taskspec'); -$taskspec->task->range('1'); -$taskspec->version->range('1'); -$taskspec->name->range('任务一'); -$taskspec->gen('1'); +zdTable('project')->config('project')->gen('5'); +zdTable('task')->config('task')->gen(8); +zdTable('taskspec')->gen(0); +zdTable('kanbanlane')->config('kanbanlane')->gen(10); +zdTable('kanbancolumn')->config('kanbancolumn')->gen(18); +zdTable('kanbancell')->config('kanbancell')->gen(18); /** title=测试taskModel->batchCreate(); +timeout=0 cid=1 -pid=1 - */ -$executionIdList = array(2); +$testTasks = array(array('type' => 'test', 'name' => '测试任务1'), array('type' => 'test', 'name' => '测试任务2')); +$storyTasks = array(array('type' => 'story', 'story' => 1, 'name' => '需求任务1'), array('type' => 'story', 'story' => 1, 'name' => '需求任务2')); +$childTasks = array(array('type' => 'devel', 'parent' => 1, 'name' => '任务1子任务1'), array('type' => 'devel', 'parent' => 1, 'name' => '任务2子任务1')); -$laneIdList = array(1, 2, 3); -$columnIdList = array(1, 2, 3); +$taskTester = new taskTest(); -$parent = array(0, 0, 0, 0, 1); -$module = array(1, 2, 3, 4, 5); -$story = array(1, 0); -$storyEstimate = array(1, 2, 1, 2, 1); -$storyDesc = array('storyDesc1', 'storyDesc2', 'storyDesc3', '', ''); -$storyPri = array(3, 3, 1, 2, 4); -$name = array('task1', 'task2', 'task3', 'task4', ''); -$color = array('', 'red', 'green', '', 'gray'); -$type = array('devel', 'request', 'design', 'test', 'study', 'discuss', 'ui', 'affair', 'misc'); -$assignedTo = array('admin', 'admin', 'dev1', 'dev2', 'admin'); -$estimate = array('1', '2', '3', '1', '1'); -$estStarted = array('2022-07-01', '2023-05-08', '', '2023-09-09', ''); -$deadline = array('2023-02-01', '2022-06-02', '', '', ''); -$desc = array('', 'taskDesc', 'taskAAA', '', ''); -$pri = array('1', '2', '3', '3', '1'); +$output[] = array('laneID' => 1, 'columnID' => 1); +$output[] = array('laneID' => 2, 'columnID' => 7); +$output[] = array('laneID' => 3, 'columnID' => 13); +$testTaskList[] = $taskTester->batchCreateObject($testTasks); +$storyTaskList[] = $taskTester->batchCreateObject($storyTasks); +$childTaskList[] = $taskTester->batchCreateObject($childTasks); +$kanbanTaskList[] = $taskTester->batchCreateObject($testTasks, 'sprint', $output[0]); -$withoutNameTask = array(); -$withoutNameTask[1] = new stdclass(); -$withoutNameTask[1]->execution = $executionIdList[0]; -$withoutNameTask[1]->parent = $parent[0]; -$withoutNameTask[1]->module = $module[0]; -$withoutNameTask[1]->name = $name[4]; -$withoutNameTask[1]->deadline = $deadline[0]; -$withoutNameTask[1]->estimate = $estimate[0]; -$withoutNameTask[1]->estStarted = $estStarted[0]; +$testTaskList[] = $taskTester->batchCreateObject($testTasks, 'stage'); +$storyTaskList[] = $taskTester->batchCreateObject($storyTasks, 'stage'); +$childTaskList[] = $taskTester->batchCreateObject($childTasks, 'stage'); +$kanbanTaskList[] = $taskTester->batchCreateObject($testTasks, 'stage', $output[1]); -$normalTaskList = array(); -$normalTaskList[1] = new stdclass(); -$normalTaskList[1]->execution = $executionIdList[0]; -$normalTaskList[1]->parent = $parent[0]; -$normalTaskList[1]->module = $module[0]; -$normalTaskList[1]->story = $story[0]; -$normalTaskList[1]->name = $name[0]; -$normalTaskList[1]->version = 1; -$normalTaskList[1]->type = $type[0]; -$normalTaskList[1]->deadline = $deadline[0]; -$normalTaskList[1]->estimate = $estimate[0]; -$normalTaskList[1]->estStarted = $estStarted[0]; -$normalTaskList[1]->mailto = ''; +$testTaskList[] = $taskTester->batchCreateObject($testTasks, 'kanban'); +$storyTaskList[] = $taskTester->batchCreateObject($storyTasks, 'kanban'); +$childTaskList[] = $taskTester->batchCreateObject($childTasks, 'kanban'); +$kanbanTaskList[] = $taskTester->batchCreateObject($testTasks, 'kanban', $output[2]); -$normalTaskList[2] = new stdclass(); -$normalTaskList[2]->execution = $executionIdList[0]; -$normalTaskList[2]->parent = $parent[1]; -$normalTaskList[2]->module = $module[1]; -$normalTaskList[2]->story = $story[1]; -$normalTaskList[2]->name = $name[1]; -$normalTaskList[2]->color = $color[1]; -$normalTaskList[2]->type = $type[1]; -$normalTaskList[2]->version = 1; -$normalTaskList[2]->assignedTo = $assignedTo[1]; -$normalTaskList[2]->estimate = $estimate[1]; -$normalTaskList[2]->estStarted = $estStarted[1]; -$normalTaskList[2]->deadline = $deadline[2]; -$normalTaskList[2]->desc = $desc[1]; -$normalTaskList[2]->pri = $pri[1]; -$normalTaskList[2]->mailto = ''; +r(current($testTaskList[0])) && p() && e('9'); // 测试批量创建迭代下测试任务 +r(count($testTaskList[0])) && p() && e('2'); // 测试批量创建迭代下测试任务 +r(current($storyTaskList[0])) && p() && e('11'); // 测试批量创建迭代下需求任务 +r(count($storyTaskList[0])) && p() && e('2'); // 测试批量创建迭代下需求任务 +r(current($childTaskList[0])) && p() && e('13'); // 测试批量创建迭代下任务1子任务 +r(count($childTaskList[0])) && p() && e('2'); // 测试批量创建迭代下任务1子任务 +r(current($kanbanTaskList[0])) && p() && e('15'); // 测试批量创建迭代下测试任务并更新看板 +r(count($kanbanTaskList[0])) && p() && e('2'); // 测试批量创建迭代下测试任务并更新看板 -$hasParentTask = array(); -$hasParentTask[1] = new stdclass(); -$hasParentTask[1]->execution = $executionIdList[0]; -$hasParentTask[1]->parent = $parent[4]; -$hasParentTask[1]->module = $module[1]; -$hasParentTask[1]->story = $story[1]; -$hasParentTask[1]->name = $name[1]; -$hasParentTask[1]->color = $color[1]; -$hasParentTask[1]->type = $type[1]; -$hasParentTask[1]->version = 1; -$hasParentTask[1]->assignedTo = $assignedTo[1]; -$hasParentTask[1]->estimate = $estimate[1]; -$hasParentTask[1]->estStarted = $estStarted[1]; -$hasParentTask[1]->deadline = $deadline[2]; -$hasParentTask[1]->desc = $desc[1]; -$hasParentTask[1]->pri = $pri[1]; -$hasParentTask[1]->mailto = ''; +r(current($testTaskList[1])) && p() && e('17'); // 测试批量创建阶段下测试任务 +r(count($testTaskList[1])) && p() && e('2'); // 测试批量创建阶段下测试任务 +r(current($storyTaskList[1])) && p() && e('19'); // 测试批量创建阶段下需求任务 +r(count($storyTaskList[1])) && p() && e('2'); // 测试批量创建阶段下需求任务 +r(current($childTaskList[1])) && p() && e('21'); // 测试批量创建阶段下任务1子任务 +r(count($childTaskList[1])) && p() && e('2'); // 测试批量创建阶段下任务1子任务 +r(current($kanbanTaskList[1])) && p() && e('23'); // 测试批量创建阶段下测试任务并更新看板 +r(count($kanbanTaskList[1])) && p() && e('2'); // 测试批量创建阶段下测试任务并更新看板 -$hasStoryTask = array(); -$hasStoryTask[1] = new stdclass(); -$hasStoryTask[1]->execution = $executionIdList[0]; -$hasStoryTask[1]->parent = $parent[0]; -$hasStoryTask[1]->module = $module[1]; -$hasStoryTask[1]->story = $story[0]; -$hasStoryTask[1]->name = $name[1]; -$hasStoryTask[1]->color = $color[1]; -$hasStoryTask[1]->type = $type[1]; -$hasStoryTask[1]->version = 1; -$hasStoryTask[1]->assignedTo = $assignedTo[1]; -$hasStoryTask[1]->estimate = $estimate[1]; -$hasStoryTask[1]->estStarted = $estStarted[1]; -$hasStoryTask[1]->deadline = $deadline[2]; -$hasStoryTask[1]->desc = $desc[1]; -$hasStoryTask[1]->pri = $pri[1]; -$hasStoryTask[1]->mailto = ''; - -$verifyScoreTask = array(); -$verifyScoreTask[1] = new stdclass(); -$verifyScoreTask[1]->execution = $executionIdList[0]; -$verifyScoreTask[1]->parent = $parent[4]; -$verifyScoreTask[1]->module = $module[1]; -$verifyScoreTask[1]->story = $story[1]; -$verifyScoreTask[1]->name = $name[1]; -$verifyScoreTask[1]->color = $color[1]; -$verifyScoreTask[1]->type = $type[1]; -$verifyScoreTask[1]->version = 1; -$verifyScoreTask[1]->assignedTo = $assignedTo[1]; -$verifyScoreTask[1]->estimate = $estimate[1]; -$verifyScoreTask[1]->estStarted = $estStarted[1]; -$verifyScoreTask[1]->deadline = $deadline[2]; -$verifyScoreTask[1]->desc = $desc[1]; -$verifyScoreTask[1]->pri = $pri[1]; -$verifyScoreTask[1]->mailto = ''; - -$kanbanTask = array(); -$kanbanTask[1] = new stdclass(); -$kanbanTask[1]->execution = $executionIdList[0]; -$kanbanTask[1]->parent = $parent[4]; -$kanbanTask[1]->module = $module[1]; -$kanbanTask[1]->story = $story[1]; -$kanbanTask[1]->name = $name[3]; -$kanbanTask[1]->color = $color[1]; -$kanbanTask[1]->type = $type[1]; -$kanbanTask[1]->version = 1; -$kanbanTask[1]->assignedTo = $assignedTo[1]; -$kanbanTask[1]->estimate = $estimate[1]; -$kanbanTask[1]->estStarted = $estStarted[1]; -$kanbanTask[1]->deadline = $deadline[2]; -$kanbanTask[1]->desc = $desc[1]; -$kanbanTask[1]->pri = $pri[1]; -$kanbanTask[1]->mailto = ''; - -$task = new taskTest(); - -r($task->batchCreateObject($withoutNameTask, $executionIdList[0])) && p('message:0') && e('『任务名称』不能为空。'); // 测试任务名称为空的情况 -r($task->batchCreateObject($normalTaskList, $executionIdList[0])) && p('') && e('2'); // 测试正常任务批量创建成功 -r($task->batchCreateObject($hasParentTask, $executionIdList[0], $parent[4])) && p('name') && e('任务1'); // 测试拆分任务 -r($task->batchCreateObject($hasStoryTask, $executionIdList[0], 0, $story[0])) && p('title') && e('需求1'); // 测试关联需求的情况 -r($task->batchCreateObject($verifyScoreTask, $executionIdList[0], 0, 0, true)) && p('') && e('1'); // 测试是否正常创建积分记录 -r($task->batchCreateObject($kanbanTask, $executionIdList[0], 0, 0, false, array('laneID' => $laneIdList[0], 'columnID' => $columnIdList[0]))) && p('name') && e('task4'); // 测试在看板的泳道列批量创建任务 +r(current($testTaskList[2])) && p() && e('25'); // 测试批量创建看板下测试任务 +r(count($testTaskList[2])) && p() && e('2'); // 测试批量创建看板下测试任务 +r(current($storyTaskList[2])) && p() && e('27'); // 测试批量创建看板下需求任务 +r(count($storyTaskList[2])) && p() && e('2'); // 测试批量创建看板下需求任务 +r(current($childTaskList[2])) && p() && e('29'); // 测试批量创建看板下任务1子任务 +r(count($childTaskList[2])) && p() && e('2'); // 测试批量创建看板下任务1子任务 +r(current($kanbanTaskList[2])) && p() && e('31'); // 测试批量创建看板下测试任务并更新看板 +r(count($kanbanTaskList[2])) && p() && e('2'); // 测试批量创建看板下测试任务并更新看板 diff --git a/module/task/test/model/canoperateeffort.php b/module/task/test/model/canoperateeffort.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/checkeeststartedanddeadline.php b/module/task/test/model/checkeeststartedanddeadline.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/checkrequired4batchcreate.php b/module/task/test/model/checkrequired4batchcreate.php deleted file mode 100755 index 6005746f15..0000000000 --- a/module/task/test/model/checkrequired4batchcreate.php +++ /dev/null @@ -1,198 +0,0 @@ -#!/usr/bin/env php -config('project')->gen('10'); - -$story = zdTable('story'); -$story->id->range('1'); -$story->product->range('1'); -$story->title->range('需求1'); -$story->type->range('story'); -$story->version->range('1'); -$story->status->range('active'); -$story->stage->range('projected'); -$story->reviewedDate->range('(-1M)-(+1w):60m')->type('timestamp')->format('YY/MM/DD'); -$story->lastEditedDate->range('(-1M)-(+1w):60m')->type('timestamp')->format('YY/MM/DD'); -$story->gen('1'); - -$storyspec = zdTable('storyspec'); -$storyspec->story->range('1'); -$storyspec->version->range('1'); -$storyspec->title->range('需求1'); -$storyspec->spec->range('storyspec1'); -$storyspec->gen('1'); - -$task = zdTable('task'); -$task->id->range('1'); -$task->name->range('任务1'); -$task->execution->range('2'); -$task->type->range('devel'); -$task->status->range('wait'); -$task->parent->range("`-1`"); -$task->gen('1'); - -$taskspec = zdTable('taskspec'); -$taskspec->task->range('1'); -$taskspec->version->range('1'); -$taskspec->name->range('任务一'); -$taskspec->gen('1'); - -/** - -title=测试taskTao->checkRequired4BatchCreate(); -cid=1 -pid=1 - - -*/ - -$executionIdList = array(2, 3, 4, 5, 6, 7, 8 ,9 ,10); - -$laneIdList = array(1, 2, 3); -$columnIdList = array(1, 2, 3); - -$parent = array(0, 0, 0, 0, 1); -$module = array(1, 2, 3, 4, 5); -$story = array(1, 0); -$storyEstimate = array(1, 2, 1, 2, 1); -$storyDesc = array('storyDesc1', 'storyDesc2', 'storyDesc3', '', ''); -$storyPri = array(3, 3, 1, 2, 4); -$name = array('task1', 'task2', 'task3', 'task4', ''); -$color = array('', 'red', 'green', '', 'gray'); -$type = array('devel', 'request', 'design', 'test', 'study', 'discuss', 'ui', 'affair', 'misc'); -$assignedTo = array('admin', 'admin', 'dev1', 'dev2', 'admin'); -$estimate = array('1', '2', '3', '1', '1', 's', '-1'); -$estStarted = array('2022-07-01', '2023-05-08', '', '2023-09-09', ''); -$deadline = array('2023-07-01', '2022-01-02', '2023-01-01', '', ''); -$desc = array('', 'taskDesc', 'taskAAA', '', ''); -$pri = array('1', '2', '3', '3', '1'); - -$withoutStoryTask = array(); -$withoutStoryTask[1] = new stdclass(); -$withoutStoryTask[1]->execution = $executionIdList[0]; -$withoutStoryTask[1]->parent = $parent[0]; -$withoutStoryTask[1]->module = $module[0]; -$withoutStoryTask[1]->name = $name[0]; -$withoutStoryTask[1]->type = $type[0]; -$withoutStoryTask[1]->deadline = $deadline[0]; -$withoutStoryTask[1]->estimate = $estimate[0]; -$withoutStoryTask[1]->estStarted = $estStarted[0]; - -$requestStageTask = array(); -$requestStageTask[1] = new stdclass(); -$requestStageTask[1]->execution = $executionIdList[0]; -$requestStageTask[1]->parent = $parent[0]; -$requestStageTask[1]->module = $module[0]; -$requestStageTask[1]->name = $name[1]; -$requestStageTask[1]->type = $type[0]; -$requestStageTask[1]->deadline = $deadline[0]; -$requestStageTask[1]->estimate = $estimate[0]; -$requestStageTask[1]->estStarted = $estStarted[0]; - -$reviewStageTask = array(); -$reviewStageTask[1] = new stdclass(); -$reviewStageTask[1]->execution = $executionIdList[0]; -$reviewStageTask[1]->parent = $parent[0]; -$reviewStageTask[1]->module = $module[0]; -$reviewStageTask[1]->name = $name[2]; -$reviewStageTask[1]->type = $type[0]; -$reviewStageTask[1]->deadline = $deadline[0]; -$reviewStageTask[1]->estimate = $estimate[0]; -$reviewStageTask[1]->estStarted = $estStarted[0]; - -$devStageTask = array(); -$devStageTask[1] = new stdclass(); -$devStageTask[1]->execution = $executionIdList[0]; -$devStageTask[1]->parent = $parent[0]; -$devStageTask[1]->module = $module[0]; -$devStageTask[1]->name = $name[3]; -$devStageTask[1]->type = $type[0]; -$devStageTask[1]->deadline = $deadline[0]; -$devStageTask[1]->estimate = $estimate[0]; -$devStageTask[1]->estStarted = $estStarted[0]; - -$conformLimitedTask = array(); -$conformLimitedTask[1] = new stdclass(); -$conformLimitedTask[1]->execution = $executionIdList[0]; -$conformLimitedTask[1]->parent = $parent[0]; -$conformLimitedTask[1]->module = $module[0]; -$conformLimitedTask[1]->story = $story[0]; -$conformLimitedTask[1]->name = $name[0]; -$conformLimitedTask[1]->version = 1; -$conformLimitedTask[1]->type = $type[0]; -$conformLimitedTask[1]->deadline = $deadline[0]; -$conformLimitedTask[1]->estimate = $estimate[0]; -$conformLimitedTask[1]->estStarted = $estStarted[0]; -$conformLimitedTask[1]->mailto = ''; - -$unConformLimitedTask = array(); -$unConformLimitedTask[1] = new stdclass(); -$unConformLimitedTask[1]->execution = $executionIdList[0]; -$unConformLimitedTask[1]->parent = $parent[0]; -$unConformLimitedTask[1]->module = $module[0]; -$unConformLimitedTask[1]->story = $story[0]; -$unConformLimitedTask[1]->name = $name[0]; -$unConformLimitedTask[1]->version = 1; -$unConformLimitedTask[1]->type = $type[0]; -$unConformLimitedTask[1]->deadline = $deadline[2]; -$unConformLimitedTask[1]->estimate = $estimate[0]; -$unConformLimitedTask[1]->estStarted = $estStarted[0]; -$unConformLimitedTask[1]->mailto = ''; - -$deadlineSmallTask = array(); -$deadlineSmallTask[1] = new stdclass(); -$deadlineSmallTask[1]->execution = $executionIdList[0]; -$deadlineSmallTask[1]->parent = $parent[0]; -$deadlineSmallTask[1]->module = $module[0]; -$deadlineSmallTask[1]->story = $story[0]; -$deadlineSmallTask[1]->name = $name[0]; -$deadlineSmallTask[1]->version = 1; -$deadlineSmallTask[1]->type = $type[0]; -$deadlineSmallTask[1]->estStarted = $estStarted[1]; -$deadlineSmallTask[1]->deadline = $deadline[1]; -$deadlineSmallTask[1]->estimate = $estimate[0]; -$deadlineSmallTask[1]->mailto = ''; - -$estimateNumberTask = array(); -$estimateNumberTask[1] = new stdclass(); -$estimateNumberTask[1]->execution = $executionIdList[0]; -$estimateNumberTask[1]->parent = $parent[0]; -$estimateNumberTask[1]->module = $module[0]; -$estimateNumberTask[1]->story = $story[0]; -$estimateNumberTask[1]->name = $name[0]; -$estimateNumberTask[1]->version = 1; -$estimateNumberTask[1]->type = $type[0]; -$estimateNumberTask[1]->estStarted = $estStarted[0]; -$estimateNumberTask[1]->deadline = $deadline[0]; -$estimateNumberTask[1]->estimate = $estimate[5]; -$estimateNumberTask[1]->mailto = ''; - -$negativeNumberTask = array(); -$negativeNumberTask[1] = new stdclass(); -$negativeNumberTask[1]->execution = $executionIdList[0]; -$negativeNumberTask[1]->parent = $parent[0]; -$negativeNumberTask[1]->module = $module[0]; -$negativeNumberTask[1]->story = $story[0]; -$negativeNumberTask[1]->name = $name[0]; -$negativeNumberTask[1]->version = 1; -$negativeNumberTask[1]->type = $type[0]; -$negativeNumberTask[1]->estStarted = $estStarted[0]; -$negativeNumberTask[1]->deadline = $deadline[0]; -$negativeNumberTask[1]->estimate = $estimate[6]; -$negativeNumberTask[1]->mailto = ''; - -$task = new taskTest(); - -r($task->checkRequired4BatchCreateTest($executionIdList[0], $withoutStoryTask, true)) && p('message:0') && e('『相关研发需求』不能为空。'); // 测试短期项目批量创建未关联需求的任务 -r($task->checkRequired4BatchCreateTest($executionIdList[3], $withoutStoryTask, true)) && p('1:name') && e('task1'); // 测试运维迭代批量创建未关联需求的任务 -r($task->checkRequired4BatchCreateTest($executionIdList[4], $requestStageTask, true)) && p('1:name') && e('task2'); // 测试需求类型阶段批量创建未关联需求的任务 -r($task->checkRequired4BatchCreateTest($executionIdList[5], $reviewStageTask, true)) && p('1:name') && e('task3'); // 测试总结评审类型阶段批量创建未关联需求的任务 -r($task->checkRequired4BatchCreateTest($executionIdList[6], $devStageTask, true)) && p('message:0') && e('『相关研发需求』不能为空。'); // 测试开发类型阶段批量创建未关联需求的任务 -r($task->checkRequired4BatchCreateTest($executionIdList[0], $conformLimitedTask, false, true)) && p('deadline:0') && e('任务截止日期应小于等于执行的结束日期:2023-02-01。'); // 测试开启起止日期限制,创建的任务截止日期大于执行的截止日期 -r($task->checkRequired4BatchCreateTest($executionIdList[0], $unConformLimitedTask, false, true)) && p('1:name') && e('task1'); // 测试开启起止日期限制,创建的任务截止日期小于执行的截止日期 -r($task->checkRequired4BatchCreateTest($executionIdList[0], $deadlineSmallTask)) && p('message:0') && e('"截止日期"必须大于"预计开始"'); // 测试任务截止日期小于任务的截止日期 -r($task->checkRequired4BatchCreateTest($executionIdList[0], $estimateNumberTask)) && p('message:0') && e('"最初预计"必须为正数'); // 测试任务预计工时不为数字的情况 -r($task->checkRequired4BatchCreateTest($executionIdList[0], $negativeNumberTask)) && p('message:0') && e('"最初预计"必须为正数'); // 测试任务预计工时为负数的情况 diff --git a/module/task/test/model/createmultitask.php b/module/task/test/model/createmultitask.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/createtaskofaffair.php b/module/task/test/model/createtaskofaffair.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/createtaskoftest.php b/module/task/test/model/createtaskoftest.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/getteambyaccount.php b/module/task/test/model/getteambyaccount.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/updatekanban4batchcreate.php b/module/task/test/model/updatekanban4batchcreate.php deleted file mode 100755 index 36d5b7ae30..0000000000 --- a/module/task/test/model/updatekanban4batchcreate.php +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env php -config('project')->gen(5); -zdTable('task')->config('task')->gen(8); -zdTable('kanbancolumn')->config('kanbancolumn')->gen(10); -zdTable('kanbancell')->config('kanbancell')->gen(10); - -/** - -title=taskModel->updateKanban4BatchCreate(); -timeout=0 -cid=2 - - -*/ - -$taskIdList = array('1', '2', '3', '4', '5', '6', '7', '8'); -$executionIdList = array('2', '3', '4', '5'); -$laneIdList = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); -$columnIdList = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); - -$task = new taskTest(); - -r($task->updateKanban4BatchCreateTest($taskIdList[1], $executionIdList[2], $laneIdList[1], $columnIdList[1])) && p() && e(',2,'); // 综合研发界面下看板项目的任务泳道未开始列无卡片的情况。 -r($task->updateKanban4BatchCreateTest($taskIdList[1], $executionIdList[2], $laneIdList[2], $columnIdList[2])) && p() && e(',2,5,6,805,'); // 综合研发界面下看板项目的任务泳道未开始列有卡片的情况。 -r($task->updateKanban4BatchCreateTest($taskIdList[2], $executionIdList[2], $laneIdList[9], $columnIdList[2])) && p() && e('0'); // 综合研发界面下看板项目任务泳道为空未开始列的情况。 -r($task->updateKanban4BatchCreateTest($taskIdList[2], $executionIdList[2], $laneIdList[9], $columnIdList[2])) && p() && e('0'); // 综合研发界面下看板项目任务泳道列为空的情况。 -r($task->updateKanban4BatchCreateTest($taskIdList[5], $executionIdList[3], $laneIdList[1], $columnIdList[2], 'lite')) && p() && e(',6,'); // 运营管理界面下看板项目任务泳道未开始列无卡片的情况。 -r($task->updateKanban4BatchCreateTest($taskIdList[5], $executionIdList[3], $laneIdList[3], $columnIdList[3], 'lite')) && p() && e(',6,7,8,807,'); // 运营管理界面下看板项目任务泳道未开始列有卡片的情况。 diff --git a/module/task/test/model/updatekanbancell.php b/module/task/test/model/updatekanbancell.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/updatekanbandata.php b/module/task/test/model/updatekanbandata.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/updatekanbanforbatchcreate.php b/module/task/test/model/updatekanbanforbatchcreate.php new file mode 100755 index 0000000000..07d73398ff --- /dev/null +++ b/module/task/test/model/updatekanbanforbatchcreate.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +config('project')->gen(5); +zdTable('task')->config('task')->gen(8); +zdTable('kanbancolumn')->config('kanbancolumn')->gen(10); +zdTable('kanbancell')->config('kanbancell')->gen(10); + +/** + +title=taskModel->batchcreate(); +timeout=0 +cid=2 + + +*/ + +$taskIdList = array('1', '2', '3', '4', '5', '6', '7', '8'); +$executionIdList = array('2', '3', '4', '5'); +$laneIdList = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); +$columnIdList = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); + +$task = new taskTest(); + +r($task->updateKanbanForBatchCreateTest($taskIdList[1], $executionIdList[2], $laneIdList[1], $columnIdList[1])) && p() && e('0'); // 综合研发界面下看板项目的任务泳道未开始列无卡片的情况。 +r($task->updateKanbanForBatchCreateTest($taskIdList[1], $executionIdList[2], $laneIdList[2], $columnIdList[2])) && p() && e('0'); // 综合研发界面下看板项目的任务泳道未开始列有卡片的情况。 +r($task->updateKanbanForBatchCreateTest($taskIdList[2], $executionIdList[2], $laneIdList[9], $columnIdList[2])) && p() && e('0'); // 综合研发界面下看板项目任务泳道为空未开始列的情况。 +r($task->updateKanbanForBatchCreateTest($taskIdList[2], $executionIdList[2], $laneIdList[9], $columnIdList[2])) && p() && e('0'); // 综合研发界面下看板项目任务泳道列为空的情况。 +r($task->updateKanbanForBatchCreateTest($taskIdList[5], $executionIdList[3], $laneIdList[1], $columnIdList[2], 'lite')) && p() && e(',6,'); // 运营管理界面下看板项目任务泳道未开始列无卡片的情况。 +r($task->updateKanbanForBatchCreateTest($taskIdList[5], $executionIdList[3], $laneIdList[3], $columnIdList[3], 'lite')) && p() && e(',6,'); // 运营管理界面下看板项目任务泳道未开始列有卡片的情况。 diff --git a/module/task/test/model/updateteam.php b/module/task/test/model/updateteam.php old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/activate/kanbancell.yaml b/module/task/test/model/yaml/activate/kanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/activate/kanbancolumn.yaml b/module/task/test/model/yaml/activate/kanbancolumn.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/activate/kanbanlane.yaml b/module/task/test/model/yaml/activate/kanbanlane.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/activate/kanbanregion.yaml b/module/task/test/model/yaml/activate/kanbanregion.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/afterbatchcreate/project.yaml b/module/task/test/model/yaml/afterbatchcreate/project.yaml new file mode 100755 index 0000000000..2a064b7281 --- /dev/null +++ b/module/task/test/model/yaml/afterbatchcreate/project.yaml @@ -0,0 +1,19 @@ +title: table zt_project +author: Hu Fangzhou +version: "1.0" +fields: + - field: id + range: 1-5 + - field: name + note: "名称" + fields: + - field: name1 + range: rnd + - field: name2 + range: 项目,迭代,阶段,看板{2} + - field: project + range: 1 + - field: type + range: project,sprint,stage,kanban{2} + - field: vision + range: rnd{4},lite diff --git a/module/task/test/model/yaml/afterbatchcreate/task.yaml b/module/task/test/model/yaml/afterbatchcreate/task.yaml new file mode 100755 index 0000000000..fe8a5ae765 --- /dev/null +++ b/module/task/test/model/yaml/afterbatchcreate/task.yaml @@ -0,0 +1,22 @@ +title: zt_task +author: Tian Shujie +version: "1.0" +fields: + - field: id + range: 1-8 + - field: type + range: design,devel,test,study,discuss,ui,affair,misc + - field: status + range: wait + - field: project + range: 1 + - field: execution + range: "2{2},3{2},4{2},5{2}" + - field: deleted + range: 0 + - field: vision + range: rnd + - field: openedDate + range: "20220101 000000:1W" # 生成从2021年1月1日0时0分0秒到当前时间的数据,步长为1周 + type: timestamp + format: "YY/MM/DD hh:mm:ss" diff --git a/module/task/test/model/yaml/aftersplittask/action.yaml b/module/task/test/model/yaml/aftersplittask/action.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/aftersplittask/task.yaml b/module/task/test/model/yaml/aftersplittask/task.yaml old mode 100644 new mode 100755 index 87686e323b..68a199a25b --- a/module/task/test/model/yaml/aftersplittask/task.yaml +++ b/module/task/test/model/yaml/aftersplittask/task.yaml @@ -4,6 +4,8 @@ version: "1.0" fields: - field: id range: 1-9 + - field: execution + range: 2 - field: parent range: 0,1,0,2,0,3,0{3} - field: type diff --git a/module/task/test/model/yaml/afterstart/kanbancell.yaml b/module/task/test/model/yaml/afterstart/kanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/afterstart/kanbancolumn.yaml b/module/task/test/model/yaml/afterstart/kanbancolumn.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/afterstart/kanbanlane.yaml b/module/task/test/model/yaml/afterstart/kanbanlane.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/afterstart/kanbanregion.yaml b/module/task/test/model/yaml/afterstart/kanbanregion.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/batchchangemodule/execution.yaml b/module/task/test/model/yaml/batchchangemodule/execution.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/batchchangemodule/task.yaml b/module/task/test/model/yaml/batchchangemodule/task.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/batchcreate/kanbancell.yaml b/module/task/test/model/yaml/batchcreate/kanbancell.yaml old mode 100644 new mode 100755 index 1eaec2ce6e..33e0f2570f --- a/module/task/test/model/yaml/batchcreate/kanbancell.yaml +++ b/module/task/test/model/yaml/batchcreate/kanbancell.yaml @@ -1,16 +1,16 @@ title: table zt_kanbancell desc: "看板单元格" -author: Hu Fangzhou +author: Tian Shujie version: "1.0" fields: - field: kanban - range: 2-5 + range: 2{6},4{6},5{6} - field: lane - range: 1-10 + range: "1{6},2{6},3{6}" - field: column - range: 1-10 + range: 1-18 - field: type - range: task{4},common{4},story,bug + range: task - field: cards fields: - field: card1 @@ -20,7 +20,3 @@ fields: - field: card2 postfix: "," range: 2-1000:2 - - field: card3 - postfix: "," - range: 801-1000:2 - diff --git a/module/task/test/model/yaml/batchcreate/kanbancolumn.yaml b/module/task/test/model/yaml/batchcreate/kanbancolumn.yaml new file mode 100755 index 0000000000..bb3a3a6154 --- /dev/null +++ b/module/task/test/model/yaml/batchcreate/kanbancolumn.yaml @@ -0,0 +1,20 @@ +title: table zt_kanbancolumn +desc: "看板列" +author: Tian Shujie +version: "1.0" +fields: + - field: parent + range: "0" + - field: name + range: 1-18 + prefix: "column" + - field: region + range: "1{6},2{6},3{6}" + - field: region + range: "1{6},2{6},3{6}" + - field: type + range: wait,developing,developed,pause,canceled,closed + - field: color + range: "#333" + - field: deleted + range: "0" diff --git a/module/task/test/model/yaml/batchcreate/kanbanlane.yaml b/module/task/test/model/yaml/batchcreate/kanbanlane.yaml new file mode 100755 index 0000000000..c8555537d4 --- /dev/null +++ b/module/task/test/model/yaml/batchcreate/kanbanlane.yaml @@ -0,0 +1,22 @@ +title: table zt_kanbanlane +desc: "看板泳道" +author: Tian Shujie +version: "1.0" +fields: + - field: id + range: 1-10 + - field: execution + range: "2,3,4,0{7}" + - field: name + range: 1-10 + prefix: "lane" + - field: region + range: 1-10 + - field: type + range: "task{3},common{7}" + - field: group + range: 1-10 + - field: color + range: "#333" + - field: deleted + range: "0" diff --git a/module/task/test/model/yaml/batchcreate/project.yaml b/module/task/test/model/yaml/batchcreate/project.yaml old mode 100644 new mode 100755 index 7bd055f68e..2a064b7281 --- a/module/task/test/model/yaml/batchcreate/project.yaml +++ b/module/task/test/model/yaml/batchcreate/project.yaml @@ -1,91 +1,19 @@ title: table zt_project -desc: "项目、执行" author: Hu Fangzhou version: "1.0" fields: - field: id - range: 1-10 - - field: project - range: 1 - - field: model - range: scrum,[]{9} + range: 1-5 - field: name note: "名称" fields: - field: name1 - range: 项目,执行{9} + range: rnd - field: name2 - range: 1,[1-9] + range: 项目,迭代,阶段,看板{2} + - field: project + range: 1 - field: type - range: project,scrum{4},stage{3},kanban{2} - - field: status - range: wait{2},doing{4},suspended,closed - - field: lifetime - range: - - field: budget - range: 900000-1:100 - - field: budgetUnit - range: CNY,USD - - field: attribute - note: "Only stage has attribute" - range: - - field: percent - range: 1-100 - - field: milestone - note: "Is it milestone" - range: 0 - - field: output - note: "Output document" - range: - - field: auth - note: "Only project has auth" - range: "extend" - - field: parent - range: 1-10 - - field: path - fields: - - field: path1 - prefix: "," - range: 1 - - field: path2 - prefix: "," - range: 2-10 - postfix: "," - - field: grade - range: "2" - - field: code - range: 1-10000 - prefix: "project" - - field: begin - range: "(-3M)-(+M):1D" - type: timestamp - format: "YY/MM/DD" - postfix: "\t" - - field: end - range: "(+5w)-(+2M):1D" - type: timestamp - format: "YY/MM/DD" - postfix: "\t" - - field: PO - range: - - field: PM - range: - - field: QD - range: - - field: RD - range: - - field: team - range: - - field: acl - range: open,private,program - - field: order - range: 5-10000:5 - - field: openedVersion - range: - - field: openedDate - range: "(-3M)-(+M):1D" - type: timestamp - format: "YY/MM/DD" - postfix: "\t" - - field: deleted - range: 0 + range: project,sprint,stage,kanban{2} + - field: vision + range: rnd{4},lite diff --git a/module/task/test/model/yaml/batchcreate/task.yaml b/module/task/test/model/yaml/batchcreate/task.yaml new file mode 100755 index 0000000000..fe8a5ae765 --- /dev/null +++ b/module/task/test/model/yaml/batchcreate/task.yaml @@ -0,0 +1,22 @@ +title: zt_task +author: Tian Shujie +version: "1.0" +fields: + - field: id + range: 1-8 + - field: type + range: design,devel,test,study,discuss,ui,affair,misc + - field: status + range: wait + - field: project + range: 1 + - field: execution + range: "2{2},3{2},4{2},5{2}" + - field: deleted + range: 0 + - field: vision + range: rnd + - field: openedDate + range: "20220101 000000:1W" # 生成从2021年1月1日0时0分0秒到当前时间的数据,步长为1周 + type: timestamp + format: "YY/MM/DD hh:mm:ss" diff --git a/module/task/test/model/yaml/checkrequired4batchcreate/project.yaml b/module/task/test/model/yaml/checkrequired4batchcreate/project.yaml deleted file mode 100644 index ba45937204..0000000000 --- a/module/task/test/model/yaml/checkrequired4batchcreate/project.yaml +++ /dev/null @@ -1,31 +0,0 @@ -title: table zt_project -author: Hu Fangzhou -version: "1.0" -fields: - - field: id - range: 1-10 - - field: name - note: "名称" - fields: - - field: name1 - range: rnd{9},lite - - field: name2 - range: 项目,迭代{4},阶段{3},看板{2} - - field: project - range: 0,1{9} - - field: type - range: project,sprint{4},stage{3},kanban{2} - - field: lifetime - range: "[],short{2},long{1},ops{1},[]{5}" - - field: attribute - range: "[]{5},request,review,dev,[]{2}" - - field: begin - range: "20220101 000000:3M" - type: timestamp - format: "YY/MM/DD" - - field: end - range: "20230101 000000:1M" - type: timestamp - format: "YY/MM/DD" - - field: vision - range: rnd{9},lite diff --git a/module/task/test/model/yaml/computebeginandend/task_computebeginandend.yaml b/module/task/test/model/yaml/computebeginandend/task_computebeginandend.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/computeworkinghours/task_computeworkinghours.yaml b/module/task/test/model/yaml/computeworkinghours/task_computeworkinghours.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/createmultitask/project.yaml b/module/task/test/model/yaml/createmultitask/project.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/createtaskofaffair/project.yaml b/module/task/test/model/yaml/createtaskofaffair/project.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/createtaskoftest/project.yaml b/module/task/test/model/yaml/createtaskoftest/project.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/createtaskoftest/story.yaml b/module/task/test/model/yaml/createtaskoftest/story.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/isnostoryexecution/project_isnostoryexecution.yaml b/module/task/test/model/yaml/isnostoryexecution/project_isnostoryexecution.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/managetaskteam/effort_managetaskteam.yaml b/module/task/test/model/yaml/managetaskteam/effort_managetaskteam.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/managetaskteam/taskteam_managetaskteam.yaml b/module/task/test/model/yaml/managetaskteam/taskteam_managetaskteam.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanban4batchcreate/kanbancell.yaml b/module/task/test/model/yaml/updatekanban4batchcreate/kanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanban4batchcreate/kanbancolumn.yaml b/module/task/test/model/yaml/updatekanban4batchcreate/kanbancolumn.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanban4batchcreate/project.yaml b/module/task/test/model/yaml/updatekanban4batchcreate/project.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanban4batchcreate/task.yaml b/module/task/test/model/yaml/updatekanban4batchcreate/task.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbancell/kanbancell_updatekanbancell.yaml b/module/task/test/model/yaml/updatekanbancell/kanbancell_updatekanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbancell/kanbancolumn_updatekanbancell.yaml b/module/task/test/model/yaml/updatekanbancell/kanbancolumn_updatekanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbancell/kanbanlane_updatekanbancell.yaml b/module/task/test/model/yaml/updatekanbancell/kanbanlane_updatekanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbancell/kanbanregion_updatekanbancell.yaml b/module/task/test/model/yaml/updatekanbancell/kanbanregion_updatekanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbandata/kanbancell.yaml b/module/task/test/model/yaml/updatekanbandata/kanbancell.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbandata/kanbancolumn.yaml b/module/task/test/model/yaml/updatekanbandata/kanbancolumn.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbandata/kanbanlane.yaml b/module/task/test/model/yaml/updatekanbandata/kanbanlane.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbandata/project.yaml b/module/task/test/model/yaml/updatekanbandata/project.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/model/yaml/updatekanbandata/task.yaml b/module/task/test/model/yaml/updatekanbandata/task.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/tao/copytaskdata.php b/module/task/test/tao/copytaskdata.php new file mode 100755 index 0000000000..183e1945e8 --- /dev/null +++ b/module/task/test/tao/copytaskdata.php @@ -0,0 +1,25 @@ +#!/usr/bin/env php +config('task')->gen(9); +zdTable('effort')->config('effort')->gen(3); + +/** + +title=taskModel->copyTaskData(); +timeout=0 +cid=2 + +*/ + +$taskIdList = array(0, 1, 2, 3, 4, 5); + +$task = new taskTest(); + +r($task->copyTaskDataTest($taskIdList[1], 'subTaskEffort')) && p('objectID') && e('1'); // 测试父任务日志的objectID是否更改为子任务ID +r($task->copyTaskDataTest($taskIdList[2], 'subTaskEffort')) && p('objectType') && e('task'); // 测试更新的日志类型是否为task +r($task->copyTaskDataTest($taskIdList[3], 'subTaskEffort')) && p('consumed') && e('1'); // 测试父任务日志消耗是否更改为子任务工时消耗 +r($task->copyTaskDataTest($taskIdList[4], 'childrenTask')) && p('consumed') && e('1'); // 测试子任务的消耗是否和父任务一致 +r($task->copyTaskDataTest($taskIdList[5], 'childrenTask')) && p('name,type,pri') && e('开发任务11,design,1'); // 测试子任务信息是否和父任务一致 diff --git a/module/task/test/tao/setteammember.php b/module/task/test/tao/setteammember.php old mode 100644 new mode 100755 diff --git a/module/task/test/tao/splitconsumedtask.php b/module/task/test/tao/splitconsumedtask.php deleted file mode 100755 index 1323ee51f7..0000000000 --- a/module/task/test/tao/splitconsumedtask.php +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env php -config('task')->gen(9); -zdTable('effort')->config('effort')->gen(3); - -/** - -title=taskModel->splitConsumedTask(); -timeout=0 -cid=2 - -*/ - -$taskIdList = array(0, 1, 2, 3, 4, 5); - -$task = new taskTest(); - -r($task->splitConsumedTaskTest($taskIdList[1], 'subTaskEffort')) && p('objectID') && e('10'); // 测试父任务日志的objectID是否更改为子任务ID -r($task->splitConsumedTaskTest($taskIdList[2], 'subTaskEffort')) && p('objectType') && e('task'); // 测试更新的日志类型是否为task -r($task->splitConsumedTaskTest($taskIdList[3], 'subTaskEffort')) && p('consumed') && e('3'); // 测试父任务日志消耗是否更改为子任务工时消耗 -r($task->splitConsumedTaskTest($taskIdList[4], 'childrenTask')) && p('consumed') && e('1'); // 测试子任务的消耗是否和父任务一致 -r($task->splitConsumedTaskTest($taskIdList[5], 'childrenTask')) && p('name,type,pri') && e('开发任务15,discuss,1'); // 测试子任务信息是否和父任务一致 diff --git a/module/task/test/tao/yaml/checkhaschildren/task_checkhaschildren.yaml b/module/task/test/tao/yaml/checkhaschildren/task_checkhaschildren.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/tao/yaml/splitconsumedtask/effort.yaml b/module/task/test/tao/yaml/copytaskdata/effort.yaml old mode 100644 new mode 100755 similarity index 100% rename from module/task/test/tao/yaml/splitconsumedtask/effort.yaml rename to module/task/test/tao/yaml/copytaskdata/effort.yaml diff --git a/module/task/test/tao/yaml/splitconsumedtask/task.yaml b/module/task/test/tao/yaml/copytaskdata/task.yaml old mode 100644 new mode 100755 similarity index 100% rename from module/task/test/tao/yaml/splitconsumedtask/task.yaml rename to module/task/test/tao/yaml/copytaskdata/task.yaml diff --git a/module/task/test/tao/yaml/managetaskteammember/effort_managetaskteammember.yaml b/module/task/test/tao/yaml/managetaskteammember/effort_managetaskteammember.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/tao/yaml/managetaskteammember/taskteam_managetaskteammember.yaml b/module/task/test/tao/yaml/managetaskteammember/taskteam_managetaskteammember.yaml old mode 100644 new mode 100755 diff --git a/module/task/test/task.class.php b/module/task/test/task.class.php old mode 100644 new mode 100755 index 5cc32e7662..0a9ecde5b1 --- a/module/task/test/task.class.php +++ b/module/task/test/task.class.php @@ -52,71 +52,70 @@ class taskTest * Test batch create tasks. * * @param array $data - * @param int $executionID - * @param int $taskID - * @param int $storyID - * @param bool $verifyScore + * @param string $executionType * @param array $output * @access public - * @return array|object|int|false + * @return array */ - public function batchCreateObject(array $data = array(), int $executionID = 0, int $taskID = 0, int $storyID = 0, bool $verifyScore = false, array $output = array()): array|object|int|false + public function batchCreateObject(array $param = array(), string $executionType = 'sprint', array $output = array()): array { global $tester; + $_SERVER['HTTP_HOST'] = $tester->config->db->host; + $executionIdList = array('sprint' => 2, 'stage' => 3, 'kanban' => 4); + $executionID = zget($executionIdList, $executionType); + $createFields = array( + 'project' => 1, + 'execution' => $executionID, + 'parent' => 0, + 'module' => 0, + 'story' => 0, + 'name' => '', + 'type' => 'test', + 'assignedTo' => 'admin', + 'assignedDate' => helper::now(), + 'pri' => 3, + 'estimate' => 0, + 'left' => 0, + 'estStarted' => '2021-01-10', + 'deadline' => '2021-03-19', + 'desc' => '', + 'version' => '1', + 'openedBy' => 'admin', + 'openedDate' => helper::now(), + 'laneID' => 0, + ); + + $tasks = array(); + foreach($param as $rowIndex => $data) + { + $task = new stdclass(); + foreach($createFields as $field => $defaultValue) $task->$field = $defaultValue; + foreach($data as $key => $value) $task->$key = $value; + $tasks[$rowIndex] = $task; + } + + $taskIdList = $this->objectModel->batchCreate($tasks, $output); + + if(dao::isError()) return dao::getError(); + return $taskIdList; + } + + /** + * 批量创建任务后的其他数据处理。 + * Other data process after task batch create. + * + * @param array $taskIdList + * @param int $parentID + * @access public + * @return bool + */ + public function afterBatchCreateObject(array $taskIdList, int $parentID = 0): bool + { + global $tester; $_SERVER['HTTP_HOST'] = $tester->config->db->host; - $execution = $tester->dao->findById($executionID)->from(TABLE_EXECUTION)->fetch(); - - $lastScore = $tester->dao->select('after')->from(TABLE_SCORE)->orderBy('id_desc')->limit(1)->fetch('after'); - - $objectIdList = $this->objectModel->batchCreate($execution, $data, $taskID, $output); - - $childTask = array(); - if(!dao::isError()) $childTask = $this->objectModel->getById(current($objectIdList)); - - if(dao::isError()) - { - return dao::getError(); - } - - if(!empty($taskID)) - { - $parentTask = $this->objectModel->getById($childTask->parent); - return $parentTask; - } - - if(!empty($storyID)) - { - $releatedStory = $tester->loadModel('story')->getById($childTask->story); - return $releatedStory; - } - - if($verifyScore) - { - $score = $tester->dao->select('after')->from(TABLE_SCORE)->orderBy('id_desc')->limit(1)->fetch('after'); - return $score == $lastScore + 1; - } - - if(!empty($output)) - { - $laneID = isset($output['laneID']) ? $output['laneID'] : 0; - $columnID = isset($output['columnID']) ? $output['columnID'] : 0; - $cards = $tester->dao->select('cards')->from(TABLE_KANBANCELL) - ->where('kanban')->eq($executionID) - ->andWhere('lane')->eq($laneID) - ->andWhere('column')->eq($columnID) - ->andWhere('type')->eq('task') - ->fetch('cards'); - $taskIdList = trim($cards, ','); - $taskIdList = explode(',', $taskIdList); - $latestTaskID = current($taskIdList); - $task = $this->objectModel->getById($latestTaskID); - - return $task ? $task : false; - } - - return count($objectIdList); + return $this->objectModel->afterBatchCreate($taskIdList, $parentID); } /** @@ -1917,13 +1916,13 @@ class taskTest * @access public * @return string */ - public function updateKanban4BatchCreateTest(int $taskID, int $executionID, int $laneID, int $columnID, string $vision = 'rnd'): string + public function updateKanbanForBatchCreateTest(int $taskID, int $executionID, int $laneID, int $columnID, string $vision = 'rnd'): string { global $tester; $tester->config->vision = $vision; - $this->objectModel->updateKanban4BatchCreate($taskID, $executionID, $laneID, $columnID); + $this->objectModel->updateKanbanForBatchCreate($taskID, $executionID, $laneID, $columnID); $cards = $tester->dao->select('cards')->from(TABLE_KANBANCELL) ->where('kanban')->eq($executionID) ->andWhere('lane')->eq($laneID) @@ -2049,12 +2048,12 @@ class taskTest * Process other data after split task. * * @param int $oldParentTaskID - * @param string $children + * @param array $children * @param string $testObject children|parent|parentAction * @access public - * @return object|string + * @return array|object|string */ - public function afterSplitTaskTest(int $oldParentTaskID = 0, string $children = '', string $testObject = 'parent'): object|string + public function afterSplitTaskTest(int $oldParentTaskID = 0, array $children = array(), string $testObject = 'parent'): array|object|string { global $tester; $_SERVER['HTTP_HOST'] = $tester->config->db->host; @@ -2072,15 +2071,15 @@ class taskTest } /** - * 拆分已消耗的任务。 - * split the consumed task. + * 复制任务数据。 + * Copy the task data and update the effort to the new task. * * @param int $parentTaskID * @param string $testType subTaskEffort|childrenTask * @access public * @return object */ - public function splitConsumedTaskTest(int $parentTaskID, string $testType): object + public function copyTaskDataTest(int $parentTaskID, string $testType): object { global $tester; @@ -2090,7 +2089,7 @@ class taskTest if(strpos($key, 'Date')) unset($parentTask->$key); } - $taskID = $this->objectModel->splitConsumedTask($parentTask); + $taskID = $this->objectModel->copyTaskData($parentTask); $testResult['subTaskEffort'] = $tester->dao->select('*')->from(TABLE_EFFORT)->where('objectID')->eq($taskID)->andWhere('objectType')->eq('task')->fetch(); $testResult['childrenTask'] = $tester->dao->select('*')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch(); @@ -2112,10 +2111,7 @@ class taskTest public function updateKanbanDataTest(int $executionID, int $taskID, int $laneID, int $columnID): object|bool { global $tester; - $execution = $task = new stdclass(); - if($executionID) $execution = $tester->loadModel('execution')->getByID($executionID); - if($taskID) $task = $this->objectModel->getByID($taskID); - $result = $this->objectModel->updateKanbanData($execution, $task, $laneID, $columnID); + $result = $this->objectModel->updateKanbanData($executionID, (array)$taskID, $laneID, $columnID); if(!$result) return false; if($laneID) $object = $tester->loadModel('kanban')->getLaneByID($laneID); diff --git a/module/task/zen.php b/module/task/zen.php index 31e82ba366..1a3564eec4 100644 --- a/module/task/zen.php +++ b/module/task/zen.php @@ -401,6 +401,7 @@ class taskZen extends task $taskIdList = array_unique($taskIdList); $muletipleTasks = $this->dao->select('task, account')->from(TABLE_TASKTEAM)->where('task')->in($taskIdList)->fetchGroup('task', 'account'); $tasks = $this->task->getByList($taskIdList); + /* Filter tasks. */ foreach($tasks as $taskID => $task) { @@ -430,22 +431,33 @@ class taskZen extends task * 处理批量创建任务的请求数据。 * Process the request data for the batch create tasks. * - * @param int $executionID - * @param int $taskID + * @param object $execution + * @param int $taskID + * @param array $output * @access protected - * @return object[] + * @return false|object[] */ - protected function buildTasksForBatchCreate(int $executionID, int $taskID): array + protected function buildTasksForBatchCreate(object $execution, int $taskID, array $output): false|array { - $tasks = form::batchData($this->config->task->form->batchCreate)->get(); + $tasks = form::batchData()->get(); foreach($tasks as $task) { - $task->execution = $executionID; + $task->project = $execution->project; + $task->execution = $execution->id; $task->left = $task->estimate; + $task->parent = $taskID; + $task->laneID = empty($task->laneID) && !empty($output['laneID']) ? (int)$output['laneID'] : $task->laneID; } - /* 去除重复数据。 Deduplicated data. */ - return $this->removeDuplicate4BatchCreate($executionID, $tasks); + /* Remove data with the same task name. */ + $tasks = $this->removeDuplicateForBatchCreate($execution->id, $tasks); + if(dao::isError()) return false; + + /* Check if the input post data meets the requirements. */ + $this->checkBatchCreateTask($execution->id, $tasks); + if(dao::isError()) return false; + + return $tasks; } /** @@ -458,24 +470,21 @@ class taskZen extends task */ protected function buildTaskForCreate(int $executionID): object { - $formData = form::data($this->config->task->form->create); - $postData = $formData->get(); - $execution = $this->dao->findById($postData->execution)->from(TABLE_EXECUTION)->fetch(); - $team = !empty($postData->team) ? array_filter($postData->team) : array(); - $task = $formData->setDefault('execution', $executionID) + $execution = $this->dao->findById($executionID)->from(TABLE_EXECUTION)->fetch(); + $team = !empty($this->post->team) ? array_filter($this->post->team) : array(); + $task = form::data()->setDefault('execution', $executionID) ->setDefault('project', $execution->project) - ->setIF($postData->estimate !== false, 'left', $postData->estimate) - ->setIF(isset($postData->story), 'storyVersion', isset($postData->story) ? $this->loadModel('story')->getVersion($postData->story) : 0) - ->setIF(empty($postData->multiple) || count($team) < 1, 'mode', '') + ->setIF($this->post->estimate !== false, 'left', $this->post->estimate) + ->setIF($this->post->story, 'storyVersion', isset($this->post->story) ? $this->loadModel('story')->getVersion($this->post->story) : 0) + ->setIF(empty($this->post->multiple) || count($team) < 1, 'mode', '') ->setIF($this->task->isNoStoryExecution($execution), 'story', 0) - ->setIF(!empty($postData->assignedTo), 'assignedDate', helper::now()) + ->setIF($this->post->assignedTo, 'assignedDate', helper::now()) + ->setIF(!$this->post->estStarted, 'estStarted', '') + ->setIF(!$this->post->deadline, 'deadline', '') ->get(); - if(empty($postData->estStarted)) unset($task->estStarted); - if(empty($postData->deadline)) unset($task->deadline); - /* Processing image link. */ - $task = $this->loadModel('file')->processImgURL($task, $this->config->task->editor->create['id'], $postData->uid); + $task = $this->loadModel('file')->processImgURL($task, $this->config->task->editor->create['id'], $this->post->uid); /* Check if the input post data meets the requirements. */ $this->checkCreateTask($task); @@ -598,63 +607,6 @@ class taskZen extends task return $testTasks; } - /** - * 批量创建任务之前构造数据。 - * Build data before batch create tasks. - * - * @param object $execution - * @param object $tasks - * @param int $index - * @param array $dittoFields - * @param array $extendFields - * @param int $taskID - * @access protected - * @return object - */ - protected function buildData4BatchCreate(object $execution, object $tasks, int $index, array $dittoFields, array $extendFields, int $taskID): object - { - extract($dittoFields); - $now = helper::now(); - - $task = new stdclass(); - $task->story = (int)$story; - $task->type = $type; - $task->module = (int)$module; - $task->assignedTo = $assignedTo; - $task->color = isset($tasks->color[$index]) ? $tasks->color[$index] : ''; - $task->name = $tasks->name[$index]; - $task->desc = nl2br($tasks->desc[$index]); - $task->pri = (int)$tasks->pri[$index]; - $task->estimate = $tasks->estimate[$index] ? $tasks->estimate[$index] : 0; - $task->left = $tasks->estimate[$index] ? $tasks->estimate[$index] : 0; - $task->project = $execution->project; - $task->execution = $execution->id; - $task->estStarted = $estStarted; - $task->deadline = $deadline; - $task->status = 'wait'; - $task->openedBy = $this->app->user->account; - $task->openedDate = $now; - $task->parent = $taskID; - $task->vision = isset($tasks->vision[$index]) ? $tasks->vision[$index] : 'rnd'; - $task->version = 1; - if($story) $task->storyVersion = (int)$this->dao->findById($task->story)->from(TABLE_STORY)->fetch('version'); - if($assignedTo) $task->assignedDate = $now; - if(strpos($this->config->task->create->requiredFields, 'estStarted') !== false && empty($estStarted)) $task->estStarted = ''; - if(strpos($this->config->task->create->requiredFields, 'deadline') !== false && empty($deadline)) $task->deadline = ''; - if(isset($tasks->lanes[$index])) $task->laneID = $tasks->lanes[$index]; - - /* 处理工作流字段。 Process workflow fields. */ - foreach($extendFields as $extendField) - { - $task->{$extendField->field} = $tasks->{$extendField->field}[$index]; - if(is_array($task->{$extendField->field})) $task->{$extendField->field} = implode(',', $task->{$extendField->field}); - - $task->{$extendField->field} = htmlSpecialString($task->{$extendField->field}); - } - - return $task; - } - /** * 处理开始任务的日志数据。 * Process the effort data for the start task. @@ -770,6 +722,60 @@ class taskZen extends task return !dao::isError(); } + /** + * 批量创建前检查必填项。 + * Check required fields before batch create tasks. + * + * @param int $executionID + * @param object[] $tasks + * @access protected + * @return bool + */ + protected function checkBatchCreateTask(int $executionID, array $tasks): bool + { + /* Set required fields. */ + $requiredFields = $this->config->task->create->requiredFields; + $execution = $this->loadModel('execution')->getById($executionID); + if($this->task->isNoStoryExecution($execution)) $requiredFields = str_replace(',story,', ',', ',' . $requiredFields . ','); + $requiredFields = array_filter(explode(',', $requiredFields)); + + foreach($tasks as $rowIndex => $task) + { + /* If the task start and end date must be between the execution start and end date, check if the task start and end date accord with the conditions. */ + if(!empty($this->config->limitTaskDate)) + { + $this->task->checkEstStartedAndDeadline($executionID, $task->estStarted, $task->deadline); + if(dao::isError()) return false; + } + + /* Check start and end date. */ + if(!helper::isZeroDate($task->deadline) && $task->deadline < $task->estStarted) + { + dao::$errors["deadline[$rowIndex]"] = $this->lang->task->error->deadlineSmall; + return false; + } + + /* Check if the estimate is positive. */ + if($task->estimate < 0) + { + dao::$errors["estimate[$rowIndex]"] = $this->lang->task->error->recordMinus; + return false; + } + + /* Check if the required fields are empty. */ + foreach($requiredFields as $field) + { + if(empty($task->$field)) + { + dao::$errors[$field . "[$rowIndex]"] = sprintf($this->lang->error->notempty, $this->lang->task->$field); + return false; + } + } + } + + return true; + } + /** * 检查规定时间内是否创建了同名任务。 * Check whether a task with the same name is created within the specified time. @@ -884,14 +890,13 @@ class taskZen extends task * 检查当前用户在该执行中是否是受限用户。 * Checks if the current user is a limited user in this execution. * - * @param string $executionID + * @param int $executionID * @access protected * @return bool */ - protected function isLimitedInExecution(string $executionID): bool + protected function isLimitedInExecution(int $executionID): bool { - $this->execution->getLimitedExecution(); - $limitedExecutions = !empty($this->session->limitedExecutions) ? $this->session->limitedExecutions : ''; + $limitedExecutions = $this->execution->getLimitedExecution(); if(strpos(",{$limitedExecutions},", ",$executionID,") !== false) return true; return false; @@ -938,18 +943,6 @@ class taskZen extends task */ protected function getJumpLink(object $execution): string { - if($this->app->tab == 'my') - { - return $this->createLink('my', 'work', 'mode=task'); - } - elseif($this->app->tab == 'project' && $execution->multiple) - { - return $this->createLink('project', 'execution', "browseType=all&projectID={$execution->project}"); - } - else - { - return $this->createLink('execution', 'browse', "executionID={$execution->id}"); - } } /** @@ -1229,6 +1222,40 @@ class taskZen extends task return $this->generalCreateResponse($task, $execution->id, $afterChoose); } + /** + * 处理批量创建任务后的返回信息。 + * The information return after process the batch create task. + * + * @param array $taskIdList + * @param object $execution + * @access protected + * @return array + */ + protected function responseAfterbatchCreate(array $taskIdList, object $execution): array + { + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); + + /* Return task id when call the API. */ + if($this->viewType == 'json' || (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $taskIdList)); + + if(isonlybody() && $this->app->tab == 'execution' || $this->config->vision == 'lite') + { + $kanbanData = $this->getKanbanData($execution); + if($execution->type == 'kanban') return print(js::closeModal('parent.parent', '', "parent.parent.updateKanban($kanbanData, 0)")); + return print(js::closeModal('parent.parent', '', "parent.parent.updateKanban(\"task\", $kanbanData)")); + } + + $response['result'] = 'success'; + $response['message'] = $this->lang->saveSuccess; + + $link = $this->createLink('execution', 'browse', "executionID={$execution->id}"); + if($this->app->tab == 'my') $link = $this->createLink('my', 'work', 'mode=task'); + if($this->app->tab == 'project' && $execution->multiple) $link = $this->createLink('project', 'execution', "browseType=all&projectID={$execution->project}"); + $response['load'] = $link; + + return $response; + } + /** * 处理开始任务后的返回信息。 * The information return after process the start task. @@ -1254,7 +1281,7 @@ class taskZen extends task * @access protected * @return array */ - protected function removeDuplicate4BatchCreate(int $executionID, array $tasks): array + protected function removeDuplicateForBatchCreate(int $executionID, array $tasks): array { /* 1. 检查表单是否有重复。 Check duplicate in form data. */ $duplicateTasks = array(); @@ -1394,7 +1421,7 @@ class taskZen extends task { $now = helper::now(); $task = form::data($this->config->task->form->finish) - ->setIF(!$this->post->realStarted and helper::isZeroDate($oldTask->realStarted), 'realStarted', $now) + ->setIF(!$this->post->realStarted && helper::isZeroDate($oldTask->realStarted), 'realStarted', $now) ->setDefault('assignedTo', $oldTask->openedBy) ->get(); diff --git a/test/data/kanbancolumn.yaml b/test/data/kanbancolumn.yaml index ad5cd87243..a27fe3f1bd 100644 --- a/test/data/kanbancolumn.yaml +++ b/test/data/kanbancolumn.yaml @@ -17,7 +17,7 @@ fields: - field: color range: "#333" - field: limit - range: "" + range: '`-1`' - field: order range: 1-4 - field: archived diff --git a/test/data/kanbanlane.yaml b/test/data/kanbanlane.yaml index 52e329671b..5b81157bce 100644 --- a/test/data/kanbanlane.yaml +++ b/test/data/kanbanlane.yaml @@ -21,7 +21,5 @@ fields: range: "#7ec5ff" - field: order range: 5-10000:5 - - field: lastEditedTime - range: "" - field: deleted range: "0" diff --git a/test/data/taskspec.yaml b/test/data/taskspec.yaml index febb226f21..eb67b6f866 100644 --- a/test/data/taskspec.yaml +++ b/test/data/taskspec.yaml @@ -28,17 +28,3 @@ fields: postfix: "" loop: 0 format: "" - - field: estStarted - note: "预计开始" - range: "" - prefix: "" - postfix: "" - loop: 0 - format: "" - - field: deadline - note: "截止时间" - range: "" - prefix: "" - postfix: "" - loop: 0 - format: ""