From 1dfd85760184ffa90359f1b1dff49dc8d42fc4b9 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 30 Apr 2019 10:53:38 +0800 Subject: [PATCH] * finish task #5435. --- db/update11.4.1.sql | 2 + db/zentao.sql | 1 + module/product/view/browse.html.php | 1 + module/story/model.php | 69 +++++++++++++++++++++++++---- module/upgrade/model.php | 21 +++++++++ 5 files changed, 85 insertions(+), 9 deletions(-) diff --git a/db/update11.4.1.sql b/db/update11.4.1.sql index 20a5f2fce6..5f456e6cf6 100644 --- a/db/update11.4.1.sql +++ b/db/update11.4.1.sql @@ -1,3 +1,5 @@ ALTER TABLE `zt_entry` ADD `calledTime` int(10) unsigned NOT NULL DEFAULT '0' AFTER `createdDate`; ALTER TABLE `zt_story` CHANGE `toBug` `toBug` mediumint(8) unsigned NOT NULL AFTER `closedReason`; UPDATE `zt_story` SET `stage` = 'closed' WHERE `status` = 'closed'; +ALTER TABLE `zt_story` ADD `stagedBy` char(30) COLLATE 'utf8_general_ci' NOT NULL AFTER `stage`; +ALTER TABLE `zt_storystage` ADD `stagedBy` char(30) COLLATE 'utf8_general_ci' NOT NULL; diff --git a/db/zentao.sql b/db/zentao.sql index ce45c19f6e..848a4e137d 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -604,6 +604,7 @@ CREATE TABLE IF NOT EXISTS `zt_storystage` ( `story` mediumint(8) unsigned NOT NULL, `branch` mediumint(8) unsigned NOT NULL, `stage` varchar(50) NOT NULL, + UNIQUE KEY `story_branch` (`story`,`branch`), KEY `story` (`story`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_suitecase`; diff --git a/module/product/view/browse.html.php b/module/product/view/browse.html.php index 97ab02ecd1..2eff935556 100644 --- a/module/product/view/browse.html.php +++ b/module/product/view/browse.html.php @@ -273,6 +273,7 @@ foreach($lang->story->stageList as $key => $stage) { if(empty($key)) continue; + if(strpos('tested|verified|released|closed', $key) === false) continue; $actionLink = $this->createLink('story', 'batchChangeStage', "stage=$key"); echo "
  • " . html::a('#', $stage, '', "onclick=\"setFormAction('$actionLink','hiddenwin')\"") . "
  • "; } diff --git a/module/story/model.php b/module/story/model.php index a93a6c087b..579e52dceb 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -515,6 +515,7 @@ class storyModel extends model if(empty($_POST['branch'])) $story->branch = 0; if(!empty($_POST['stages'])) { + $oldStages = $this->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->fetchAll('branch'); $this->dao->delete()->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->exec(); $stageList = join(',', array_keys($this->lang->story->stageList)); @@ -522,7 +523,17 @@ class storyModel extends model $minStage = ''; foreach($this->post->stages as $branch => $stage) { - $this->dao->insert(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq($stage)->exec(); + $newStage = new stdclass(); + $newStage->story = $storyID; + $newStage->branch = $branch; + $newStage->stage = $stage; + if(isset($oldStages[$branch])) + { + $oldStage = $oldStages[$branch]; + $newStage->stagedBy = $oldStage->stagedBy; + if($stage != $oldStage->stage) $newStage->stagedBy = (strpos('tested|verified|released|closed', $stage) !== false) ? $this->app->user->account : ''; + } + $this->dao->insert(TABLE_STORYSTAGE)->data($newStage)->exec(); if(strpos($stageList, $stage) !== false and strpos($stageList, $stage) < $minStagePos) { $minStage = $stage; @@ -531,6 +542,7 @@ class storyModel extends model } $story->stage = $minStage; } + if($oldStory->stage != $story->stage) $story->stagedBy = (strpos('tested|verified|released|closed', $story->stage) !== false) ? $this->app->user->account : ''; $this->dao->update(TABLE_STORY) ->data($story) @@ -628,6 +640,7 @@ class storyModel extends model $story->duplicateStory = isset($data->duplicateStories[$storyID]) ? $data->duplicateStories[$storyID] : $oldStory->duplicateStory; $story->childStories = isset($data->childStoriesIDList[$storyID]) ? $data->childStoriesIDList[$storyID] : $oldStory->childStories; $story->version = $story->title == $oldStory->title ? $oldStory->version : $oldStory->version + 1; + if($story->stage != $oldStory->stage) $story->stagedBy = (strpos('tested|verified|released|closed', $story->stage) !== false) ? $this->app->user->account : ''; if($story->title != $oldStory->title) $story->status = 'changed'; if($story->plan !== false and $story->plan == '') $story->plan = 0; @@ -1043,6 +1056,7 @@ class storyModel extends model { $now = helper::now(); $allChanges = array(); + $account = $this->app->user->account; $oldStories = $this->getByList($storyIDList); $ignoreStories = ''; foreach($storyIDList as $storyID) @@ -1055,13 +1069,13 @@ class storyModel extends model } $story = new stdclass(); - $story->lastEditedBy = $this->app->user->account; + $story->lastEditedBy = $account; $story->lastEditedDate = $now; $story->stage = $stage; + $story->stagedBy = $account; $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->where('id')->eq((int)$storyID)->exec(); - $this->dao->update(TABLE_STORYSTAGE)->set('stage')->eq($stage)->where('story')->eq((int)$storyID)->exec(); - $this->setStage($storyID); + $this->dao->update(TABLE_STORYSTAGE)->set('stage')->eq($stage)->set('stagedBy')->eq($account)->where('story')->eq((int)$storyID)->exec(); if(!dao::isError()) $allChanges[$storyID] = common::createChanges($oldStory, $story); } if($ignoreStories) echo js::alert(sprintf($this->lang->story->ignoreChangeStage, $ignoreStories)); @@ -1164,8 +1178,12 @@ class storyModel extends model $storyID = (int)$storyID; /* Get projects which status is doing. */ + $oldStages = $this->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->fetchAll('branch'); $this->dao->delete()->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->exec(); - $story = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch(); + + $story = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch(); + if(!empty($story->stagedBy)) return false; + $product = $this->dao->findById($story->product)->from(TABLE_PRODUCT)->fetch(); $projects = $this->dao->select('t1.project,t3.branch')->from(TABLE_PROJECTSTORY)->alias('t1') ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id') @@ -1187,7 +1205,19 @@ class storyModel extends model { $this->dao->update(TABLE_STORY)->set('stage')->eq('wait')->where('id')->eq($storyID)->andWhere('plan')->eq('')->exec(); - foreach($stages as $branch => $stage) $this->dao->insert(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq($stage)->exec(); + foreach($stages as $branch => $stage) + { + if(isset($oldStages[$branch])) + { + $oldStage = $oldStages[$branch]; + if(!empty($oldStage->stagedBy)) + { + $this->dao->replace(TABLE_STORYSTAGE)->data($oldStage)->exec(); + continue; + } + } + $this->dao->replace(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq($stage)->exec(); + } $this->dao->update(TABLE_STORY)->set('stage')->eq('planned')->where('id')->eq($storyID)->andWhere("(plan != '' AND plan != '0')")->exec(); } @@ -1209,7 +1239,19 @@ class storyModel extends model /* No tasks, then the stage is projected. */ if(!$tasks and $projects) { - foreach($stages as $branch => $stage) $this->dao->insert(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq('projected')->exec(); + foreach($stages as $branch => $stage) + { + if(isset($oldStages[$branch])) + { + $oldStage = $oldStages[$branch]; + if(!empty($oldStage->stagedBy)) + { + $this->dao->replace(TABLE_STORYSTAGE)->data($oldStage)->exec(); + continue; + } + } + $this->dao->replace(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq('projected')->exec(); + } $this->dao->update(TABLE_STORY)->set('stage')->eq('projected')->where('id')->eq($storyID)->exec(); } @@ -1284,7 +1326,16 @@ class storyModel extends model $minStage = ''; foreach($stages as $branch => $stage) { - $this->dao->insert(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq($stage)->exec(); + $this->dao->replace(TABLE_STORYSTAGE)->set('story')->eq($storyID)->set('branch')->eq($branch)->set('stage')->eq($stage)->exec(); + if(isset($oldStages[$branch])) + { + $oldStage = $oldStages[$branch]; + if(!empty($oldStage->stagedBy)) + { + $this->dao->replace(TABLE_STORYSTAGE)->data($oldStage)->exec(); + $stage = $oldStage->$stage; + } + } if(strpos($stageList, $stage) !== false and strpos($stageList, $stage) < $minStagePos) { $minStage = $stage; @@ -2424,7 +2475,7 @@ class storyModel extends model echo ""; echo ''; diff --git a/module/upgrade/model.php b/module/upgrade/model.php index af581265c0..0edbea0a80 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -2294,6 +2294,27 @@ class upgradeModel extends model return true; } + /** + * Add unique key for stage. + * + * @access public + * @return bool + */ + public function addUniqueKey4Stage() + { + $this->saveLogs('Run Method ' . __FUNCTION__); + $stmt = $this->dao->select('story,branch')->from(TABLE_STORYSTAGE)->orderBy('story,branch')->query(); + $preStage = ''; + while($stage = $stmt->fetch()) + { + if($preStage == "{$stage->story}_{$stage->branch}") $this->dao->delete()->from(TABLE_STORYSTAGE)->where('story')->eq($stage->story)->andWhere('branch')->eq($stage->branch)->exec(); + $preStage = "{$stage->story}_{$stage->branch}"; + } + $this->dao->exec("ALTER TABLE " . TABLE_STORYSTAGE . " ADD UNIQUE `story_branch` (`story`, `branch`)"); + $this->saveLogs($this->dao->get()); + return true; + } + /** * Judge any error occers. *