r52553 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52552‎ | r52553 | r52554 >
Date:16:35, 29 June 2009
Author:werdna
Status:deferred
Tags:
Comment:
Replace weird SQL with a single abstracted replace call, and remove unnecessary globals.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/LqtNewMessages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/LqtNewMessages.php
@@ -12,28 +12,28 @@
1313 }
1414
1515 private static function writeUserMessageState( $thread, $user, $timestamp ) {
16 - global $wgDBprefix;
17 - if ( is_object( $thread ) ) $thread_id = $thread->id();
18 - else if ( is_integer( $thread ) ) $thread_id = $thread;
19 - else throw new MWException( "writeUserMessageState expected Thread or integer but got $thread" );
 16+ if ( is_object( $thread ) ) {
 17+ $thread_id = $thread->id();
 18+ } else if ( is_integer( $thread ) ) {
 19+ $thread_id = $thread;
 20+ } else {
 21+ throw new MWException( "writeUserMessageState expected Thread or integer but got $thread" );
 22+ }
2023
21 - if ( is_object( $user ) ) $user_id = $user->getID();
22 - else if ( is_integer( $user ) ) $user_id = $user;
23 - else throw new MWException( "writeUserMessageState expected User or integer but got $user" );
 24+ if ( is_object( $user ) ) {
 25+ $user_id = $user->getID();
 26+ } else if ( is_integer( $user ) ) {
 27+ $user_id = $user;
 28+ } else {
 29+ throw new MWException( "writeUserMessageState expected User or integer but got $user" );
 30+ }
2431
25 - if ( $timestamp === null ) $timestamp = "NULL";
26 -
2732 // use query() directly to pass in 'true' for don't-die-on-errors.
28 - $dbr =& wfGetDB( DB_MASTER );
29 - $success = $dbr->query( "insert into {$wgDBprefix}user_message_state values ($user_id, $thread_id, $timestamp)",
30 - __METHOD__, true );
31 -
32 - if ( !$success ) {
33 - // duplicate key; update.
34 - $dbr->query( "update {$wgDBprefix}user_message_state set ums_read_timestamp = $timestamp" .
35 - " where ums_thread = $thread_id and ums_user = $user_id",
36 - __METHOD__ );
37 - }
 33+ $dbw = wfGetDB( DB_MASTER );
 34+
 35+ $dbw->replace( 'user_message_state', array( array( 'ums_user', 'ums_thread' ) ),
 36+ array( 'ums_user' => $user_id, 'ums_thread' => $thread_id,
 37+ 'ums_read_timestamp' => $timestamp ), __METHOD__ );
3838 }
3939
4040 /**
@@ -41,7 +41,7 @@
4242 * If the thread is on a user's talkpage, set that user's newtalk.
4343 */
4444 static function writeMessageStateForUpdatedThread( $t, $type, $changeUser ) {
45 - global $wgDBprefix, $wgUser;
 45+ global $wgUser;
4646
4747 wfDebugLog( 'LiquidThreads', 'Doing notifications' );
4848

Status & tagging log