* Finish task #36430.

This commit is contained in:
tianshujie98
2021-03-15 09:40:46 +08:00
parent c55c18093c
commit b7cf68c746
10 changed files with 133 additions and 13 deletions
+69 -1
View File
@@ -2043,12 +2043,51 @@ class executionModel extends model
$data->version = $versions[$storyID];
$data->order = ++$lastOrder;
$this->dao->insert(TABLE_PROJECTSTORY)->data($data)->exec();
$this->story->setStage($storyID);
$this->linkCases($executionID, (int)$products[$storyID], $storyID);
$action = $executionID == $this->session->PRJ ? 'linked2project' : 'linked2execution';
$this->action->create('story', $storyID, $action, '', $executionID);
}
}
/**
* Link cases.
*
* @param int $executionID
* @param int $productID
* @param int $storyID
* @param string $type
* @access public
* @return void
*/
public function linkCases($executionID, $productID, $storyID, $type = '')
{
$this->loadModel('action');
$linkedCases = $this->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->orderBy('order_desc')->fetchPairs('case', 'order');
$lastCaseOrder = empty($linkedCases) ? 0 : reset($linkedCases);
$cases = $this->dao->select('id, version')->from(TABLE_CASE)->where('story')->eq($storyID)->fetchParis('id');
foreach($cases as $caseID => $case)
{
if(isset($linkedCases[$caseID])) continue;
$object = new stdclass();
$object->project = $executionID;
$object->product = $productID;
$object->case = $caseID;
$object->version = $case->version;
$object->order = ++$lastCaseOrder;
$this->dao->insert(TABLE_PROJECTCASE)->data($object)->exec();
$action = $executionID == $this->session->PRJ ? 'linked2project' : 'linked2execution';
if($type) $action = $type == 'project' ? 'linked2project' : 'linked2execution';
$this->action->create('case', $caseID, $action, '', $executionID);
}
}
/**
* Link all stories by execution.
*
@@ -2103,7 +2142,7 @@ class executionModel extends model
public function unlinkStory($executionID, $storyID)
{
$execution = $this->dao->findById($executionID)->from(TABLE_EXECUTION)->fetch();
if($execution->type == 'execution')
if($execution->type == 'project')
{
$executions = $this->dao->select('*')->from(TABLE_EXECUTION)->where('parent')->eq($executionID)->fetchAll('id');
$executionStories = $this->dao->select('project,story')->from(TABLE_PROJECTSTORY)->where('story')->eq($storyID)->andWhere('project')->in(array_keys($executions))->fetchAll();
@@ -2120,6 +2159,7 @@ class executionModel extends model
}
$this->loadModel('story')->setStage($storyID);
$this->unlinkCases($executionID, $storyID);
$objectType = $executionID == $this->session->PRJ ? unlinkedfromproject : unlinkedfromexecution;
$this->loadModel('action')->create('story', $storyID, $objectType, '', $executionID);
@@ -2133,6 +2173,34 @@ class executionModel extends model
}
}
/**
* Unlink cases.
*
* @param int $executionID
* @param int $storyID
* @access public
* @return void
*/
public function unlinkCases($executionID, $storyID)
{
$this->loadModel('action');
$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();
$action = $executionID == $this->session->PRJ ? 'unlinkedfromproject' : 'unlinkedfromexecution';
$this->action->create('case', $caseID, $action, '', $executionID);
}
$order = 1;
$cases = $this->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($executionID)->orderBy('order')->fetchAll();
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++;
}
}
/**
* Get team members.
*