* testcase: refactor methods to batch change branch of cases.

This commit is contained in:
liugang
2023-08-14 15:07:03 +08:00
parent 21e8e01609
commit 4e17ebfd23
2 changed files with 24 additions and 26 deletions
+1 -10
View File
@@ -1422,17 +1422,8 @@ class testcase extends control
{
if($this->post->caseIDList)
{
$caseIDList = $this->post->caseIDList;
$caseIDList = array_unique($caseIDList);
unset($_POST['caseIDList']);
$allChanges = $this->testcase->batchChangeBranch($caseIDList, $branchID);
$this->testcase->batchChangeBranch($this->post->caseIDList, $branchID);
if(dao::isError()) return print(js::error(dao::getError()));
foreach($allChanges as $caseID => $changes)
{
$this->loadModel('action');
$actionID = $this->action->create('case', $caseID, 'Edited');
$this->action->logHistory($actionID, $changes);
}
}
echo js::locate($this->session->caseList, 'parent');
+23 -16
View File
@@ -1324,28 +1324,35 @@ class testcaseModel extends model
* @param array $caseIDList
* @param int $branchID
* @access public
* @return array
* @return bool
*/
public function batchChangeBranch($caseIDList, $branchID)
{
$now = helper::now();
$allChanges = array();
$oldCases = $this->getByList($caseIDList);
foreach($caseIDList as $caseID)
$caseIDList = $this->filterIdList($caseIDList);
if(!$caseIDList) return false;
$oldCases = $this->getByList($caseIDList, "branch != {$branchID}");
$this->dao->update(TABLE_CASE)->set('branch')->eq($branchID)->where('branch')->ne($branchID)->andWhere('id')->in($caseIDList)->exec();
if(dao::isError()) return false;
$this->loadModel('action');
$case = new stdclass();
$case->branch = $branchID;
$case->lastEditedBy = $this->app->user->account;
$case->lastEditedDate = helper::now();
foreach($oldCases as $oldCase)
{
$oldCase = $oldCases[$caseID];
if($branchID == $oldCase->branch) continue;
$case = new stdclass();
$case->lastEditedBy = $this->app->user->account;
$case->lastEditedDate = $now;
$case->branch = $branchID;
$this->dao->update(TABLE_CASE)->data($case)->autoCheck()->where('id')->eq((int)$caseID)->exec();
if(!dao::isError()) $allChanges[$caseID] = common::createChanges($oldCase, $case);
$changes = common::createChanges($oldCase, $case);
if($changes)
{
$actionID = $this->action->create('case', $oldCase->id, 'edited');
$this->action->logHistory($actionID, $changes);
}
}
return $allChanges;
return !dao::isError();
}
/**