r81030 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81029‎ | r81030 | r81031 >
Date:16:28, 26 January 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Reapplying r70018 in a cleaner way
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/NewMessagesController.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/NewMessagesController.php
@@ -245,40 +245,36 @@
246246 }
247247
248248 // Send email notification, fetching all the data in one go
 249+ $tableNameUserProperties = $dbr->tableName( 'user_properties' );
249250
250 - global $wgVersion;
251 - $tables = array( 'user' );
 251+ $tables = array(
 252+ 'user',
 253+ $tableNameUserProperties . ' AS tc_prop',
 254+ $tableNameUserProperties . ' AS l_prop'
 255+ );
252256 $dbr = wfGetDB( DB_SLAVE );
253 - $fields = array( $dbr->tableName( 'user' ) . '.*' );
254 - $join_conds = array();
255 - $oldPreferenceFormat = false;
256 - if ( version_compare( $wgVersion, '1.16', '<' ) ) {
257 - $oldPreferenceFormat = true;
258 - } else {
259 - $tableNameUserProperties = $dbr->tableName( 'user_properties' );
 257+ $fields = array(
 258+ $dbr->tableName( 'user' ) . '.*',
 259+ 'tc_prop.up_value AS timecorrection',
 260+ 'l_prop.up_value as language'
 261+ );
260262
261 - $tables[] = $tableNameUserProperties . ' as tc_prop';
262 - $fields[] = 'tc_prop.up_value as timecorrection';
263 -
264 - $join_conds[$tableNameUserProperties . ' as tc_prop'] = array(
265 - 'left join',
 263+ $join_conds = array(
 264+ $tableNameUserProperties . ' AS tc_prop' => array(
 265+ 'LEFT JOIN',
266266 array(
267267 'tc_prop.up_user=user_id',
268268 'tc_prop.up_property' => 'timecorrection',
269269 )
270 - );
271 -
272 - $tables[] = $tableNameUserProperties . ' as l_prop';
273 - $fields[] = 'l_prop.up_value as language';
274 -
275 - $join_conds[$tableNameUserProperties . ' as l_prop'] = array(
276 - 'left join',
 270+ ),
 271+ $tableNameUserProperties . ' AS l_prop' => array(
 272+ 'LEFT JOIN',
277273 array(
278274 'l_prop.up_user=user_id',
279275 'l_prop.up_property' => 'language',
280276 )
281 - );
282 - }
 277+ )
 278+ );
283279
284280 $res = $dbr->select(
285281 $tables, $fields,
@@ -300,9 +296,7 @@
301297 foreach( $res as $row ) {
302298 $u = User::newFromRow( $row );
303299
304 - if ( $oldPreferenceFormat ) {
305 - $langCode = $u->getOption( 'language' );
306 - } elseif ( $row->language ) {
 300+ if ( $row->language ) {
307301 $langCode = $row->language;
308302 } else {
309303 global $wgLanguageCode;
@@ -312,11 +306,7 @@
313307 $lang = Language::factory( $langCode );
314308
315309 // Adjust with time correction
316 - if ( $oldPreferenceFormat ) {
317 - $timeCorrection = $u->getOption( 'timecorrection' );
318 - } else {
319 - $timeCorrection = $row->timecorrection;
320 - }
 310+ $timeCorrection = $row->timecorrection;
321311 $adjustedTimestamp = $lang->userAdjust( $timestamp, $timeCorrection );
322312
323313 $date = $lang->date( $adjustedTimestamp );
@@ -331,7 +321,7 @@
332322 $msg = wfMsgReal( $msgName, $params, true /* use DB */, $langCode,
333323 true /*transform*/ );
334324
335 - $to = new MailAddress( $u );
 325+ $to = new MailAddress( $u );
336326 $subject = wfMsgReal( $subjectMsg, array( $threadSubject ), true /* use DB */,
337327 $langCode, true /* transform */ );
338328

Follow-up revisions

RevisionCommit summaryAuthorDate
r81031Improvement on r81030, pass on table aliasing to database code, and also tabl...reedy16:32, 26 January 2011
r81833Fixup fixme on r81030, which should actually have been a fixme on r81657reedy18:57, 9 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70018Kill off some more < 1.16 stuffreedy15:52, 27 July 2010

Comments

#Comment by Raymond (talk | contribs)   18:11, 9 February 2011

Seen on Translatewiki:

Query: SELECT `bw_user`.*,tc_prop.up_value AS timecorrection,l_prop.up_value as language FROM `bw_user` LEFT JOIN `bw_user_properties` 'tc_prop' ON ((tc_prop.up_user=user_id) AND tc_prop.up_property = 'timecorrection') LEFT JOIN `bw_user_properties` 'l_prop' ON ((l_prop.up_user=user_id) AND l_prop.up_property = 'language') WHERE user_id = '3016'

Function: NewMessages::notifyUsersByMail

Error: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near” tc_prop' ON ((tc_prop.up_user=user_id) AND tc_prop.up_property = 'timecorrectio' at line 1 (localhost)

#Comment by Reedy (talk | contribs)   18:50, 9 February 2011

The issue is that the alias is being quoted, when we don't want it to be...

I bet it's actually r81657 at fault

#Comment by Reedy (talk | contribs)   18:51, 9 February 2011

Yeah, it is.

> $dbr = wfGetDB( DB_SLAVE );

> $tables = array('user', 'tc_prop' => 'user_properties', 'l_prop' => 'user_properties');

> $fields = array( $dbr->tableName( 'user' ) . '.*', 'tc_prop.up_value AS timecorrection', 'l_prop.up_value as language' );                                                                                    
> $join_conds = array( 'tc_prop' => array( 'LEFT JOIN', array( 'tc_prop.up_user=user_id','tc_prop.up_property' => 'timecorrection',)),'l_prop' => array('LEFT JOIN',array('l_prop.up_user=user_id','l_prop.up_property' => 'language',)));

> $dbr = wfGetDB( DB_SLAVE );

>

Status & tagging log