* Bug batchChangePlan batchChangeBranch method.

This commit is contained in:
zenggang
2023-05-22 09:26:41 +00:00
parent 929b14392c
commit 80ee36948e
7 changed files with 251 additions and 89 deletions
+18 -29
View File
@@ -676,23 +676,22 @@ class bug extends control
}
/**
* 批量修改bug分支。
* Batch change branch.
*
* @param int $branchID
* @access public
* @return void
*/
public function batchChangeBranch($branchID)
public function batchChangeBranch(int $branchID)
{
if($this->post->bugIDList)
{
$bugIdList = $this->post->bugIDList;
$bugIdList = array_unique($bugIdList);
$oldBugs = $this->bug->getByIdList($bugIdList);
$skipBugIdList = '';
unset($_POST['bugIDList']);
$bugIdList = array_unique($this->post->bugIDList);
$oldBugs = $this->bug->getByIdList($bugIdList);
/* Remove condition mismatched bugs. */
$skipBugIdList = '';
foreach($bugIdList as $key => $bugID)
{
$oldBug = $oldBugs[$bugID];
@@ -707,22 +706,21 @@ class bug extends control
}
}
if(!empty($skipBugIdList))
{
echo js::alert(sprintf($this->lang->bug->noSwitchBranch, $skipBugIdList));
}
if(!empty($skipBugIdList)) echo js::alert(sprintf($this->lang->bug->noSwitchBranch, $skipBugIdList));
$allChanges = $this->bug->batchChangeBranch($bugIdList, $branchID, $oldBugs);
if(dao::isError()) return print(js::error(dao::getError()));
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
/* Record log. */
$this->loadModel('action');
foreach($allChanges as $bugID => $changes)
{
$this->loadModel('action');
$actionID = $this->action->create('bug', $bugID, 'Edited');
$this->action->logHistory($actionID, $changes);
}
}
$this->loadModel('score')->create('ajax', 'batchOther');
return print(js::locate($this->session->bugList, 'parent'));
return array('load' => $this->session->bugList, 'closeModal' => true);
}
/**
@@ -737,9 +735,7 @@ class bug extends control
{
if($this->post->bugIDList)
{
$bugIdList = $this->post->bugIDList;
$bugIdList = array_unique($bugIdList);
$bugIdList = array_unique($this->post->bugIDList);
$this->bug->batchChangeModule($bugIdList, $moduleID);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
}
@@ -748,30 +744,23 @@ class bug extends control
}
/**
* 批量修改bug计划。
* Batch change the plan of bug.
*
* @param int $planID
* @access public
* @return void
*/
public function batchChangePlan($planID)
public function batchChangePlan(int $planID)
{
if($this->post->bugIDList)
{
$bugIDList = $this->post->bugIDList;
$bugIDList = array_unique($bugIDList);
unset($_POST['bugIDList']);
$allChanges = $this->bug->batchChangePlan($bugIDList, $planID);
if(dao::isError()) return print(js::error(dao::getError()));
foreach($allChanges as $bugID => $changes)
{
$this->loadModel('action');
$actionID = $this->action->create('bug', $bugID, 'Edited');
$this->action->logHistory($actionID, $changes);
}
$bugIdList = array_unique($this->post->bugIDList);
$this->bug->batchChangePlan($bugIdList, $planID);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
}
$this->loadModel('score')->create('ajax', 'batchOther');
return print(js::locate($this->session->bugList, 'parent'));
return array('load' => $this->session->bugList, 'closeModal' => true);
}
/**
+25 -25
View File
@@ -840,6 +840,7 @@ class bugModel extends model
}
/**
* 批量修改bug分支。
* Batch change branch.
*
* @param array $bugIDList
@@ -848,20 +849,18 @@ class bugModel extends model
* @access public
* @return array
*/
public function batchChangeBranch($bugIDList, $branchID, $oldBugs)
public function batchChangeBranch(array $bugIDList, int $branchID, array $oldBugs): array
{
$now = helper::now();
$allChanges = array();
foreach($bugIDList as $bugID)
{
$oldBug = $oldBugs[$bugID];
if($branchID == $oldBug->branch) continue;
$bug = new stdclass();
$bug->lastEditedBy = $this->app->user->account;
$bug->lastEditedDate = $now;
$bug->branch = $branchID;
$bug->branch = $branchID;
$this->bugTao->updateByID((int)$bugID, $bug);
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
if(!dao::isError()) $allChanges[$bugID] = common::createChanges($oldBug, $bug);
}
return $allChanges;
@@ -879,7 +878,6 @@ class bugModel extends model
public function batchChangeModule(array $bugIdList, int $moduleID): bool
{
$this->loadModel('action');
$now = helper::now();
$oldBugs = $this->getByIdList($bugIdList);
foreach($bugIdList as $bugID)
@@ -889,11 +887,8 @@ class bugModel extends model
/* Change the module of bug. */
$bug = new stdclass();
$bug->lastEditedBy = $this->app->user->account;
$bug->lastEditedDate = $now;
$bug->module = $moduleID;
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
$bug->module = $moduleID;
$this->bugTao->updateByID((int)$bugID, $bug);
if(dao::isError()) return false;
/* Record logs. */
@@ -905,42 +900,47 @@ class bugModel extends model
}
/**
* 批量修改bug计划。
* Batch change the plan of bug.
*
* @param array $bugIDList
* @param int $planID
* @access public
* @return array
* @return void
*/
public function batchChangePlan($bugIDList, $planID)
public function batchChangePlan(array $bugIDList, int $planID): void
{
$now = helper::now();
$allChanges = array();
$oldBugs = $this->getByList($bugIDList);
$this->loadModel('action');
$oldBugs = $this->getByIdList($bugIDList);
$unlinkPlans = array();
$link2Plans = array();
foreach($bugIDList as $bugID)
{
$oldBug = $oldBugs[$bugID];
if($planID == $oldBug->plan) continue;
/* Bugs link to plans and bugs unlink to plans. */
$unlinkPlans[$oldBug->plan] = empty($unlinkPlans[$oldBug->plan]) ? $bugID : "{$unlinkPlans[$oldBug->plan]},$bugID";
$link2Plans[$planID] = empty($link2Plans[$planID]) ? $bugID : "{$link2Plans[$planID]},$bugID";
/* Update bug plan. */
$bug = new stdclass();
$bug->lastEditedBy = $this->app->user->account;
$bug->lastEditedDate = $now;
$bug->plan = $planID;
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
if(!dao::isError()) $allChanges[$bugID] = common::createChanges($oldBug, $bug);
$bug->plan = $planID;
$this->bugTao->updateByID((int)$bugID, $bug);
if(!dao::isError())
{
$changes = common::createChanges($oldBug, $bug);
$actionID = $this->action->create('bug', $bugID, 'Edited');
$this->action->logHistory($actionID, $changes);
}
}
/* Record plan action. */
if(!dao::isError())
{
$this->loadModel('action');
foreach($unlinkPlans as $planID => $bugs) $this->action->create('productplan', $planID, 'unlinkbug', '', $bugs);
foreach($link2Plans as $planID => $bugs) $this->action->create('productplan', $planID, 'linkbug', '', $bugs);
}
return $allChanges;
}
/**
+18
View File
@@ -493,4 +493,22 @@ class bugTao extends bugModel
return !dao::isError();
}
/**
* 更新bug根据id。
* Update bug by id.
*
* @param int $bugID
* @param object $bug
* @access protected
* @return bool
*/
protected function updateByID(int $bugID, object $bug): bool
{
if(!isset($bug->lastEditedBy)) $bug->lastEditedBy = $this->app->user->account;
if(!isset($bug->lastEditedDate)) $bug->lastEditedDate = helper::now();
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq($bugID)->exec();
return !dao::isError();
}
}
+35 -5
View File
@@ -1064,9 +1064,9 @@ class bugTest
*/
public function batchChangeBranchTest($bugIDList, $branchID, $bugID)
{
$bugs = $this->objectModel->getByIdList($bugIDList);
$oldBugs = $this->objectModel->getByIdList($bugIDList);
$object = $this->objectModel->batchChangeBranch($bugIDList, $branchID, $bugs);
$object = $this->objectModel->batchChangeBranch($bugIDList, $branchID, $oldBugs);
if(dao::isError())
{
@@ -1087,7 +1087,7 @@ class bugTest
* @access public
* @return array
*/
public function batchChangeModuleTest($bugIDList, $moduleID, $bugID)
public function batchChangeModuleTest(array $bugIDList, int $moduleID, int $bugID)
{
$oldBugs = $this->objectModel->getByIdList($bugIDList);
@@ -1117,8 +1117,10 @@ class bugTest
* @access public
* @return array
*/
public function batchChangePlanTest($bugIDList, $planID, $bugID)
public function batchChangePlanTest(array $bugIDList, int $planID, int $bugID)
{
$oldBugs = $this->objectModel->getByIdList($bugIDList);
$object = $this->objectModel->batchChangePlan($bugIDList, $planID);
if(dao::isError())
@@ -1127,10 +1129,38 @@ class bugTest
}
else
{
return !empty($object[$bugID]) ? $object[$bugID] : 0;
$newBugs = $this->objectModel->getByIdList($bugIDList);
if(!empty($newBugs[$bugID]))
{
$changes = common::createChanges($oldBugs[$bugID], $newBugs[$bugID]);
return $changes;
}
}
}
/**
* Test update bug by id.
*
* @param int $bugID
* @param array $data
* @access public
* @return viod
*/
public function updateByIDTest(int $bugID, array $data, $getBug = false)
{
$oldBug = $this->objectModel->getByID($bugID);
$result = $this->objectModel->updateByID($bugID, (object)$data);
if(dao::isError()) return dao::getError();
$newBug = $this->objectModel->getByID($bugID);
if($getBug) return $newBug;
$changes = common::createChanges($oldBug, $newBug);
return $changes;
}
/**
* Test batch resolve bugs.
*
+52 -15
View File
@@ -2,29 +2,66 @@
<?php
include dirname(__FILE__, 5) . "/test/lib/init.php";
include dirname(__FILE__, 2) . '/bug.class.php';
su('admin');
/**
title=测试bugModel->batchChangeBranch();
timeout=0
cid=1
pid=1
修改分支为主干 未发生变化 >> 0
修改分支为分支11 >> branch,0,11
修改分支为分支12 >> branch,11,12
修改分支为主干 未发生变化 >> 0
修改分支为分支9 >> branch,0,9
修改分支为分支10 >> branch,9,10
修改分支为主干 未发生变化 >> 0
修改分支为分支7 >> branch,0,7
修改分支为分支8 >> branch,7,8
修改分支为主干 未发生变化 >> 0
修改分支为分支37 >> branch,0,37
修改分支为分支38 >> branch,37,38
- 修改分支为主干 未发生变化 @0
- 修改分支为分支11
- 第0条的field属性 @branch
- 第0条的old属性 @0
- 第0条的new属性 @11
- 修改分支为分支12
- 第0条的field属性 @branch
- 第0条的old属性 @11
- 第0条的new属性 @12
- 修改分支为主干 未发生变化 @0
- 修改分支为分支9
- 第0条的field属性 @branch
- 第0条的old属性 @0
- 第0条的new属性 @9
- 修改分支为分支10
- 第0条的field属性 @branch
- 第0条的old属性 @9
- 第0条的new属性 @10
- 修改分支为主干 未发生变化 @0
- 修改分支为分支7
- 第0条的field属性 @branch
- 第0条的old属性 @0
- 第0条的new属性 @7
- 修改分支为分支8
- 第0条的field属性 @branch
- 第0条的old属性 @7
- 第0条的new属性 @8
- 修改分支为主干 未发生变化 @0
- 修改分支为分支37
- 第0条的field属性 @branch
- 第0条的old属性 @0
- 第0条的new属性 @37
- 修改分支为分支38
- 第0条的field属性 @branch
- 第0条的old属性 @37
- 第0条的new属性 @38
*/
zdTable('bug')->gen(200);
zdTable('branch')->gen(50);
$bugIDList1 = array('136', '137', '138');
$bugIDList2 = array('133', '134', '135');
$bugIDList3 = array('130', '131', '132');
@@ -47,4 +84,4 @@ r($bug->batchChangeBranchTest($bugIDList3, $branchList3[1], $bugIDList3[1])) &&
r($bug->batchChangeBranchTest($bugIDList3, $branchList3[2], $bugIDList3[2])) && p('0:field,old,new') && e('branch,7,8'); // 修改分支为分支8
r($bug->batchChangeBranchTest($bugIDList4, $branchList4[0], $bugIDList4[0])) && p() && e('0'); // 修改分支为主干 未发生变化
r($bug->batchChangeBranchTest($bugIDList4, $branchList4[1], $bugIDList4[1])) && p('0:field,old,new') && e('branch,0,37'); // 修改分支为分支37
r($bug->batchChangeBranchTest($bugIDList4, $branchList4[2], $bugIDList4[2])) && p('0:field,old,new') && e('branch,37,38'); // 修改分支为分支38
r($bug->batchChangeBranchTest($bugIDList4, $branchList4[2], $bugIDList4[2])) && p('0:field,old,new') && e('branch,37,38'); // 修改分支为分支38
+53 -15
View File
@@ -2,29 +2,67 @@
<?php
include dirname(__FILE__, 5) . "/test/lib/init.php";
include dirname(__FILE__, 2) . '/bug.class.php';
su('admin');
su('user1');
/**
title=测试bugModel->batchChangePlan();
timeout=0
cid=1
pid=1
修改计划为0 未发生变化 >> 0
修改计划为计划1 >> plan,0,1
修改计划为计划2 >> plan,1,2
修改计划为0 未发生变化 >> 0
修改计划为计划1 >> plan,0,1
修改计划为计划2 >> plan,1,2
修改计划为0 未发生变化 >> 0
修改计划为计划1 >> plan,0,1
修改计划为计划2 >> plan,1,2
修改计划为0 未发生变化 >> 0
修改计划为计划1 >> plan,0,1
修改计划为计划2 >> plan,1,2
- 修改计划为0 未发生变化 @0
- 修改计划为计划1
- 第0条的field属性 @plan
- 第0条的old属性 @0
- 第0条的new属性 @1
- 修改计划为计划2
- 第0条的field属性 @plan
- 第0条的old属性 @1
- 第0条的new属性 @2
- 修改计划为0 未发生变化 @0
- 修改计划为计划1
- 第0条的field属性 @plan
- 第0条的old属性 @0
- 第0条的new属性 @1
- 修改计划为计划2
- 第0条的field属性 @plan
- 第0条的old属性 @1
- 第0条的new属性 @2
- 修改计划为0 未发生变化 @0
- 修改计划为计划1
- 第0条的field属性 @plan
- 第0条的old属性 @0
- 第0条的new属性 @1
- 修改计划为计划2
- 第0条的field属性 @plan
- 第0条的old属性 @1
- 第0条的new属性 @2
- 修改计划为0 未发生变化 @0
- 修改计划为计划1
- 第0条的field属性 @plan
- 第0条的old属性 @0
- 第0条的new属性 @1
- 修改计划为计划2
- 第0条的field属性 @plan
- 第0条的old属性 @1
- 第0条的new属性 @2
*/
zdTable('bug')->gen(200);
zdTable('productplan')->gen(10);
$bugIDList1 = array('136', '137', '138');
$bugIDList2 = array('133', '134', '135');
$bugIDList3 = array('130', '131', '132');
@@ -44,4 +82,4 @@ r($bug->batchChangePlanTest($bugIDList3, $planList[1], $bugIDList3[1])) && p('0:
r($bug->batchChangePlanTest($bugIDList3, $planList[2], $bugIDList3[2])) && p('0:field,old,new') && e('plan,1,2'); // 修改计划为计划2
r($bug->batchChangePlanTest($bugIDList4, $planList[0], $bugIDList4[0])) && p() && e('0'); // 修改计划为0 未发生变化
r($bug->batchChangePlanTest($bugIDList4, $planList[1], $bugIDList4[1])) && p('0:field,old,new') && e('plan,0,1'); // 修改计划为计划1
r($bug->batchChangePlanTest($bugIDList4, $planList[2], $bugIDList4[2])) && p('0:field,old,new') && e('plan,1,2'); // 修改计划为计划2
r($bug->batchChangePlanTest($bugIDList4, $planList[2], $bugIDList4[2])) && p('0:field,old,new') && e('plan,1,2'); // 修改计划为计划2
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/bug.class.php';
su('user1');
/**
title=bugTao->updateByID();
timeout=0
cid=1
- 更新bug title
- 第0条的field属性 @title
- 第0条的old属性 @BUG1
- 第0条的new属性 @更新bug
- 更新bug branch
- 第0条的field属性 @branch
- 第0条的old属性 @0
- 第0条的new属性 @1
- 更新bug module
- 第0条的field属性 @module
- 第0条的old属性 @1823
- 第0条的new属性 @3
- 更新bug plan
- 第0条的field属性 @plan
- 第0条的old属性 @4
- 第0条的new属性 @10
- 更新bug 后最后编辑人属性lastEditedBy @user1
*/
$bug = zdTable('bug')->gen(10);
$bugIDList = array(1, 2, 3, 4, 5, 6, 7);
$updateName = array('title' => '更新bug');
$updateBranch = array('branch' => 1);
$updateModule = array('module' => 3);
$updatePlan = array('plan' => 10);
$bug = new bugTest();
r($bug->updateByIDTest($bugIDList[0], $updateName)) && p('0:field,old,new') && e('title,BUG1,更新bug'); //更新bug title
r($bug->updateByIDTest($bugIDList[1], $updateBranch)) && p('0:field,old,new') && e('branch,0,1'); //更新bug branch
r($bug->updateByIDTest($bugIDList[2], $updateModule)) && p('0:field,old,new') && e('module,1823,3'); //更新bug module
r($bug->updateByIDTest($bugIDList[3], $updatePlan)) && p('0:field,old,new') && e('plan,4,10'); //更新bug plan
r($bug->updateByIDTest($bugIDList[5], $updatePlan, true)) && p('lastEditedBy') && e('user1'); //更新bug 后最后编辑人