diff --git a/module/tree/lang/en.php b/module/tree/lang/en.php index 9339ff32f1..27eadc5f9c 100644 --- a/module/tree/lang/en.php +++ b/module/tree/lang/en.php @@ -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.'; diff --git a/module/tree/lang/zh-cn.php b/module/tree/lang/zh-cn.php index 0859f6cc10..bafc9fcbcc 100644 --- a/module/tree/lang/zh-cn.php +++ b/module/tree/lang/zh-cn.php @@ -35,6 +35,7 @@ $lang->tree->ajaxGetOptionMenu = '接口:获取下拉列表'; $lang->tree->ajaxGetSonModules = '接口:获得子菜单列表'; $lang->tree->confirmDelete = '该模块及其子模块都会被删除,您确定删除吗?'; +$lang->tree->confirmRoot = '模块的所属产品修改,会关联修改该模块下的需求、Bug、用例的所属产品,以及项目和产品的关联关系。该操作比较危险,请谨慎操作。是否确认修改?'; $lang->tree->successSave = '成功保存'; $lang->tree->successFixed = '成功修正数据!'; diff --git a/module/tree/model.php b/module/tree/model.php index a84170a7be..e2d8140476 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -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(); } } } diff --git a/module/tree/view/edit.html.php b/module/tree/view/edit.html.php index 4c3373b8ce..a9e6c0ef4e 100644 --- a/module/tree/view/edit.html.php +++ b/module/tree/view/edit.html.php @@ -28,7 +28,7 @@ $jsRoot = $webRoot . "js/"; tree->product;?> - root, "class='form-control chosen' onchange='getProductModules(this.value)'");?> + root, "class='form-control chosen'");?> 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('tree->confirmRoot?>')) + { + $('#root').val(currentRoot); + $('#root').trigger('chosen:updated'); + } + getProductModules($(this).val()); + }) +})