]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/storage/resolveStubs.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / maintenance / storage / resolveStubs.php
index 2269e37fcedc0d4e5c2aee38634cfb640399ab5f..8ca8bb291b9cb3c6a350e82cfc3ac93b4e3ee3e2 100644 (file)
@@ -1,15 +1,31 @@
 <?php
 /**
+ * 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' );
+       $optionsWithArgs = [ 'm' ];
 
-       require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
+       require_once __DIR__ . '/../commandLine.inc';
 
        resolveStubs();
 }
@@ -21,19 +37,19 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 function resolveStubs() {
        $fname = 'resolveStubs';
 
-       $dbr = wfGetDB( DB_SLAVE );
+       $dbr = wfGetDB( DB_REPLICA );
        $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
        $blockSize = 10000;
        $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 );
 
-               $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
+               $res = $dbr->select( 'text', [ 'old_id', 'old_text', '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"\'',
@@ -47,6 +63,9 @@ function resolveStubs() {
 
 /**
  * Resolve a history stub
+ * @param int $id
+ * @param string $stubText
+ * @param string $flags
  */
 function resolveStub( $id, $stubText, $flags ) {
        $fname = 'resolveStub';
@@ -54,17 +73,23 @@ function resolveStub( $id, $stubText, $flags ) {
        $stub = unserialize( $stubText );
        $flags = explode( ',', $flags );
 
-       $dbr = wfGetDB( DB_SLAVE );
+       $dbr = wfGetDB( DB_REPLICA );
        $dbw = wfGetDB( DB_MASTER );
 
        if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
                print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
+
                return;
        }
 
        # 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() ) ),
+       $externalRow = $dbr->selectRow(
+               'text',
+               [ 'old_text' ],
+               [
+                       'old_id' => $stub->mOldId,
+                       'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() )
+               ],
                $fname
        );
 
@@ -83,13 +108,12 @@ function resolveStub( $id, $stubText, $flags ) {
        # Update the row
        # print "oldid=$id\n";
        $dbw->update( 'text',
-               array( /* SET */
+               [ /* SET */
                        'old_flags' => $newFlags,
                        'old_text' => $externalRow->old_text . '/' . $stub->mHash
-               ),
-               array( /* WHERE */
+               ],
+               [ /* WHERE */
                        'old_id' => $id
-               ), $fname
+               ], $fname
        );
 }
-