This commit is contained in:
Catouse
2015-05-19 17:23:48 +08:00
4 changed files with 55 additions and 30 deletions

View File

@@ -35,6 +35,7 @@ $lang->tree->ajaxGetOptionMenu = 'API: Get select menu';
$lang->tree->ajaxGetSonModules = 'API: Get son modules';
$lang->tree->confirmDelete = 'Are you sure to delete this module and its children?';
$lang->tree->confirmRoot = 'Modify the module products, modified the products belong to the needs of the module, bug, use case, and project and product relationship. This is dangerous, please be careful. To confirm the change?';
$lang->tree->successSave = 'Successfully saved';
$lang->tree->successFixed = 'Successfully fixed.';

View File

@@ -35,6 +35,7 @@ $lang->tree->ajaxGetOptionMenu = '接口:获取下拉列表';
$lang->tree->ajaxGetSonModules = '接口:获得子菜单列表';
$lang->tree->confirmDelete = '该模块及其子模块都会被删除,您确定删除吗?';
$lang->tree->confirmRoot = '模块的所属产品修改会关联修改该模块下的需求、Bug、用例的所属产品以及项目和产品的关联关系。该操作比较危险请谨慎操作。是否确认修改';
$lang->tree->successSave = '成功保存';
$lang->tree->successFixed = '成功修正数据!';

View File

@@ -1037,44 +1037,54 @@ class treeModel extends model
* Change root.
*
* @param int $moduleID
* @param int $before
* @param int $after
* @param int $oldRoot
* @param int $newRoot
* @param string $type
* @access public
* @return void
*/
public function changeRoot($moduleID, $before, $after, $type)
public function changeRoot($moduleID, $oldRoot, $newRoot, $type)
{
$childIds = $this->dao->select('id')->from(TABLE_MODULE)->where('path')->like("%,$moduleID,%")->fetchPairs('id', 'id');
$this->dao->update(TABLE_STORY)->set('product')->eq($after)->where('module')->in($childIds)->exec();
$this->dao->update(TABLE_BUG)->set('product')->eq($after)->where('module')->in($childIds)->exec();
$this->dao->update(TABLE_CASE)->set('product')->eq($after)->where('module')->in($childIds)->exec();
/* Get all children id list. */
$childIdList = $this->dao->select('id')->from(TABLE_MODULE)->where('path')->like("%,$moduleID,%")->fetchPairs('id', 'id');
if($type == 'story')
/* Update product field for stories, bugs, cases under this module. */
$this->dao->update(TABLE_STORY)->set('product')->eq($newRoot)->where('module')->in($childIdList)->exec();
$this->dao->update(TABLE_BUG)->set('product')->eq($newRoot)->where('module')->in($childIdList)->exec();
$this->dao->update(TABLE_CASE)->set('product')->eq($newRoot)->where('module')->in($childIdList)->exec();
if($type != 'story') return;
/* If the type if story, check it's releated projects. */
$projectStories = $this->dao->select('DISTINCT t1.id,t1.version,t2.project')
->from(TABLE_STORY)->alias('t1')
->leftJoin(TABLE_PROJECTSTORY)->alias('t2')->on('t1.id=t2.story')
->where('t1.module')->in($childIdList)
->andWhere('t2.product')->eq($oldRoot)
->fetchAll('id');
$projects = array();
foreach($projectStories as $story)
{
$linkedStories = $this->dao->select('DISTINCT t1.id,t1.version,t2.project')->from(TABLE_STORY)->alias('t1')
->leftJoin(TABLE_PROJECTSTORY)->alias('t2')->on('t1.id=t2.story')
->where('t1.module')->in($childIds)
->andWhere('t2.product')->eq($before)
->fetchAll('id');
$projects = array();
foreach($linkedStories as $story)
{
$this->dao->update(TABLE_PROJECTSTORY)->set('product')->eq($after)->where('project')->eq($story->project)->andWhere('story')->eq($story->id)->andWhere('version')->eq($story->version)->exec();
$projects[$story->project] = $story->project;
}
$this->dao->update(TABLE_PROJECTSTORY)
->set('product')->eq($newRoot)
->where('project')->eq($story->project)
->andWhere('story')->eq($story->id)
->andWhere('version')->eq($story->version)
->exec();
$projects[$story->project] = $story->project;
}
if($projects)
if($projects)
{
$projectProduct = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->in($projects)->fetchGroup('project', 'product');
$linkedProduct = $this->dao->select('DISTINCT project,product')->from(TABLE_PROJECTSTORY)->where('project')->in($projects)->fetchGroup('project', 'product');
foreach($projects as $project)
{
$projectProduct = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->in($projects)->fetchGroup('project', 'product');
$linkedProduct = $this->dao->select('DISTINCT project,product')->from(TABLE_PROJECTSTORY)->where('project')->in($projects)->fetchGroup('project', 'product');
foreach($projects as $project)
if(!isset($projectProduct[$project]) or !in_array($newRoot, array_keys($projectProduct[$project]))) $this->dao->insert(TABLE_PROJECTPRODUCT)->set('project')->eq($project)->set('product')->eq($newRoot)->exec();
if(isset($linkedProduct[$project]) and !in_array($oldRoot, array_keys($linkedProduct[$project])))
{
if(!isset($projectProduct[$project]) or !in_array($after, array_keys($projectProduct[$project]))) $this->dao->insert(TABLE_PROJECTPRODUCT)->set('project')->eq($project)->set('product')->eq($after)->exec();
if(isset($linkedProduct[$project]) and !in_array($before, array_keys($linkedProduct[$project])))
{
$this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('project')->eq($project)->andWhere('product')->eq($before)->exec();
$this->dao->update(TABLE_BUILD)->set('product')->eq($after)->where('product')->eq($before)->andWhere('project')->eq($project)->exec();
}
$this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('project')->eq($project)->andWhere('product')->eq($oldRoot)->exec();
$this->dao->update(TABLE_BUILD)->set('product')->eq($newRoot)->where('product')->eq($oldRoot)->andWhere('project')->eq($project)->exec();
}
}
}

View File

@@ -28,7 +28,7 @@ $jsRoot = $webRoot . "js/";
<?php if($showProduct):?>
<tr>
<th class='w-80px'><?php echo $lang->tree->product;?></th>
<td><?php echo html::select('root', $products, $module->root, "class='form-control chosen' onchange='getProductModules(this.value)'");?></td>
<td><?php echo html::select('root', $products, $module->root, "class='form-control chosen'");?></td>
</tr>
<?php endif;?>
<?php $hidden = ($type != 'story' and $module->type == 'story');?>
@@ -69,4 +69,17 @@ function getProductModules(productID)
$('#parent').trigger('chosen:updated')
}, 'json');
}
$(function()
{
$('#root').change(function()
{
if($(this).val() == currentRoot) return true;
if(!confirm('<?php echo $lang->tree->confirmRoot?>'))
{
$('#root').val(currentRoot);
$('#root').trigger('chosen:updated');
}
getProductModules($(this).val());
})
})
</script>