* Rewrite story batchchangebranch. Code for task #102984.

This commit is contained in:
wangyidong
2023-10-09 09:30:12 +08:00
parent 53bcd1a710
commit 2d6cdf3678
5 changed files with 57 additions and 53 deletions
+1 -1
View File
@@ -329,7 +329,7 @@ class productplanModel extends model
* @access public
* @return array
*/
public function getPlansByStories($storyIdList)
public function getPlansByStories(array $storyIdList): array
{
if(empty($storyIdList)) return array();
return $this->dao->select('t2.id as storyID, t3.*')->from(TABLE_PLANSTORY)->alias('t1')
+18 -17
View File
@@ -1019,10 +1019,13 @@ class story extends control
* @access public
* @return void
*/
public function batchChangeBranch($branchID, $confirm = '', $storyIdList = '', $storyType = 'story')
public function batchChangeBranch(int $branchID, string $confirm = '', string $storyIdList = '', string $storyType = 'story')
{
if(empty($storyIdList) and empty($_POST['storyIdList'])) return print(js::locate($this->session->storyList, 'parent'));
if(empty($storyIdList) and empty($_POST['storyIdList'])) return $this->send(array('result' => 'success', 'load' => true));
if(!empty($_POST['storyIdList'])) $storyIdList = $this->post->storyIdList;
if(is_string($storyIdList)) $storyIdList = array_filter(explode(',', $storyIdList));
$storyIdList = array_unique($storyIdList);
$plans = $this->loadModel('productplan')->getPlansByStories($storyIdList);
if(empty($confirm))
{
@@ -1034,17 +1037,17 @@ class story extends control
/* Determine whether there is a conflict between the branch of the story and the linked plan. */
foreach($storyIdList as $storyID)
{
if($stories[$storyID]->branch != $branchID and $branchID != BRANCH_MAIN and isset($plans[$storyID]))
if($stories[$storyID]->branch == $branchID) continue;
if($branchID == BRANCH_MAIN) continue;
if(!isset($plans[$storyID])) continue;
foreach($plans[$storyID] as $plan)
{
foreach($plans[$storyID] as $plan)
{
if($plan->branch != $branchID)
{
$conflictStoryIdList .= '[' . $storyID . ']';
$conflictStoryArray[] = $storyID;
break;
}
}
if($plan->branch == $branchID) continue;
$conflictStoryIdList .= "[{$storyID}]";
$conflictStoryArray[] = $storyID;
break;
}
}
@@ -1056,21 +1059,19 @@ class story extends control
$storyIdList = implode(',', $storyIdList);
$confirmURL = $this->createLink('story', 'batchChangeBranch', "branchID=$branchID&confirm=yes&storyIdList=$storyIdList&storyType=$storyType");
$cancelURL = $this->createLink('story', 'batchChangeBranch', "branchID=$branchID&confirm=no&storyIdList=$normalStotyIdList&storyType=$storyType");
return print(js::confirm(sprintf($this->lang->story->confirmChangeBranch, $conflictStoryIdList ), $confirmURL, $cancelURL));
return $this->send(array('result' => 'success', 'load' => array('confirm' => sprintf($this->lang->story->confirmChangeBranch, $conflictStoryIdList), 'confirmed' => $confirmURL, 'canceled' => $cancelURL)));
}
}
if(is_string($storyIdList)) $storyIdList = array_filter(explode(',', $storyIdList));
$storyIdList = array_unique($storyIdList);
$allChanges = $this->story->batchChangeBranch($storyIdList, $branchID, $confirm, $plans);
if(dao::isError()) return print(js::error(dao::getError()));
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
foreach($allChanges as $storyID => $changes)
{
$actionID = $this->action->create('story', $storyID, 'Edited');
$this->action->logHistory($actionID, $changes);
}
if(!dao::isError()) $this->loadModel('score')->create('ajax', 'batchOther');
echo js::reload('parent');
return $this->send(array('result' => 'success', 'load' => true));
}
/**
+11 -21
View File
@@ -1571,23 +1571,19 @@ class storyModel extends model
*
* @param array $storyIdList
* @param int $branchID
* @param string $confirm
* @param string $confirm yes|null
* @param array $plans
* @access public
* @return array
*/
public function batchChangeBranch($storyIdList, $branchID, $confirm = '', $plans = array())
public function batchChangeBranch(array $storyIdList, int $branchID, string $confirm = '', array $plans = array()): array
{
$now = helper::now();
$allChanges = array();
$oldStories = $this->getByList($storyIdList);
$story = current($oldStories);
$productID = $story->product;
$mainModules = $this->dao->select('id')->from(TABLE_MODULE)
->where('root')->eq($productID)
->andWhere('branch')->eq(0)
->andWhere('type')->eq('story')
->fetchPairs('id');
$mainModules = $this->dao->select('id')->from(TABLE_MODULE)->where('root')->eq($productID)->andWhere('branch')->eq(0)->andWhere('type')->eq('story')->fetchPairs('id', 'id');
foreach($storyIdList as $storyID)
{
@@ -1604,30 +1600,24 @@ class storyModel extends model
{
if($confirm == 'yes')
{
$planIdList = '';
$conflictPlanIdList = '';
$planIdList = array();
$conflictPlanIdList = array();
/* Determine whether there is a conflict between the branch of the story and the linked plan. */
if($oldStory->branch != $branchID and $branchID != BRANCH_MAIN and isset($plans[$storyID]))
{
foreach($plans[$storyID] as $planID => $plan)
{
if($plan->branch != $branchID)
{
$conflictPlanIdList .= $planID . ',';
}
else
{
$planIdList .= $planID . ',';
}
if($plan->branch != $branchID) $conflictPlanIdList[$planID] = $planID;
if($plan->branch == $branchID) $planIdList[$planID] = $planID;
}
/* If there is a conflict in the linked plan when the branch story to be modified, the linked with the conflicting plan will be removed. */
if($conflictPlanIdList)
if($conflictPlanIdList) $this->dao->delete()->from(TABLE_PLANSTORY)->where('story')->eq($storyID)->andWhere('plan')->in(implode(',', $conflictPlanIdList))->exec();
if($planIdList)
{
$story->plan = $planIdList;
$this->dao->delete()->from(TABLE_PLANSTORY)->where('story')->eq($storyID)->andWhere('plan')->in($conflictPlanIdList)->exec();
$this->dao->update(TABLE_STORY)->set('plan')->eq($planIdList)->where('id')->eq($storyID)->exec();
$story->plan = implode(',', $planIdList);
$this->dao->update(TABLE_STORY)->set('plan')->eq($story->plan)->where('id')->eq($storyID)->exec();
}
}
}
+25 -12
View File
@@ -4,7 +4,13 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/story.class.php';
su('admin');
zdTable('story')->gen(20);
$story = zdTable('story');
$story->product->range('1{3},2{3}');
$story->branch->range('0{3},0-4');
$story->plan->range('``{3},2,``,3');
$story->status->range('draft,active,closed');
$story->gen(6);
zdTable('storyspec')->gen(20);
/**
@@ -12,19 +18,26 @@ title=测试 storyModel->batchChangeBranch();
cid=1
pid=1
批量修改需求的所属分支,判断被修改分支需求的数量 >> 3
批量修改需求的所属分支,判断需求2修改后的分支ID >> 2
批量修改需求的所属分支,判断需求4修改后的分支ID >> 2
批量修改需求的所属分支,判断需求6修改后的分支ID >> 2
*/
$story = new storyTest();
$storyIdList = array(2, 4, 6);
$plans[2][1] = new stdclass();
$plans[2][1]->branch = 2;
$plans[2][2] = new stdclass();
$plans[2][2]->branch = 3;
$plans[2][3] = new stdclass();
$plans[2][3]->branch = 3;
$stories = $story->batchChangeBranchTest($storyIdList, 2);
$story = new storyTest();
$stories1 = $story->batchChangeBranchTest($storyIdList, 2);
$stories2 = $story->batchChangeBranchTest($storyIdList, 3, 'yes', $plans);
r(count($stories)) && p() && e('3'); // 批量修改需求的所属分支,判断被修改分支需求的数量
r($stories) && p('2:branch') && e('2'); // 批量修改需求的所属分支,判断需求2修改后的分支ID
r($stories) && p('4:branch') && e('2'); // 批量修改需求的所属分支,判断需求4修改后的分支ID
r($stories) && p('6:branch') && e('2'); // 批量修改需求的所属分支,判断需求6修改后的分支ID
r(count($stories1)) && p() && e('3'); // 批量修改需求的所属分支,判断被修改分支需求的数量
r($stories1) && p('2:branch') && e('2'); // 批量修改需求的所属分支,判断需求2修改后的分支ID
r($stories1) && p('4:branch') && e('2'); // 批量修改需求的所属分支,判断需求4修改后的分支ID
r($stories1) && p('6:branch') && e('2'); // 批量修改需求的所属分支,判断需求6修改后的分支ID
r(count($stories2)) && p() && e('3'); // 批量修改需求的所属分支,并同步修改计划,判断被修改分支需求的数量
r($stories2[2]) && p('branch|plan', '|') && e('3|2,3'); // 批量修改需求的所属分支,并同步修改计划,判断需求2修改后的分支ID和计划
r($stories2) && p('4:branch') && e('3'); // 批量修改需求的所属分支,并同步修改计划,判断需求4修改后的分支ID
r($stories2) && p('6:branch') && e('3'); // 批量修改需求的所属分支,并同步修改计划,判断需求6修改后的分支ID
+2 -2
View File
@@ -484,14 +484,14 @@ class storyTest
* @access public
* @return void
*/
public function batchChangeBranchTest($storyIdList, $branchID, $confirm = '', $plans = array())
public function batchChangeBranchTest(array $storyIdList, int $branchID, string $confirm = '', array $plans = array())
{
$changes = $this->objectModel->batchChangeBranch($storyIdList, $branchID, $confirm, $plans);
if(dao::isError()) return dao::getError();
$storyIdList = array_keys($changes);
return $this->objectModel->dao->select('*')->from(TABLE_STORY)->where('id')->in($storyIdList)->fetchAll();
return $this->objectModel->dao->select('*')->from(TABLE_STORY)->where('id')->in($storyIdList)->fetchAll('id');
}
/**