diff --git a/module/bug/control.php b/module/bug/control.php
index 07473775d2..428b3c4b45 100644
--- a/module/bug/control.php
+++ b/module/bug/control.php
@@ -766,6 +766,34 @@ class bug extends control
$this->display();
}
+ /**
+ * Batch change branch.
+ *
+ * @param int $branchID
+ * @access public
+ * @return void
+ */
+ public function batchChangeBranch($branchID)
+ {
+ if($this->post->bugIDList)
+ {
+ $bugIDList = $this->post->bugIDList;
+ $bugIDList = array_unique($bugIDList);
+ unset($_POST['bugIDList']);
+ $allChanges = $this->bug->batchChangeBranch($bugIDList, $branchID);
+ if(dao::isError()) die(js::error(dao::getError()));
+ foreach($allChanges as $bugID => $changes)
+ {
+ $this->loadModel('action');
+ $actionID = $this->action->create('bug', $bugID, 'Edited');
+ $this->action->logHistory($actionID, $changes);
+ $this->bug->sendmail($bugID, $actionID);
+ }
+ }
+ $this->loadModel('score')->create('ajax', 'batchOther');
+ die(js::locate($this->session->bugList, 'parent'));
+ }
+
/**
* Batch change the module of bug.
*
diff --git a/module/bug/model.php b/module/bug/model.php
index 65e926525f..b6802cef13 100644
--- a/module/bug/model.php
+++ b/module/bug/model.php
@@ -869,6 +869,35 @@ class bugModel extends model
$this->linkBugToBuild($bugID, $bug->resolvedBuild);
}
+ /**
+ * Batch change branch.
+ *
+ * @param array $bugIDList
+ * @param int $branchID
+ * @access public
+ * @return array
+ */
+ public function batchChangeBranch($bugIDList, $branchID)
+ {
+ $now = helper::now();
+ $allChanges = array();
+ $oldBugs = $this->getByList($bugIDList);
+ 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;
+
+ $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;
+ }
+
/**
* Batch change the module of bug.
*
diff --git a/module/bug/view/browse.html.php b/module/bug/view/browse.html.php
index 01e27a1313..d96aed6646 100644
--- a/module/bug/view/browse.html.php
+++ b/module/bug/view/browse.html.php
@@ -237,6 +237,23 @@ $currentBrowseType = isset($lang->bug->mySelects[$browseType]) && in_array($brow
$misc = common::hasPriv('bug', 'batchActivate') ? "onclick=\"setFormAction('$actionLink')\"" : $class;
if($misc) echo "
" . html::a('javascript:;', $lang->bug->activate, '', $misc) . "";
+ if(common::hasPriv('bug', 'batchChangeBranch') and $this->session->currentProductType != 'normal')
+ {
+ $withSearch = count($branches) > 8;
+ echo "';
+ }
+
if(common::hasPriv('bug', 'batchChangeModule'))
{
$withSearch = count($modules) > 8;
diff --git a/module/testcase/control.php b/module/testcase/control.php
index b4d14ed56b..f0b26653a1 100644
--- a/module/testcase/control.php
+++ b/module/testcase/control.php
@@ -842,6 +842,33 @@ class testcase extends control
die(js::locate($this->session->caseList));
}
+ /**
+ * Batch change branch.
+ *
+ * @param int $branchID
+ * @access public
+ * @return void
+ */
+ public function batchChangeBranch($branchID)
+ {
+ if($this->post->caseIDList)
+ {
+ $caseIDList = $this->post->caseIDList;
+ $caseIDList = array_unique($caseIDList);
+ unset($_POST['caseIDList']);
+ $allChanges = $this->testcase->batchChangeBranch($caseIDList, $branchID);
+ if(dao::isError()) die(js::error(dao::getError()));
+ foreach($allChanges as $caseID => $changes)
+ {
+ $this->loadModel('action');
+ $actionID = $this->action->create('case', $caseID, 'Edited');
+ $this->action->logHistory($actionID, $changes);
+ }
+ }
+
+ die(js::locate($this->session->caseList, 'parent'));
+ }
+
/**
* Batch change the module of case.
*
diff --git a/module/testcase/model.php b/module/testcase/model.php
index 276b169a29..6bcd2e5f27 100644
--- a/module/testcase/model.php
+++ b/module/testcase/model.php
@@ -817,6 +817,36 @@ class testcaseModel extends model
return $allChanges;
}
+ /**
+ * Batch change branch.
+ *
+ * @param array $caseIDList
+ * @param int $branchID
+ * @access public
+ * @return array
+ */
+ public function batchChangeBranch($caseIDList, $branchID)
+ {
+ $now = helper::now();
+ $allChanges = array();
+ $oldCases = $this->getByList($caseIDList);
+ foreach($caseIDList as $caseID)
+ {
+ $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);
+ }
+
+ return $allChanges;
+ }
+
/**
* Batch change the module of case.
*
diff --git a/module/testcase/view/browse.html.php b/module/testcase/view/browse.html.php
index 7a2d74378d..5568136d72 100644
--- a/module/testcase/view/browse.html.php
+++ b/module/testcase/view/browse.html.php
@@ -128,6 +128,23 @@ js::set('branch', $branch);
$misc = common::hasPriv('testtask', 'batchRun') ? "onclick=\"setFormAction('$actionLink')\"" : $class;
echo "" . html::a('#', $lang->testtask->runCase, '', $misc) . "";
+ if(common::hasPriv('testcase', 'batchChangeBranch') and $this->session->currentProductType != 'normal')
+ {
+ $withSearch = count($branches) > 8;
+ echo "';
+ }
+
if(common::hasPriv('testcase', 'batchChangeModule'))
{
$withSearch = count($modules) > 8;