diff --git a/module/execution/model.php b/module/execution/model.php index e511cf7b1a..1767db833e 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -3208,17 +3208,25 @@ class executionModel extends model } /* 取消该需求关联的所有任务。*/ - $tasks = $this->dao->select('id')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('execution')->eq($executionID)->andWhere('status')->in('wait,doing')->fetchPairs('id'); - foreach($tasks as $taskID) + $tasks = $this->dao->select('*')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('execution')->eq($executionID)->andWhere('status')->in('wait,doing')->fetchAll(); + $now = helper::now(); + foreach($tasks as $task) { - if(empty($taskID)) continue; - $changes = $this->loadModel('task')->cancel($taskID); - $actionID = $this->action->create('task', $taskID, 'Canceled'); - $this->action->logHistory($actionID, $changes); + if(empty($task)) continue; + $task->status = 'cancel'; + $task->assignedTo = $task->openedBy; + $task->assignedDate = $now; + $task->canceledBy = $task->lastEditedBy = $this->app->user->account; + $task->canceledDate = $task->lastEditedDate = $now; + $task->finishedBy = ''; + $task->finishedDate = null; + + $this->loadModel('task')->cancel($task); } } /** + * 解除用例跟执行的关联关系。 * Unlink cases. * * @param int $executionID @@ -3226,22 +3234,22 @@ class executionModel extends model * @access public * @return void */ - public function unlinkCases($executionID, $storyID) + public function unlinkCases(int $executionID, int $storyID): void { $this->loadModel('action'); $execution = $this->dao->findById($executionID)->from(TABLE_EXECUTION)->fetch(); $cases = $this->dao->select('id')->from(TABLE_CASE)->where('story')->eq($storyID)->fetchAll('id'); foreach($cases as $caseID => $case) { - $this->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->andWhere('`case`')->eq($caseID)->limit(1)->exec(); + $this->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->andWhere('`case`')->eq($caseID)->exec(); $action = $execution->type == 'project' ? 'unlinkedfromproject' : 'unlinkedfromexecution'; - if($execution->multiple or $execution->type == 'project') $this->action->create('case', $caseID, $action, '', $executionID); + if($execution->multiple || $execution->type == 'project') $this->action->create('case', $caseID, $action, '', $executionID); /* Sync unlink case in no multiple execution. */ - if(empty($execution->multiple) and $execution->type != 'project') + if(empty($execution->multiple) && $execution->type != 'project') { $this->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($execution->project)->andWhere('`case`')->eq($caseID)->limit(1)->exec(); - $this->loadModel('action')->create('case', $caseID, 'unlinkedfromproject', '', $execution->project); + $this->action->create('case', $caseID, 'unlinkedfromproject', '', $execution->project); } } @@ -3250,7 +3258,7 @@ class executionModel extends model foreach($cases as $case) { if($case->order != $order) $this->dao->update(TABLE_PROJECTCASE)->set('`order`')->eq($order)->where('project')->eq($executionID)->andWhere('`case`')->eq($case->case)->exec(); - $order++; + $order ++; } } diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index de416f0838..b23243e786 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -1518,32 +1518,29 @@ class executionTest } /** - * function unlinkCases test by execution + * 解除用例跟执行的关联关系。 + * Unlink cases. * - * @param string $executionID - * @param string $productID - * @param string $storyID + * @param int $executionID + * @param int $productID + * @param int $storyID * @access public * @return array */ - public function unlinkCasesTest($executionID, $productID, $storyID) + public function unlinkCasesTest(int $executionID, int $productID, int $storyID): array { - global $tester; - - $tester->dbh->query("delete from zt_projectcase where project = $executionID"); + $this->executionModel->dao->delete()->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->exec(); $this->executionModel->linkCases($executionID, $productID, $storyID); $this->executionModel->unlinkCases($executionID, $storyID); if(dao::isError()) { - $error = dao::getError(); - return $error; + return dao::getError(); } else { - $object = $tester->dbh->query("select * from zt_projectcase where project = $executionID")->fetchAll(); - return $object; + return $this->executionModel->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->fetchAll(); } } diff --git a/module/execution/test/model/unlinkcases.php b/module/execution/test/model/unlinkcases.php index 1cb7f6a5d7..7c9ec9bd1b 100755 --- a/module/execution/test/model/unlinkcases.php +++ b/module/execution/test/model/unlinkcases.php @@ -41,19 +41,15 @@ su('admin'); /** title=测试executionModel->unlinkCasesTest(); +timeout=0 cid=1 -pid=1 - -敏捷执行解除关联用例 >> 0 -瀑布执行解除关联用例 >> 0 -看板执行解除关联用例 >> 0 */ $executionIDList = array('3', '4', '5'); $products = array('1', '43', '68'); $stories = array('2', '170', '270'); -$count = array('0','1'); +$count = array(0, 1); $execution = new executionTest(); r($execution->unlinkCasesTest($executionIDList[0], $products[0], $stories[0])) && p() && e('0'); // 敏捷执行解除关联用例