Revert "merged master"
[lhc/web/wiklou.git] / maintenance / storage / resolveStubs.php
index c8d2f4c..08d0ee0 100644 (file)
@@ -1,12 +1,33 @@
 <?php
+/**
+ * Script to convert history stubs that point to an external row to direct
+ * external pointers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance ExternalStorage
+ */
 
 define( 'REPORTING_INTERVAL', 100 );
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        $optionsWithArgs = array( 'm' );
 
-       require_once( dirname(__FILE__) . '/../commandLine.inc' );
-       require_once( 'includes/ExternalStoreDB.php' );
+       require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
 
        resolveStubs();
 }
@@ -24,25 +45,20 @@ function resolveStubs() {
        $numBlocks = intval( $maxID / $blockSize ) + 1;
 
        for ( $b = 0; $b < $numBlocks; $b++ ) {
-               wfWaitForSlaves( 2 );
-               
+               wfWaitForSlaves();
+
                printf( "%5.2f%%\n", $b / $numBlocks * 100 );
-               $start = intval($maxID / $numBlocks) * $b + 1;
-               $end = intval($maxID / $numBlocks) * ($b + 1);
-               
+               $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 " .
-                       # Using a more restrictive flag set for now, until I do some more analysis -- TS
-                       #"AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
-                       
-                       "AND old_flags='object' " .
-                       "AND LOWER(LEFT(old_text,22)) = 'O:15:\"historyblobstub\"'", $fname );
-               while ( $row = $dbr->fetchObject( $res ) ) {
+                       "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";
 }
@@ -66,7 +82,7 @@ function resolveStub( $id, $stubText, $flags ) {
 
        # Get the (maybe) external row
        $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
-               array( 'old_id' => $stub->mOldId, "old_flags LIKE '%external%'" ),
+               array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
                $fname
        );
 
@@ -83,7 +99,7 @@ function resolveStub( $id, $stubText, $flags ) {
        }
 
        # Update the row
-       #print "oldid=$id\n";
+       # print "oldid=$id\n";
        $dbw->update( 'text',
                array( /* SET */
                        'old_flags' => $newFlags,