Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -629,14 +629,33 @@ |
630 | 630 | return $refs; |
631 | 631 | } |
632 | 632 | |
633 | | - public function getSignoffs( $from = DB_SLAVE ) { |
| 633 | + public function getSignoffsForUser( $user, $from = DB_SLAVE ) { |
| 634 | + return $this->fetchSignoffs( array( 'user' => $user ), $from ); |
| 635 | + } |
| 636 | + |
| 637 | + public function getSignoffs( $from = DB_SLAVE) { |
| 638 | + return $this->fetchSignoffs( array(), $from ); |
| 639 | + } |
| 640 | + |
| 641 | + /** |
| 642 | + * @param $options Array: array of filtering options |
| 643 | + * @param $from DB_SLAVE|DB_MASTER |
| 644 | + */ |
| 645 | + private function fetchSignoffs( $options, $from = DB_SLAVE ) { |
| 646 | + # Default conditions for DB query. |
| 647 | + $fetchConditions = array( |
| 648 | + 'cs_repo_id' => $this->mRepoId, |
| 649 | + 'cs_rev_id' => $this->mId, |
| 650 | + ); |
| 651 | + # Add a filter on user id (see getSignoffsForUser()) |
| 652 | + if( isset($options['user']) ) { |
| 653 | + $fetchConditions['cs_user'] = $options['user']->getID() ; |
| 654 | + } |
| 655 | + |
634 | 656 | $db = wfGetDB( $from ); |
635 | 657 | $result = $db->select( 'code_signoffs', |
636 | 658 | array( 'cs_user', 'cs_user_text', 'cs_flag', 'cs_timestamp' ), |
637 | | - array( |
638 | | - 'cs_repo_id' => $this->mRepoId, |
639 | | - 'cs_rev_id' => $this->mId, |
640 | | - ), |
| 659 | + $fetchConditions, |
641 | 660 | __METHOD__, |
642 | 661 | array( 'ORDER BY' => 'cs_timestamp' ) |
643 | 662 | ); |
— | — | @@ -669,6 +688,27 @@ |
670 | 689 | $dbw->insert( 'code_signoffs', $rows, __METHOD__ ); |
671 | 690 | } |
672 | 691 | |
| 692 | + /** |
| 693 | + * Skip already existing signoffs. |
| 694 | + */ |
| 695 | + public function mergeSignoff( $user, $postedFlags, $from = DB_SLAVE ) { |
| 696 | + $existingFlags = array(); |
| 697 | + $userSignoffs = $this->getSignoffsForUser( $user, $from ); |
| 698 | + |
| 699 | + # get user existing signoffs flags |
| 700 | + foreach( $userSignoffs as $signoff ) { |
| 701 | + $existingFlags[] = $signoff->flag; |
| 702 | + } |
| 703 | + |
| 704 | + # compare with posted ones and only keep non existant |
| 705 | + $addFlags = array_diff( $postedFlags, $existingFlags ); |
| 706 | + if( count( $addFlags ) ) { |
| 707 | + $this->addSignoff( $user, $addFlags ); |
| 708 | + } else { |
| 709 | + # We skipped insertion / replacement |
| 710 | + } |
| 711 | + } |
| 712 | + |
673 | 713 | public function getTags( $from = DB_SLAVE ) { |
674 | 714 | $db = wfGetDB( $from ); |
675 | 715 | $result = $db->select( 'code_tags', |
Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | } |
88 | 88 | // Add any signoffs |
89 | 89 | if ( count( $signoffFlags ) && $this->validPost( 'codereview-signoff' ) ) { |
90 | | - $this->mRev->addSignoff( $wgUser, $signoffFlags ); |
| 90 | + $this->mRev->mergeSignoff( $wgUser, $signoffFlags ); |
91 | 91 | } |
92 | 92 | // Add any comments |
93 | 93 | $commentAdded = false; |