* testcase: refactor methods to batch change branch of cases.
This commit is contained in:
@@ -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
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user