Index: branches/wmf/1.17wmf1/extensions/FlaggedRevs/maintenance/fixImages.php |
— | — | @@ -0,0 +1,51 @@ |
| 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' ); |
| 11 | +require "$IP/maintenance/commandLine.inc"; |
| 12 | + |
| 13 | +function update_flaggedimages( $start = null ) { |
| 14 | + echo "Removing unreferenced flaggedimages columns\n"; |
| 15 | + |
| 16 | + $BATCH_SIZE = 1000; |
| 17 | + |
| 18 | + $db = wfGetDB( DB_MASTER ); |
| 19 | + |
| 20 | + if( $start === null ) { |
| 21 | + $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ ); |
| 22 | + } |
| 23 | + $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __FUNCTION__ ); |
| 24 | + if( is_null( $start ) || is_null( $end ) ){ |
| 25 | + echo "...flaggedimages table seems to be empty.\n"; |
| 26 | + return; |
| 27 | + } |
| 28 | + # Do remaining chunk |
| 29 | + $end += $BATCH_SIZE - 1; |
| 30 | + $blockStart = $start; |
| 31 | + $blockEnd = $start + $BATCH_SIZE - 1; |
| 32 | + $nulled = 0; |
| 33 | + while( $blockEnd <= $end ) { |
| 34 | + echo "...doing fi_rev_id from $blockStart to $blockEnd\n"; |
| 35 | + $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
| 36 | + $db->begin(); |
| 37 | + $db->update( 'flaggedimages', |
| 38 | + array( 'fi_img_timestamp' => '' ), |
| 39 | + array( $cond, "fi_img_timestamp LIKE 'DEFAULT%'" ), |
| 40 | + __FUNCTION__ ); |
| 41 | + if( $db->affectedRows() > 0 ) { |
| 42 | + $nulled += $db->affectedRows(); |
| 43 | + } |
| 44 | + $db->commit(); |
| 45 | + $blockStart += $BATCH_SIZE; |
| 46 | + $blockEnd += $BATCH_SIZE; |
| 47 | + wfWaitForSlaves( 5 ); |
| 48 | + } |
| 49 | + echo "flaggedimages columns update complete ... [{$nulled} fixed]\n"; |
| 50 | +} |
| 51 | + |
| 52 | +update_flaggedimages(); |