r100828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100827‎ | r100828 | r100829 >
Date:17:24, 26 October 2011
Author:aaron
Status:ok
Tags:
Comment:
committed the live hacks for this script
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/FlaggedRevs/maintenance/fixBug28348.inc (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/FlaggedRevs/maintenance/fixBug28348.inc
@@ -3,16 +3,17 @@
44 function update_images_bug_28348( $start = null ) {
55 echo "Correcting fi_img_timestamp column in flaggedimages\n";
66
7 - $BATCH_SIZE = 5000;
 7+ $BATCH_SIZE = 3000;
88
99 $logFilePath = "bug28348-fixed-" . wfWikiID();
10 - if ( 0 && file_exists( $logFilePath ) ) {
 10+ if ( file_exists( $logFilePath ) ) {
1111 echo "Already done\n";
1212 return;
1313 }
1414
1515 $db = wfGetDB( DB_MASTER );
16 -
 16+ $dbCommons = wfGetDB( DB_SLAVE, array(), 'commonswiki' );
 17+
1718 if( $start === null ) {
1819 $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ );
1920 }
@@ -31,46 +32,61 @@
3233 $count = $changed = 0;
3334 while( $blockEnd <= $end ) {
3435 echo "...doing fi_rev_id from $blockStart to $blockEnd\n";
35 - $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd" .
36 - " AND fi_img_timestamp IS NOT NULL AND img_name IS NULL"; // optimize
37 - $res = $db->select( array( 'flaggedimages', 'image' ), '*', $cond,
 36+ $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd AND fi_img_timestamp IS NOT NULL" .
 37+ " AND img_name IS NULL AND oi_name IS NULL"; // optimize
 38+ $res = $db->select( array( 'flaggedimages', 'image', 'oldimage' ),
 39+ '*',
 40+ $cond,
3841 __FUNCTION__,
3942 array(),
40 - array( 'image' => array( 'LEFT JOIN',
41 - 'img_sha1 = fi_img_sha1 AND img_timestamp = fi_img_timestamp' ) )
 43+ array( // skip OK references to local files
 44+ 'image' => array( 'LEFT JOIN',
 45+ 'img_sha1 = fi_img_sha1 AND img_timestamp = fi_img_timestamp' ),
 46+ 'oldimage' => array( 'LEFT JOIN',
 47+ 'oi_sha1 = fi_img_sha1 AND oi_timestamp = fi_img_timestamp' )
 48+ )
4249 );
4350
 51+ $didAnything = false;
4452 $db->begin();
45 - # Go through and clean up missing items, as well as correct fr_quality...
46 - foreach( $res as $row ) {
 53+ # Go through and clean up broken file rows
 54+ foreach ( $res as $row ) {
4755 $count++;
 56+ $sha1 = $row->fi_img_sha1;
4857 $fi_img_timestamp = trim( $row->fi_img_timestamp ); // clear pad garbage
4958 if ( !$fi_img_timestamp ) {
5059 continue; // nothing to check
5160 }
5261 $time = wfTimestamp( TS_MW, $fi_img_timestamp );
53 - $sha1 = $row->fi_img_sha1;
54 - # Check if the specified file exists...
55 - $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) );
56 - if ( !$file ) { // doesn't exist?
57 - $time = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $time ) + 1 );
58 - # Check if the fi_img_timestamp value is off by 1 second...
 62+ $offsetTime = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $time ) + 1 );
 63+ # WMF optimization
 64+ $ok = $dbCommons->select( 'image', '1',
 65+ array( 'img_sha1' => $sha1, 'img_timestamp' => $dbCommons->timestamp( $time ) ) );
 66+ if ( $ok ) {
 67+ continue; // current version is it; skip since it must be OK
 68+ }
 69+ # Check if the file exists with offset time...
 70+ $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $offsetTime ) );
 71+ if ( $file ) { // doesn't exist?
 72+ # Confirm that fi_img_timestamp value is off by 1 second...
5973 $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) );
60 - if ( $file ) {
 74+ if ( !$file ) {
6175 echo "fixed file {$row->fi_name} reference in rev ID {$row->fi_rev_id}\n";
6276 # Fix the fi_img_timestamp value...
6377 $db->update( 'flaggedimages',
64 - array( 'fi_img_timestamp' => $db->timestamp( $time ) ),
 78+ array( 'fi_img_timestamp' => $db->timestamp( $offsetTime ) ),
6579 array( 'fi_rev_id' => $row->fi_rev_id, 'fi_name' => $row->fi_name ),
6680 __METHOD__
6781 );
6882 $changed++;
 83+ $didAnything = true;
6984 $logDump .= "{$row->fi_rev_id} {$row->fi_name} {$fi_img_timestamp}\n";
7085 }
7186 }
7287 }
73 - $didAnything = ( $res->numRows() > 0 );
74 - file_put_contents( $logFilePath, $logDump, FILE_APPEND );
 88+ if ( $logDump != '' ) {
 89+ file_put_contents( $logFilePath, $logDump, FILE_APPEND );
 90+ }
7591 $logDump = '';
7692 $db->commit();
7793

Status & tagging log