Index: trunk/extensions/FlaggedRevs/maintenance/fixBug28348.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 5 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
| 6 | +} else { |
| 7 | + $IP = dirname(__FILE__).'/../../..'; |
| 8 | +} |
| 9 | + |
| 10 | +$options = array( 'help', 'startrev' ); |
| 11 | +require "$IP/maintenance/commandLine.inc"; |
| 12 | +require dirname(__FILE__) . '/fixBug28348.inc'; |
| 13 | + |
| 14 | +if ( isset($options['help']) ) { |
| 15 | + echo <<<TEXT |
| 16 | +Purpose: |
| 17 | + Correct bad fi_img_timestamp rows due to bug 28348 |
| 18 | +Usage: |
| 19 | + php updateLinks.php --help |
| 20 | + php updateLinks.php [--startrev <ID>] |
| 21 | + |
| 22 | + --help : This help message |
| 23 | + --<ID> : The ID of the starting rev |
| 24 | + --<CALL> : One of (revs) |
| 25 | + |
| 26 | +TEXT; |
| 27 | + exit(0); |
| 28 | +} |
| 29 | + |
| 30 | +error_reporting( E_ALL ); |
| 31 | + |
| 32 | +$startRev = isset( $options['startrev'] ) ? |
| 33 | + (int)$options['startrev'] : null; |
| 34 | + |
| 35 | +update_images_bug_28348( $startRev ); |
Property changes on: trunk/extensions/FlaggedRevs/maintenance/fixBug28348.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 36 | + native |
Index: trunk/extensions/FlaggedRevs/maintenance/fixBug28348.inc |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +function update_images_bug_28348( $start = null ) { |
| 5 | + echo "Correcting fi_img_timestamp column in flaggedimages\n"; |
| 6 | + |
| 7 | + $BATCH_SIZE = 1000; |
| 8 | + |
| 9 | + $db = wfGetDB( DB_MASTER ); |
| 10 | + |
| 11 | + if( $start === null ) { |
| 12 | + $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ ); |
| 13 | + } |
| 14 | + $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __FUNCTION__ ); |
| 15 | + if( is_null( $start ) || is_null( $end ) ) { |
| 16 | + echo "...flaggedimages table seems to be empty.\n"; |
| 17 | + return; |
| 18 | + } |
| 19 | + # Do remaining chunk |
| 20 | + $end += $BATCH_SIZE - 1; |
| 21 | + $blockStart = $start; |
| 22 | + $blockEnd = $start + $BATCH_SIZE - 1; |
| 23 | + |
| 24 | + $count = $changed = 0; |
| 25 | + while( $blockEnd <= $end ) { |
| 26 | + echo "...doing fi_rev_id from $blockStart to $blockEnd\n"; |
| 27 | + $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
| 28 | + $res = $db->select( 'flaggedimages', '*', $cond, __FUNCTION__ ); |
| 29 | + |
| 30 | + $db->begin(); |
| 31 | + # Go through and clean up missing items, as well as correct fr_quality... |
| 32 | + foreach( $res as $row ) { |
| 33 | + $count++; |
| 34 | + $fi_img_timestamp = trim( $row->fi_img_timestamp ); // clear pad garbage |
| 35 | + if ( !$fi_img_timestamp ) { |
| 36 | + continue; // nothing to check |
| 37 | + } |
| 38 | + $time = wfTimestamp( TS_MW, $fi_img_timestamp ); |
| 39 | + $sha1 = $row->fi_img_sha1; |
| 40 | + # Check if the specified file exists... |
| 41 | + $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
| 42 | + if ( !$file ) { // doesn't exist? |
| 43 | + $time = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $time ) + 1 ); |
| 44 | + # Check if the fi_img_timestamp value is off by 1 second... |
| 45 | + $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
| 46 | + if ( $file ) { |
| 47 | + echo "fixed file {$row->fi_name} reference in rev ID {$row->fi_rev_id}\n"; |
| 48 | + # Fix the fi_img_timestamp value... |
| 49 | + $dbw->update( 'flaggedimages', |
| 50 | + array( 'fi_img_timestamp' => $dbw->timestamp( $time ) ), |
| 51 | + array( 'fi_rev_id' => $row->fi_rev_id, 'fi_name' => $row->fi_name ), |
| 52 | + __METHOD__ |
| 53 | + ); |
| 54 | + $changed++; |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + $db->commit(); |
| 59 | + $db->freeResult( $res ); |
| 60 | + $blockStart += $BATCH_SIZE; |
| 61 | + $blockEnd += $BATCH_SIZE; |
| 62 | + wfWaitForSlaves( 5 ); |
| 63 | + } |
| 64 | + echo "fi_img_timestamp column fixes complete ... {$count} rows [{$changed} changed]\n"; |
| 65 | +} |
Property changes on: trunk/extensions/FlaggedRevs/maintenance/fixBug28348.inc |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 66 | + native |