* Refactor mergeBranch method.
This commit is contained in:
@@ -7,3 +7,9 @@ $config->branch->form->batchedit['branchID'] = array('type' => 'int', 'requir
|
||||
$config->branch->form->batchedit['name'] = array('type' => 'string', 'required' => true);
|
||||
$config->branch->form->batchedit['desc'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->branch->form->batchedit['status'] = array('type' => 'string', 'required' => false, 'default' => 'active');
|
||||
|
||||
$config->branch->form->mergebranch['createBranch'] = array('type' => 'int', 'required' => false, 'default' => 0);
|
||||
$config->branch->form->mergebranch['targetBranch'] = array('type' => 'int', 'required' => false, 'default' => 0);
|
||||
$config->branch->form->mergebranch['mergedBranchIDList'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->branch->form->mergebranch['name'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->branch->form->mergebranch['desc'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
|
||||
@@ -320,13 +320,14 @@ class branch extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 将多个分支合并到一个分支。
|
||||
* Merge multiple branches into one branch.
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function mergeBranch($productID)
|
||||
public function mergeBranch(int $productID)
|
||||
{
|
||||
if($this->post->mergedBranchIDList)
|
||||
{
|
||||
@@ -338,10 +339,11 @@ class branch extends control
|
||||
return $branch != 0 and $branch != $mergeToBranch;
|
||||
});
|
||||
|
||||
$mergedBranchIDList = implode(',', $mergedBranches);
|
||||
$mergedBranches = $this->dao->select('id,name')->from(TABLE_BRANCH)->where('id')->in($mergedBranchIDList)->fetchPairs();
|
||||
$mergedBranches = $this->branch->getPairsByIdList($mergedBranches);
|
||||
|
||||
$targetBranch = $this->branch->mergeBranch($productID, $mergedBranchIDList);
|
||||
$postData = form::data()->get();
|
||||
$branchIdList = implode(',', array_keys($mergedBranches));
|
||||
$targetBranch = $this->branch->mergeBranch($productID, $branchIdList, $postData);
|
||||
if(dao::isError()) return $this->sendError(dao::getError());
|
||||
|
||||
$this->loadModel('action')->create('branch', $targetBranch, 'MergedBranch', '', implode(',', $mergedBranches));
|
||||
|
||||
+23
-68
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The model file of branch module of ZenTaoCMS.
|
||||
*
|
||||
@@ -162,6 +163,19 @@ class branchModel extends model
|
||||
return $branches;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分支ID列表获取分支名称列表。
|
||||
* Get the list of branch name from the branch ID list.
|
||||
*
|
||||
* @param array $branchIdList
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getPairsByIdList(array $branchIdList): array
|
||||
{
|
||||
return $this->dao->select('id,name')->from(TABLE_BRANCH)->where('id')->in($branchIdList)->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all pairs.
|
||||
*
|
||||
@@ -726,92 +740,33 @@ class branchModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 将多个分支合并到一个分支。
|
||||
* Merge multiple branches into one branch.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param string $mergedBranches
|
||||
* @param int $productID
|
||||
* @param string $mergedBranches
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return int|bool
|
||||
*/
|
||||
public function mergeBranch($productID, $mergedBranches)
|
||||
public function mergeBranch(int $productID, string $mergedBranches, object $data): int|bool
|
||||
{
|
||||
$data = fixer::input('post')->get();
|
||||
if(empty($data->targetBranch) && empty($data->name))
|
||||
if($data->createBranch && empty($data->name))
|
||||
{
|
||||
$this->changeBranchLanguage($productID);
|
||||
if($this->post->createBranch)
|
||||
{
|
||||
dao::$errors['name'] = sprintf($this->lang->error->notempty, $this->lang->branch->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
dao::$errors['targetBranch'] = sprintf($this->lang->error->notempty, $this->lang->branch->mergeBranch);
|
||||
}
|
||||
dao::$errors['name'] = sprintf($this->lang->error->notempty, $this->lang->branch->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get the target branch. */
|
||||
$targetBranch = $data->createBranch ? $this->create($productID, true) : $data->targetBranch;
|
||||
|
||||
if($data->createBranch) $this->loadModel('action')->create('branch', $targetBranch, 'Opened');
|
||||
|
||||
/* Branch. */
|
||||
$this->dao->delete()->from(TABLE_BRANCH)->where('id')->in($mergedBranches)->exec();
|
||||
|
||||
/* Release. */
|
||||
$this->dao->update(TABLE_RELEASE)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Build. */
|
||||
$this->dao->update(TABLE_BUILD)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Plan. */
|
||||
$this->dao->update(TABLE_PRODUCTPLAN)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Module. */
|
||||
$this->dao->update(TABLE_MODULE)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Story. */
|
||||
$this->dao->update(TABLE_STORY)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
$this->dao->update(TABLE_PROJECTSTORY)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Bug. */
|
||||
$this->dao->update(TABLE_BUG)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Case. */
|
||||
$this->dao->update(TABLE_CASE)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Linked project or execution. */
|
||||
$linkedProject = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)
|
||||
->where('branch')->in($mergedBranches . ",$targetBranch")
|
||||
->andWhere('product')->eq($productID)
|
||||
->fetchGroup('project');
|
||||
|
||||
$this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('branch')->in($mergedBranches . ",$targetBranch")
|
||||
->andWhere('product')->eq($productID)
|
||||
->exec();
|
||||
foreach($linkedProject as $projectID => $projectProducts)
|
||||
{
|
||||
$plan = 0;
|
||||
if(!$data->createBranch)
|
||||
{
|
||||
/* Get the linked plan of the target branch. */
|
||||
foreach($projectProducts as $projectProduct)
|
||||
{
|
||||
if($projectProduct->branch == $targetBranch)
|
||||
{
|
||||
$plan = $projectProduct->plan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$projectProduct = new stdClass();
|
||||
$projectProduct->project = $projectID;
|
||||
$projectProduct->product = $productID;
|
||||
$projectProduct->branch = $targetBranch;
|
||||
$projectProduct->plan = $plan;
|
||||
$this->dao->insert(TABLE_PROJECTPRODUCT)->data($projectProduct)->autoCheck()->exec();
|
||||
}
|
||||
$this->branchTao->afterMerge($productID, $targetBranch, $mergedBranches, $data);
|
||||
if(dao::isError()) return false;
|
||||
|
||||
return $targetBranch;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The tao file of branch module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Shujie Tian <tianshujie@easycorp.ltd>
|
||||
* @package branch
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class branchTao extends branchModel
|
||||
{
|
||||
/**
|
||||
* 合并分支后的其他数据处理。
|
||||
* other data process after merge branch.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param int $targetBranch
|
||||
* @param string $mergedBranches
|
||||
* @param object $data
|
||||
* @access protected
|
||||
* @return bool
|
||||
*/
|
||||
protected function afterMerge(int $productID, int $targetBranch, string $mergedBranches, object $data): bool
|
||||
{
|
||||
$this->dao->update(TABLE_RELEASE)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec(); // Update release branch.
|
||||
$this->dao->update(TABLE_BUILD)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec(); // Update build branch.
|
||||
$this->dao->update(TABLE_PRODUCTPLAN)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec(); // Update plan branch.
|
||||
$this->dao->update(TABLE_MODULE)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec(); // Update module branch.
|
||||
$this->dao->update(TABLE_BUG)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec(); // Update bug branch.
|
||||
$this->dao->update(TABLE_CASE)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec(); // Update case branch.
|
||||
|
||||
/* Update story branch. */
|
||||
$this->dao->update(TABLE_STORY)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
$this->dao->update(TABLE_PROJECTSTORY)->set('branch')->eq($targetBranch)->where('branch')->in($mergedBranches)->exec();
|
||||
|
||||
/* Linked project or execution. */
|
||||
$linkedProject = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)
|
||||
->where('branch')->in($mergedBranches . ",$targetBranch")
|
||||
->andWhere('product')->eq($productID)
|
||||
->fetchGroup('project');
|
||||
|
||||
$this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('branch')->in($mergedBranches . ",$targetBranch")
|
||||
->andWhere('product')->eq($productID)
|
||||
->exec();
|
||||
foreach($linkedProject as $projectID => $projectProducts)
|
||||
{
|
||||
$plan = 0;
|
||||
if($data->createBranch) continue;
|
||||
|
||||
/* Get the linked plan of the target branch. */
|
||||
foreach($projectProducts as $projectProduct)
|
||||
{
|
||||
if($projectProduct->branch == $targetBranch)
|
||||
{
|
||||
$plan = $projectProduct->plan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$projectProduct = new stdClass();
|
||||
$projectProduct->project = $projectID;
|
||||
$projectProduct->product = $productID;
|
||||
$projectProduct->branch = $targetBranch;
|
||||
$projectProduct->plan = $plan;
|
||||
$this->dao->insert(TABLE_PROJECTPRODUCT)->data($projectProduct)->autoCheck()->exec();
|
||||
}
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user