r77193 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77192‎ | r77193 | r77194 >
Date:22:23, 23 November 2010
Author:hashar
Status:reverted (Comments)
Tags:
Comment:
Merge non existing signoff flags, ignore existing ones
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeRevision.php
@@ -629,14 +629,33 @@
630630 return $refs;
631631 }
632632
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+
634656 $db = wfGetDB( $from );
635657 $result = $db->select( 'code_signoffs',
636658 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,
641660 __METHOD__,
642661 array( 'ORDER BY' => 'cs_timestamp' )
643662 );
@@ -669,6 +688,27 @@
670689 $dbw->insert( 'code_signoffs', $rows, __METHOD__ );
671690 }
672691
 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+
673713 public function getTags( $from = DB_SLAVE ) {
674714 $db = wfGetDB( $from );
675715 $result = $db->select( 'code_tags',
Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php
@@ -86,7 +86,7 @@
8787 }
8888 // Add any signoffs
8989 if ( count( $signoffFlags ) && $this->validPost( 'codereview-signoff' ) ) {
90 - $this->mRev->addSignoff( $wgUser, $signoffFlags );
 90+ $this->mRev->mergeSignoff( $wgUser, $signoffFlags );
9191 }
9292 // Add any comments
9393 $commentAdded = false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r77289Revert r77193: this seems to have intended to fix bug 26042, but r77288 handl...catrope14:59, 25 November 2010

Comments

#Comment by Reedy (talk | contribs)   22:25, 23 November 2010
+		} else {
+			# We skipped insertion / replacement
+		}

Ewww

#Comment by Nikerabbit (talk | contribs)   08:19, 24 November 2010

+ # compare with posted ones and only keep non existant existent or existing? what and where and for what purpose?

#Comment by Hashar (talk | contribs)   21:47, 24 November 2010

Maybe changes it too:

  1. compare posted flags with existing flags. Only keep the one to be inserted since
  2. flags are unique per users (see code_signoffs table index cs_repo_rev_user_flag
#Comment by Hashar (talk | contribs)   21:48, 24 November 2010

s/changes it too/changes it to/  :(

Status & tagging log