X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FresolveStubs.php;h=08d0ee04f6d751b224f8ed150a26981d70a171bc;hb=392af46809d831514f49618cdef1e1529d7fddf4;hp=840ae3f787584bf7b4e76dc6c3278d2c1b33d24c;hpb=5e4de9e7387a0839655257fa6a2236b79c61e0ba;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/resolveStubs.php b/maintenance/storage/resolveStubs.php index 840ae3f787..08d0ee04f6 100644 --- a/maintenance/storage/resolveStubs.php +++ b/maintenance/storage/resolveStubs.php @@ -1,12 +1,33 @@ selectField( 'text', 'MAX(old_id)', false, $fname ); - $stubs = array(); - $flagsArray = array(); + $blockSize = 10000; + $numBlocks = intval( $maxID / $blockSize ) + 1; - # Do it in 100 blocks - for ( $b = 0; $b < 100; $b++ ) { - print "$b%\r"; - $start = intval($maxID / 100) * $b + 1; - $end = intval($maxID / 100) * ($b + 1); + for ( $b = 0; $b < $numBlocks; $b++ ) { + wfWaitForSlaves(); + + printf( "%5.2f%%\n", $b / $numBlocks * 100 ); + $start = intval( $maxID / $numBlocks ) * $b + 1; + $end = intval( $maxID / $numBlocks ) * ( $b + 1 ); $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ), - "old_id>=$start AND old_id<=$end AND old_flags like '%object%' ". - "AND old_text LIKE 'O:15:\"historyblobstub\"%'", $fname ); - while ( $row = $dbr->fetchObject( $res ) ) { - $stubs[$row->old_id] = $row->old_text; - $flagsArray[$row->old_id] = $row->old_flags; + "old_id>=$start AND old_id<=$end " . + "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " . + 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'', + $fname ); + foreach ( $res as $row ) { + resolveStub( $row->old_id, $row->old_text, $row->old_flags ); } - $dbr->freeResult( $res ); } print "100%\n"; +} - print "\nConverting " . count( $stubs ) . " rows ...\n"; - - # Get master database, no transactions - $dbw =& wfGetDB( DB_MASTER ); - $dbw->clearFlag( DBO_TRX ); - $dbw->immediateCommit(); +/** + * Resolve a history stub + */ +function resolveStub( $id, $stubText, $flags ) { + $fname = 'resolveStub'; - $i = 0; - foreach( $stubs as $id => $stub ) { - if ( !(++$i % REPORTING_INTERVAL) ) { - print "$i\n"; - wfWaitForSlaves( 5 ); - } + $stub = unserialize( $stubText ); + $flags = explode( ',', $flags ); - $stub = unserialize( $stub ); - if ( get_class( $stub ) !== 'historyblobstub' ) { - print "Error, invalid stub object\n"; - return; - } + $dbr = wfGetDB( DB_SLAVE ); + $dbw = wfGetDB( DB_MASTER ); - # Get the (maybe) external row - $externalRow = $dbr->selectRow( 'text', array( 'old_text' ), - array( 'old_id' => $stub->mOldId, "old_flags LIKE '%external%'" ), - $fname - ); + if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) { + print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n"; + return; + } - if ( !$externalRow ) { - # Object wasn't external - continue; - } + # Get the (maybe) external row + $externalRow = $dbr->selectRow( 'text', array( 'old_text' ), + array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ), + $fname + ); - # Preserve the legacy encoding flag, but switch from object to external - $flags = explode( ',', $flagsArray[$id] ); - if ( in_array( 'utf-8', $flags ) ) { - $newFlags = 'external,utf-8'; - } else { - $newFlags = 'external'; - } + if ( !$externalRow ) { + # Object wasn't external + return; + } - # Update the row - $dbw->update( 'text', - array( /* SET */ - 'old_flags' => $newFlags, - 'old_text' => $externalRow->old_text . '/' . $stub->mHash - ), - array( /* WHERE */ - 'old_id' => $id - ), $fname - ); + # Preserve the legacy encoding flag, but switch from object to external + if ( in_array( 'utf-8', $flags ) ) { + $newFlags = 'external,utf-8'; + } else { + $newFlags = 'external'; } + + # Update the row + # print "oldid=$id\n"; + $dbw->update( 'text', + array( /* SET */ + 'old_flags' => $newFlags, + 'old_text' => $externalRow->old_text . '/' . $stub->mHash + ), + array( /* WHERE */ + 'old_id' => $id + ), $fname + ); } -?>