]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/storage/checkStorage.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / maintenance / storage / checkStorage.php
index 245c2fec8951fd7f0420ab4d1077c946d408679f..c288d682b280e9ef83a229fda6a03c8679bdf1a9 100644 (file)
@@ -9,7 +9,7 @@
 define( 'CONCAT_HEADER', 'O:27:"concatenatedgziphistoryblob"' );
 
 if ( !defined( 'MEDIAWIKI' ) ) {
-       require_once( dirname(__FILE__) . '/../commandLine.inc' );
+       require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
 
        $cs = new CheckStorage;
        $fix = isset( $options['fix'] );
@@ -22,7 +22,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 }
 
 
-//----------------------------------------------------------------------------------
+// ----------------------------------------------------------------------------------
 
 /**
  * @ingroup Maintenance ExternalStorage
@@ -37,7 +37,7 @@ class CheckStorage {
                'unfixable' => 'Unexpected errors with no automated fixing method',
                'fixed' => 'Errors already fixed',
                'fixable' => 'Errors which would already be fixed if --fix was specified',
-       );              
+       );
 
        function check( $fix = false, $xml = '' ) {
                $fname = 'checkStorage';
@@ -63,14 +63,14 @@ class CheckStorage {
 
                for ( $chunkStart = 1 ; $chunkStart < $maxRevId; $chunkStart += $chunkSize ) {
                        $chunkEnd = $chunkStart + $chunkSize - 1;
-                       //print "$chunkStart of $maxRevId\n";
+                       // print "$chunkStart of $maxRevId\n";
 
                        // Fetch revision rows
                        $this->oldIdMap = array();
-                       $dbr->ping();           
-                       $res = $dbr->select( 'revision', array( 'rev_id', 'rev_text_id' ), 
+                       $dbr->ping();
+                       $res = $dbr->select( 'revision', array( 'rev_id', 'rev_text_id' ),
                                array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), $fname );
-                       while ( $row = $dbr->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $this->oldIdMap[$row->rev_id] = $row->rev_text_id;
                        }
                        $dbr->freeResult( $res );
@@ -83,9 +83,9 @@ class CheckStorage {
                        $missingTextRows = array_flip( $this->oldIdMap );
                        $externalRevs = array();
                        $objectRevs = array();
-                       $res = $dbr->select( 'text', array( 'old_id', 'old_flags' ), 
+                       $res = $dbr->select( 'text', array( 'old_id', 'old_flags' ),
                                'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', $fname );
-                       while ( $row = $dbr->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $flags = $row->old_flags;
                                $id = $row->old_id;
 
@@ -116,7 +116,7 @@ class CheckStorage {
                                        if ( $fix ) {
                                                $this->error( 'fixed', "Warning: old_flags set to 0", $id );
                                                $dbw->ping();
-                                               $dbw->update( 'text', array( 'old_flags' => '' ), 
+                                               $dbw->update( 'text', array( 'old_flags' => '' ),
                                                        array( 'old_id' => $id ), $fname );
                                                echo "Fixed\n";
                                        } else {
@@ -137,15 +137,15 @@ class CheckStorage {
                        $externalConcatBlobs = array();
                        $externalNormalBlobs = array();
                        if ( count( $externalRevs ) ) {
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ), 
+                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
                                        array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), $fname );
-                               while ( $row = $dbr->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $urlParts = explode( '://', $row->old_text, 2 );
                                        if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) {
                                                $this->error( 'restore text', "Error: invalid URL \"{$row->old_text}\"", $row->old_id );
                                                continue;
                                        }
-                                       list( $proto, $path ) = $urlParts;
+                                       list( $proto, ) = $urlParts;
                                        if ( $proto != 'DB' ) {
                                                $this->error( 'restore text', "Error: invalid external protocol \"$proto\"", $row->old_id );
                                                continue;
@@ -164,7 +164,7 @@ class CheckStorage {
 
                        // Check external concat blobs for the right header
                        $this->checkExternalConcatBlobs( $externalConcatBlobs );
-                       
+
                        // Check external normal blobs for existence
                        if ( count( $externalNormalBlobs ) ) {
                                if ( is_null( $this->dbStore ) ) {
@@ -174,10 +174,10 @@ class CheckStorage {
                                        $blobIds = array_keys( $xBlobIds );
                                        $extDb =& $this->dbStore->getSlave( $cluster );
                                        $blobsTable = $this->dbStore->getTable( $extDb );
-                                       $res = $extDb->select( $blobsTable, 
-                                               array( 'blob_id' ), 
+                                       $res = $extDb->select( $blobsTable,
+                                               array( 'blob_id' ),
                                                array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
-                                       while ( $row = $extDb->fetchObject( $res ) ) {
+                                       foreach ( $res as $row ) {
                                                unset( $xBlobIds[$row->blob_id] );
                                        }
                                        $extDb->freeResult( $res );
@@ -194,9 +194,9 @@ class CheckStorage {
                        $curIds = array();
                        if ( count( $objectRevs ) ) {
                                $headerLength = 300;
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ), 
+                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
                                        array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), $fname );
-                               while ( $row = $dbr->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $oldId = $row->old_id;
                                        $matches = array();
                                        if ( !preg_match( '/^O:(\d+):"(\w+)"/', $row->header, $matches ) ) {
@@ -245,9 +245,9 @@ class CheckStorage {
                        $externalConcatBlobs = array();
                        if ( count( $concatBlobs ) ) {
                                $headerLength = 300;
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ), 
+                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
                                        array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), $fname );
-                               while ( $row = $dbr->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $flags = explode( ',', $row->old_flags );
                                        if ( in_array( 'external', $flags ) ) {
                                                // Concat blob is in external storage?
@@ -261,7 +261,7 @@ class CheckStorage {
                                                                if ( !isset( $externalConcatBlobs[$cluster][$id] ) ) {
                                                                        $externalConcatBlobs[$cluster][$id] = array();
                                                                }
-                                                               $externalConcatBlobs[$cluster][$id] = array_merge( 
+                                                               $externalConcatBlobs[$cluster][$id] = array_merge(
                                                                        $externalConcatBlobs[$cluster][$id], $concatBlobs[$row->old_id]
                                                                );
                                                        }
@@ -270,7 +270,7 @@ class CheckStorage {
                                                                $concatBlobs[$row->old_id] );
                                                }
                                        } elseif ( strcasecmp( substr( $row->header, 0, strlen( CONCAT_HEADER ) ), CONCAT_HEADER ) ) {
-                                               $this->error( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}", 
+                                               $this->error( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}",
                                                        $concatBlobs[$row->old_id] );
                                        } # else good
 
@@ -286,7 +286,7 @@ class CheckStorage {
                }
 
                print "\n\nErrors:\n";
-               foreach( $this->errors as $name => $errors ) {
+               foreach ( $this->errors as $name => $errors ) {
                        if ( count( $errors ) ) {
                                $description = $this->errorDescriptions[$name];
                                echo "$description: " . implode( ',', array_keys( $errors ) ) . "\n";
@@ -323,7 +323,7 @@ class CheckStorage {
                        foreach ( $ids as $id ) {
                                $revIds = array_merge( $revIds, array_keys( $this->oldIdMap, $id ) );
                        }
-                       print "$msg in text rows " . implode( ', ', $ids ) . 
+                       print "$msg in text rows " . implode( ', ', $ids ) .
                                ", revisions " . implode( ', ', $revIds ) . "\n";
                } else {
                        $id = $ids;
@@ -346,18 +346,18 @@ class CheckStorage {
                if ( is_null( $this->dbStore ) ) {
                        $this->dbStore = new ExternalStoreDB;
                }
-               
+
                foreach ( $externalConcatBlobs as $cluster => $oldIds ) {
                        $blobIds = array_keys( $oldIds );
                        $extDb =& $this->dbStore->getSlave( $cluster );
                        $blobsTable = $this->dbStore->getTable( $extDb );
                        $headerLength = strlen( CONCAT_HEADER );
-                       $res = $extDb->select( $blobsTable, 
-                               array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ), 
+                       $res = $extDb->select( $blobsTable,
+                               array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ),
                                array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
-                       while ( $row = $extDb->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                if ( strcasecmp( $row->header, CONCAT_HEADER ) ) {
-                                       $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL", 
+                                       $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
                                                $oldIds[$row->blob_id] );
                                }
                                unset( $oldIds[$row->blob_id] );
@@ -383,7 +383,7 @@ class CheckStorage {
 
                $revFileName = "$wgTmpDirectory/broken-revlist-$wgDBname";
                $filteredXmlFileName = "$wgTmpDirectory/filtered-$wgDBname.xml";
-               
+
                // Write revision list
                if ( !file_put_contents( $revFileName, implode( "\n", $revIds ) ) ) {
                        echo "Error writing revision list, can't restore text\n";
@@ -393,8 +393,8 @@ class CheckStorage {
                // Run mwdumper
                echo "Filtering XML dump...\n";
                $exitStatus = 0;
-               passthru( 'mwdumper ' . 
-                       wfEscapeShellArg( 
+               passthru( 'mwdumper ' .
+                       wfEscapeShellArg(
                                "--output=file:$filteredXmlFileName",
                                "--filter=revlist:$revFileName",
                                $xml
@@ -416,7 +416,7 @@ class CheckStorage {
                $dbw = wfGetDB( DB_MASTER );
                $dbr->ping();
                $dbw->ping();
-               
+
                $source = new ImportStreamSource( $file );
                $importer = new WikiImporter( $source );
                $importer->setRevisionCallback( array( &$this, 'importRevision' ) );
@@ -429,8 +429,8 @@ class CheckStorage {
                $id = $revision->getID();
                $text = $revision->getText();
                if ( $text === '' ) {
-                       // This is what happens if the revision was broken at the time the 
-                       // dump was made. Unfortunately, it also happens if the revision was 
+                       // This is what happens if the revision was broken at the time the
+                       // dump was made. Unfortunately, it also happens if the revision was
                        // legitimately blank, so there's no way to tell the difference. To
                        // be safe, we'll skip it and leave it broken
                        $id = $id ? $id : '';
@@ -457,7 +457,7 @@ class CheckStorage {
 
                // Update the text row
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->update( 'text', 
+               $dbw->update( 'text',
                        array( 'old_flags' => $flags, 'old_text' => $text ),
                        array( 'old_id' => $oldId ),
                        $fname, array( 'LIMIT' => 1 )