diff --git a/trunk/module/story/control.php b/trunk/module/story/control.php index 83b20eab24..ee39993737 100644 --- a/trunk/module/story/control.php +++ b/trunk/module/story/control.php @@ -123,7 +123,8 @@ class story extends control { $changes = $this->story->change($storyID); if(dao::isError()) die(js::error(dao::getError())); - $files = $this->loadModel('file')->saveUpload('story', $storyID); + $version = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch('version'); + $files = $this->loadModel('file')->saveUpload('story', $storyID, $version); if($this->post->comment != '' or !empty($changes) or !empty($files)) { $action = (!empty($changes) or !empty($files)) ? 'Changed' : 'Commented'; @@ -170,6 +171,7 @@ class story extends control $this->assign('users', $users); $this->assign('actions', $this->action->getList('story', $storyID)); $this->assign('modulePath', $modulePath); + $this->assign('version', $version); $this->display(); } @@ -197,10 +199,15 @@ class story extends control if(!empty($_POST)) { - $this->story->reivew($storyID); - $action = "Reviewed"; + $this->story->review($storyID); + $action = "Reviewed as " . ucfirst($this->post->result); $actionID = $this->action->create('story', $storyID, $action, $this->post->comment); $this->action->logHistory($actionID); + if($this->post->result == 'reject') + { + $action = "Closed for " . ucfirst($this->post->closedReason); + $this->action->create('story', $storyID, $action); + } die(js::locate(inlink('view', "storyID=$storyID"), 'parent')); } diff --git a/trunk/module/story/lang/zh-cn.php b/trunk/module/story/lang/zh-cn.php index ed4c1525d4..cdb0d98873 100644 --- a/trunk/module/story/lang/zh-cn.php +++ b/trunk/module/story/lang/zh-cn.php @@ -32,10 +32,12 @@ $lang->story->manage = "操作"; $lang->story->tasks = "相关任务"; $lang->story->bugs = "Bug"; -$lang->story->reviewDelete = "您确认删除该需求吗?"; -$lang->story->errorFormat = '需求数据有误'; -$lang->story->errorEmptyTitle = '标题不能为空'; -$lang->story->linkStory = '关联需求'; +$lang->story->reviewDelete = "您确认删除该需求吗?"; +$lang->story->errorFormat = '需求数据有误'; +$lang->story->errorEmptyTitle = '标题不能为空'; +$lang->story->mustChooseResult = '必须选择评审结果'; +$lang->story->mustChoosePreVersion = '必须选择回溯的版本'; +$lang->story->linkStory = '关联需求'; $lang->story->ajaxGetProjectStories = '接口:获取项目需求列表'; $lang->story->ajaxGetProductStories = '接口:获取产品需求列表'; @@ -123,3 +125,4 @@ $lang->story->linkStories = '相关需求'; $lang->story->childStories = '细分需求'; $lang->story->duplicateStory = '重复需求'; $lang->story->reviewResult = '评审结果'; +$lang->story->preVersion = '之前版本'; diff --git a/trunk/module/story/model.php b/trunk/module/story/model.php index 49a2783c92..b5279cb78e 100644 --- a/trunk/module/story/model.php +++ b/trunk/module/story/model.php @@ -32,7 +32,9 @@ class storyModel extends model if(!$story) return false; if(substr($story->closedDate, 0, 4) == '0000') $story->closedDate = ''; if($version == 0) $version = $story->version; - $story->spec = $this->dao->select('spec')->from(TABLE_STORYSPEC)->where('story')->eq($storyID)->andWhere('version')->eq($version)->fetch('spec'); + $spec = $this->dao->select('title,spec')->from(TABLE_STORYSPEC)->where('story')->eq($storyID)->andWhere('version')->eq($version)->fetch(); + $story->title = $spec->title; + $story->spec = $spec->spec; $story->projects = $this->dao->select('t1.project, t2.name') ->from(TABLE_PROJECTSTORY)->alias('t1') ->leftJoin(TABLE_PROJECT)->alias('t2') @@ -76,9 +78,13 @@ class storyModel extends model if(!dao::isError()) { $storyID = $this->dao->lastInsertID(); - $this->loadModel('file')->saveUpload('story', $storyID); + $this->loadModel('file')->saveUpload('story', $storyID, $extra = 1); $spec = htmlspecialchars($this->post->spec); - $this->dao->insert(TABLE_STORYSPEC)->set('story')->eq($storyID)->set('version')->eq(1)->set('spec')->eq($spec)->exec(); + $this->dao->insert(TABLE_STORYSPEC) + ->set('story')->eq($storyID) + ->set('version')->eq(1) + ->set('title')->eq($story->title) + ->set('spec')->eq($spec)->exec(); return $storyID; } return false; @@ -106,7 +112,6 @@ class storyModel extends model ->setIF($specChanged and $oldStory->closedBy, 'closedDate', '') ->remove('files,labels,spec,comment') ->get(); - $this->dao->update(TABLE_STORY) ->data($story) ->autoCheck() @@ -117,7 +122,12 @@ class storyModel extends model if($specChanged) { $spec = htmlspecialchars($this->post->spec); - $this->dao->insert(TABLE_STORYSPEC)->set('story')->eq($storyID)->set('version')->eq($oldStory->version + 1)->set('spec')->eq($spec)->exec(); + $this->dao->insert(TABLE_STORYSPEC) + ->set('story')->eq($storyID) + ->set('version')->eq($oldStory->version + 1) + ->set('title')->eq($story->title) + ->set('spec')->eq($spec) + ->exec(); $story->spec = $this->post->spec; } else @@ -172,12 +182,40 @@ class storyModel extends model /* 评审需求。*/ public function review($storyID) { + if($this->post->result == false) die(js::alert($this->lang->story->mustChooseResult)); + if($this->post->result == 'revert' and $this->post->preVersion == false) die(js::alert($this->lang->story->mustChoosePreVersion)); + $oldStory = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch(); - $story->confirmedBy = $this->app->user->account; - $story->confirmedDate = date('Y-m-d H:i:s'); - $story->status = 'active'; - if($oldStory->status == 'changed') $story->version = $oldStory->version + 1; - $this->dao->update(TABLE_STORY)->data($story)->where('id')->eq($storyID)->exec(); + $now = date('Y-m-d H:i:s'); + $story = fixer::input('post') + ->remove('result,preVersion,comment') + ->add('reviewedDate', $now) + ->add('lastEditedBy', $this->app->user->account) + ->add('lastEditedDate', $now) + ->setIF($this->post->result == 'pass' and $oldStory->status == 'draft', 'status', 'active') + ->setIF($this->post->result == 'pass' and $oldStory->status == 'changed', 'status', 'active') + ->setIF($this->post->result == 'reject', 'closedBy', $this->app->user->account) + ->setIF($this->post->result == 'reject', 'closedDate', $now) + ->setIF($this->post->result == 'reject', 'status', 'closed') + ->setIF($this->post->result == 'revert', 'version', $this->post->preVersion) + ->setIF($this->post->result == 'revert', 'status', 'active') + ->removeIF($this->post->result == 'pass' or $this->post->result == 'revert', 'closedReason, duplicateStory, childStories') + ->removeIF($this->post->result == 'reject' and $this->post->closedReason != 'duplicate', 'duplicateStory') + ->removeIF($this->post->result == 'reject' and $this->post->closedReason != 'subdivided', 'childStories') + ->get(); + $this->dao->update(TABLE_STORY)->data($story) + ->autoCheck() + ->batchCheck('assignedTo, reviewedBy', 'notempty') + ->checkIF($this->post->result == 'reject' and $this->post->closedReason == 'duplicate', 'duplicateStory', 'notempty') + ->checkIF($this->post->result == 'reject' and $this->post->closedReason == 'subdivided', 'childStories', 'notempty') + ->where('id')->eq($storyID)->exec(); + if($this->post->result == 'revert') + { + $preTitle = $this->dao->select('title')->from(TABLE_STORYSPEC)->where('story')->eq($storyID)->andWHere('version')->eq($this->post->preVersion)->fetch('title'); + $this->dao->update(TABLE_STORY)->set('title')->eq($preTitle)->where('id')->eq($storyID)->exec(); + $this->dao->delete()->from(TABLE_STORYSPEC)->where('story')->eq($storyID)->andWHere('version')->eq($oldStory->version)->exec(); + $this->dao->delete()->from(TABLE_FILE)->where('objectType')->eq('story')->andWhere('objectID')->eq($storyID)->andWhere('extra')->eq($oldStory->version)->exec(); + } return true; } diff --git a/trunk/module/story/view/review.html.php b/trunk/module/story/view/review.html.php index fb0adc55de..a171598caa 100644 --- a/trunk/module/story/view/review.html.php +++ b/trunk/module/story/view/review.html.php @@ -24,15 +24,46 @@ ?> @@ -42,15 +73,29 @@ function setClosedReason(result)