From 6d5eb4fa8e4f62957f2e841687a31ce992c30cea Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Tue, 10 Aug 2021 15:53:13 +0800 Subject: [PATCH] * Finish task #41242. --- module/story/control.php | 7 +++-- module/story/model.php | 65 +++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/module/story/control.php b/module/story/control.php index 8ee5a75e54..87eab50d21 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -572,6 +572,9 @@ class story extends control $action = !empty($changes) ? 'Edited' : 'Commented'; $actionID = $this->action->create('story', $storyID, $action, $this->post->comment); $this->action->logHistory($actionID, $changes); + + $story = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch(); + $this->story->recordReviewAction($story); } $this->executeHooks($storyID); @@ -603,11 +606,11 @@ class story extends control /* Get users. */ $users = $this->user->getPairs('pofirst|nodeleted|noclosed', "$story->assignedTo,$story->openedBy,$story->closedBy"); - $isShowReviewer = true; + $isShowReviewer = false; $reviewerList = $this->story->getReviewerPairs($story->id, $story->version); $reviewerList = array_keys($reviewerList); $reviewedBy = explode(',', trim($story->reviewedBy, ',')); - if(!array_diff($reviewerList, $reviewedBy)) $isShowReviewer = false; + if(array_diff($reviewerList, $reviewedBy) and strpos('draft,changed', $story->status) !== false) $isShowReviewer = true; $reviewedReviewer = array(); foreach($reviewedBy as $reviewer) $reviewedReviewer[] = zget($users, $reviewer); diff --git a/module/story/model.php b/module/story/model.php index b3d8dbcaf9..28d3eefc8e 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -720,7 +720,7 @@ class storyModel extends model * * @param int $storyID * @access public - * @return array the changes of the story. + * @return array the changes of the story. */ public function update($storyID) { @@ -791,6 +791,44 @@ class storyModel extends model if(isset($story->stage) and $oldStory->stage != $story->stage) $story->stagedBy = (strpos('tested|verified|released|closed', $story->stage) !== false) ? $this->app->user->account : ''; + if(isset($_POST['reviewer'])) + { + $_POST['reviewer'] = array_filter($_POST['reviewer']); + $oldReviewer = $this->getReviewerPairs($storyID, $oldStory->version); + + /* Update story reviewer. */ + $this->dao->delete()->from(TABLE_STORYREVIEW)->where('story')->eq($storyID)->andWhere('version')->eq($oldStory->version)->andWhere('reviewer')->notin(implode(',', $_POST['reviewer']))->exec(); + foreach($_POST['reviewer'] as $reviewer) + { + if(in_array($reviewer, array_keys($oldReviewer))) continue; + + $reviewData = new stdclass(); + $reviewData->story = $storyID; + $reviewData->version = $oldStory->version; + $reviewData->reviewer = $reviewer; + $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); + } + + /* Update the story status by review rules. */ + $reviewerList = $this->getReviewerPairs($storyID, $oldStory->version); + $reviewedBy = explode(',', trim($oldStory->reviewedBy, ',')); + if(!array_diff(array_keys($reviewerList), $reviewedBy)) + { + $status = $this->setStatusByReviewRules($reviewerList); + $story->status = $status ? $status : $oldStory->status; + if($story->status == 'closed') + { + $story->closedBy = $this->app->user->account; + $story->closedDate = $now; + $story->assignedTo = 'closed'; + $story->assignedDate = $now; + $story->stage = 'closed'; + if($this->post->closedReason == 'done') $story->stage = 'released'; + } + + } + } + $this->dao->update(TABLE_STORY) ->data($story) ->autoCheck() @@ -869,27 +907,6 @@ class storyModel extends model if(empty($oldStory->plan) or empty($story->plan)) $this->setStage($storyID); // Set new stage for this story. } - if(isset($_POST['reviewer'])) - { - $_POST['reviewer'] = array_filter($_POST['reviewer']); - $oldReviewer = $this->getReviewerPairs($storyID, $oldStory->version); - $oldStory->reviewers = implode(',', array_keys($oldReviewer)); - $story->reviewers = implode(',', $_POST['reviewer']); - - /* Update story reviewer. */ - $this->dao->delete()->from(TABLE_STORYREVIEW)->where('story')->eq($storyID)->andWhere('version')->eq($oldStory->version)->andWhere('reviewer')->notin(implode(',', $_POST['reviewer']))->exec(); - foreach($_POST['reviewer'] as $reviewer) - { - if(in_array($reviewer, array_keys($oldReviewer))) continue; - - $reviewData = new stdclass(); - $reviewData->story = $storyID; - $reviewData->version = $oldStory->version; - $reviewData->reviewer = $reviewer; - $this->dao->insert(TABLE_STORYREVIEW)->data($reviewData)->exec(); - } - } - unset($oldStory->parent); unset($story->parent); return common::createChanges($oldStory, $story); @@ -4467,14 +4484,14 @@ class storyModel extends model * @access public * @return int */ - public function recordReviewAction($story, $result, $reason) + public function recordReviewAction($story, $result = '', $reason = '') { $reasonParam = $result == 'reject' ? ',' . $reason : ''; $reviewers = $this->getReviewerPairs($story->id, $story->version); $reviewedBy = explode(',', trim($story->reviewedBy, ',')); $comment = isset($_POST['comment']) ? $this->post->comment : ''; - $actionID = $this->loadModel('action')->create('story', $story->id, 'Reviewed', $comment, ucfirst($result) . $reasonParam); + $actionID = !empty($result) ? $this->loadModel('action')->create('story', $story->id, 'Reviewed', $comment, ucfirst($result) . $reasonParam) : ''; if($story->status == 'closed') $this->action->create('story', $story->id, 'ReviewClosed'); if($story->status == 'active') $this->action->create('story', $story->id, 'PassReviewed');