diff --git a/module/execution/model.php b/module/execution/model.php index de246e497a..a4628a7293 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -2821,41 +2821,76 @@ class executionModel extends model } /** + * 修改执行的所属项目。 * Change execution project. * - * @param int $newProject - * @param int $oldProject + * @param int $newProjectID + * @param int $oldProjectID * @param int $executionID - * @param string $syncStories yes|no + * @param string $syncStories yes|no * @access public * @return void */ - public function changeProject($newProject, $oldProject, $executionID, $syncStories = 'no') + public function changeProject(int $newProjectID, int $oldProjectID, int $executionID, string $syncStories = 'no'): void { - if($newProject == $oldProject) return; + if($newProjectID == $oldProjectID) return; - $this->dao->update(TABLE_EXECUTION)->set('parent')->eq($newProject)->set('path')->eq(",$newProject,$executionID,")->where('id')->eq($executionID)->exec(); + $this->dao->update(TABLE_EXECUTION)->set('parent')->eq($newProjectID)->set('path')->eq(",$newProjectID,$executionID,")->where('id')->eq($executionID)->exec(); - $this->dao->update(TABLE_BUILD)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); - $this->dao->update(TABLE_BUG)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); - $this->dao->update(TABLE_CASE)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); - $this->dao->update(TABLE_DOC)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); - $this->dao->update(TABLE_DOCLIB)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); - $this->dao->update(TABLE_TASK)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); - $this->dao->update(TABLE_TESTREPORT)->set('project')->eq($newProject)->where('project')->eq($oldProject)->andWhere('execution')->eq($executionID)->exec(); + /* Update the project to which the relevant data belongs. */ + $this->dao->update(TABLE_BUILD)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + $this->dao->update(TABLE_BUG)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + $this->dao->update(TABLE_CASE)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + $this->dao->update(TABLE_DOC)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + $this->dao->update(TABLE_DOCLIB)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + $this->dao->update(TABLE_TASK)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + $this->dao->update(TABLE_TESTREPORT)->set('project')->eq($newProjectID)->where('project')->eq($oldProjectID)->andWhere('execution')->eq($executionID)->exec(); + /* Update the team members and whitelist of the project. */ + $addedAccounts = $this->updateProjectUsers($executionID, $newProjectID); + if($addedAccounts) $this->loadModel('user')->updateUserView($newProjectID, 'project', $addedAccounts); + + /* Sync stories to new project. */ + if($syncStories == 'yes') + { + $this->loadModel('action'); + $projectLinkedStories = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($newProjectID)->fetchPairs('story', 'story'); + $executionLinkedStories = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); + foreach($executionLinkedStories as $linkedStory) + { + if(isset($projectLinkedStories[$linkedStory->story])) continue; + + $linkedStory->project = $newProjectID; + $this->dao->insert(TABLE_PROJECTSTORY)->data($linkedStory)->exec(); + $this->action->create('story', $linkedStory->story, 'linked2project', '', $newProjectID); + } + } + } + + /** + * 更新项目的团队成员和白名单。 + * Update the team members and whitelist of the project. + * + * @param int $executionID + * @param int $newProjectID + * @access public + * @return array + */ + public function updateProjectUsers(int $executionID, int $newProjectID): array + { $executionTeam = $this->loadModel('user')->getTeamMemberPairs($executionID, 'execution'); - $projectTeam = $this->user->getTeamMemberPairs($newProject, 'project'); + $projectTeam = $this->user->getTeamMemberPairs($newProjectID, 'project'); $addedAccounts = array(); + $today = helper::today(); foreach($executionTeam as $account => $realname) { if(isset($projectTeam[$account])) continue; $member = new stdclass(); - $member->root = (int)$newProject; + $member->root = $newProjectID; $member->type = 'project'; $member->account = $account; - $member->join = helper::today(); + $member->join = $today; $member->days = 0; $member->hours = $this->config->execution->defaultWorkhours; $this->dao->replace(TABLE_TEAM)->data($member)->exec(); @@ -2864,7 +2899,7 @@ class executionModel extends model } $executionWhitelist = $this->loadModel('personnel')->getWhitelistAccount($executionID, 'sprint'); - $projectWhitelist = $this->personnel->getWhitelistAccount($newProject, 'project'); + $projectWhitelist = $this->personnel->getWhitelistAccount($newProjectID, 'project'); foreach($executionWhitelist as $account) { if(isset($projectWhitelist[$account])) continue; @@ -2872,7 +2907,7 @@ class executionModel extends model $whitelist = new stdclass(); $whitelist->account = $account; $whitelist->objectType = 'project'; - $whitelist->objectID = (int)$newProject; + $whitelist->objectID = $newProjectID; $whitelist->type = 'whitelist'; $whitelist->source = 'sync'; $this->dao->replace(TABLE_ACL)->data($whitelist)->exec(); @@ -2880,23 +2915,7 @@ class executionModel extends model $addedAccounts[$account] = $account; } - /* Sync stories to new project. */ - if($syncStories == 'yes') - { - $this->loadModel('action'); - $projectLinkedStories = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($newProject)->fetchPairs('story', 'story'); - $executionLinkedStories = $this->dao->select('*')->from(TABLE_PROJECTSTORY)->where('project')->eq($executionID)->fetchAll(); - foreach($executionLinkedStories as $linkedStory) - { - if(isset($projectLinkedStories[$linkedStory->story])) continue; - - $linkedStory->project = $newProject; - $this->dao->insert(TABLE_PROJECTSTORY)->data($linkedStory)->exec(); - $this->action->create('story', $linkedStory->story, 'linked2project', '', $newProject); - } - } - - if($addedAccounts) $this->loadModel('user')->updateUserView($newProject, 'project', $addedAccounts); + return $addedAccounts; } /** diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index 125f4ae873..1eb4364bc7 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -1288,31 +1288,22 @@ class executionTest } /** - * function changeProject test by execution + * 修改执行的所属项目。 + * Change execution project. * - * @param string $newProject - * @param string $oldProject - * @param string $executionID - * @param array $syncStories + * @param int $newProjectID + * @param int $oldProjectID + * @param int $executionID + * @param string $syncStories yes|no * @access public - * @return array + * @return array|object */ - public function changeProjectTest($newProject, $oldProject, $executionID, $syncStories = 'no') + public function changeProjectTest(int $newProjectID, int $oldProjectID, int $executionID, string $syncStories = 'no'): array|object { - global $tester; + $this->executionModel->changeProject($newProjectID, $oldProjectID, $executionID, $syncStories); - $this->executionModel->changeProject($newProject, $oldProject, $executionID, $syncStories); - - if(dao::isError()) - { - $error = dao::getError(); - return $error; - } - else - { - $newExecution = $tester->dbh->query("select parent,path from zt_project where id = $executionID")->fetchAll(); - return $newExecution; - } + if(dao::isError()) return dao::getError(); + return $this->executionModel->dao->select('parent,path')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch(); } /** diff --git a/module/execution/test/model/changeproject.php b/module/execution/test/model/changeproject.php index dfc6b1f530..c35a135bba 100755 --- a/module/execution/test/model/changeproject.php +++ b/module/execution/test/model/changeproject.php @@ -11,6 +11,7 @@ $execution->name->range('项目集1,项目1,项目2,项目3,项目4,项目5,项 $execution->type->range('program,project{6},sprint,stage,kanban'); $execution->model->range('[],scrum{2},waterfall{2},kanban{2},[]{3}'); $execution->parent->range('0,1{6},2,3,4'); +$execution->path->range('`,1,`,`,1,2,`,`,1,3,`,`,1,4,`,`,1,5,`,`,1,6,`,`1,7,`,`,1,2,8,`,`,1,3,9,`,`,1,4,10`'); $execution->status->range('doing'); $execution->openedBy->range('admin,user1'); $execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD'); @@ -20,12 +21,8 @@ $execution->gen(10); /** title=测试executionModel->changeProjectTest(); +timeout=0 cid=1 -pid=1 - -测试修改敏捷执行关联项目 >> 5 -测试修改瀑布执行关联项目 >> ,6,9, -测试修改看板执行关联项目 >> 7 */ @@ -34,6 +31,9 @@ $oldProjectIDlist = array(2, 3, 4); $newProjectIDlist = array(5, 6, 7); $executionTester = new executionTest(); -r($executionTester->changeProjectTest($newProjectIDlist[0], $oldProjectIDlist[0], $executionIDList[0])) && p('0:parent') && e('5'); // 测试修改敏捷执行关联项目 -r($executionTester->changeProjectTest($newProjectIDlist[1], $oldProjectIDlist[1], $executionIDList[1])) && p('0:path') && e(',6,9,'); // 测试修改瀑布执行关联项目 -r($executionTester->changeProjectTest($newProjectIDlist[2], $oldProjectIDlist[2], $executionIDList[2])) && p('0:parent') && e('7'); // 测试修改看板执行关联项目 +r($executionTester->changeProjectTest($oldProjectIDlist[0], $oldProjectIDlist[0], $executionIDList[0])) && p('parent') && e('2'); // 测试不修改敏捷执行关联项目 +r($executionTester->changeProjectTest($oldProjectIDlist[1], $oldProjectIDlist[1], $executionIDList[1])) && p('path', ';') && e(',1,3,9,'); // 测试不修改瀑布执行关联项目 +r($executionTester->changeProjectTest($oldProjectIDlist[2], $oldProjectIDlist[2], $executionIDList[2])) && p('parent') && e('4'); // 测试不修改看板执行关联项目 +r($executionTester->changeProjectTest($newProjectIDlist[0], $oldProjectIDlist[0], $executionIDList[0])) && p('parent') && e('5'); // 测试修改敏捷执行关联项目 +r($executionTester->changeProjectTest($newProjectIDlist[1], $oldProjectIDlist[1], $executionIDList[1])) && p('path', ';') && e(',6,9,'); // 测试修改瀑布执行关联项目 +r($executionTester->changeProjectTest($newProjectIDlist[2], $oldProjectIDlist[2], $executionIDList[2])) && p('parent') && e('7'); // 测试修改看板执行关联项目 diff --git a/module/execution/test/model/updateprojectusers.php b/module/execution/test/model/updateprojectusers.php new file mode 100644 index 0000000000..da9dda53e4 --- /dev/null +++ b/module/execution/test/model/updateprojectusers.php @@ -0,0 +1,29 @@ +#!/usr/bin/env php +gen(300); +su('admin'); + +zdTable('project')->config('execution')->gen(30); +zdTable('team')->config('team')->gen(30); + +/** + +title=测试executionModel->updateProjectUsers(); +timeout=0 +cid=1 + +*/ + +$newProjectIdList = array(11, 60, 100); +$executionIdList = array(101, 106, 124); + +global $tester; +$tester->loadModel('execution'); +r($tester->execution->updateProjectUsers($executionIdList[1], $newProjectIdList[0])) && p('user9') && e('user9'); // 测试阶段更新到敏捷项目下 +r($tester->execution->updateProjectUsers($executionIdList[2], $newProjectIdList[0])) && p('dev7') && e('dev7'); // 测试看板更新到敏捷项目下 +r($tester->execution->updateProjectUsers($executionIdList[0], $newProjectIdList[1])) && p('user4') && e('user4'); // 测试迭代更新到瀑布项目下 +r($tester->execution->updateProjectUsers($executionIdList[2], $newProjectIdList[1])) && p('dev7') && e('dev7'); // 测试看板更新到瀑布项目下 +r($tester->execution->updateProjectUsers($executionIdList[0], $newProjectIdList[2])) && p('user4') && e('user4'); // 测试迭代更新到看板项目下 +r($tester->execution->updateProjectUsers($executionIdList[1], $newProjectIdList[2])) && p('user9') && e('user9'); // 测试阶段更新到看板项目下