* Refactor unlinkCases method and fix unlink story error.

This commit is contained in:
tianshujie
2023-09-11 09:10:06 +08:00
parent 2b4f496997
commit 2bbdeac8ed
3 changed files with 31 additions and 30 deletions
+20 -12
View File
@@ -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 ++;
}
}
+9 -12
View File
@@ -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();
}
}
+2 -6
View File
@@ -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'); // 敏捷执行解除关联用例