Merge "build: Set private flag in package.json (for now)"
[lhc/web/wiklou.git] / maintenance / storage / checkStorage.php
index 9174d12..c0f6c7b 100644 (file)
@@ -39,6 +39,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 /**
  * Maintenance script to do various checks on external storage.
  *
+ * @fixme this should extend the base Maintenance class
  * @ingroup Maintenance ExternalStorage
  */
 class CheckStorage {
@@ -211,8 +212,12 @@ class CheckStorage {
                        $curIds = array();
                        if ( count( $objectRevs ) ) {
                                $headerLength = 300;
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
-                                       array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), __METHOD__ );
+                               $res = $dbr->select(
+                                       'text',
+                                       array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
+                                       array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ),
+                                       __METHOD__
+                               );
                                foreach ( $res as $row ) {
                                        $oldId = $row->old_id;
                                        $matches = array();
@@ -223,7 +228,11 @@ class CheckStorage {
 
                                        $className = strtolower( $matches[2] );
                                        if ( strlen( $className ) != $matches[1] ) {
-                                               $this->error( 'restore text', "Error: invalid object header, wrong class name length", $oldId );
+                                               $this->error(
+                                                       'restore text',
+                                                       "Error: invalid object header, wrong class name length",
+                                                       $oldId
+                                               );
                                                continue;
                                        }
 
@@ -262,8 +271,12 @@ class CheckStorage {
                        $externalConcatBlobs = array();
                        if ( count( $concatBlobs ) ) {
                                $headerLength = 300;
-                               $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
-                                       array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), __METHOD__ );
+                               $res = $dbr->select(
+                                       'text',
+                                       array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
+                                       array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ),
+                                       __METHOD__
+                               );
                                foreach ( $res as $row ) {
                                        $flags = explode( ',', $row->old_flags );
                                        if ( in_array( 'external', $flags ) ) {
@@ -271,7 +284,11 @@ class CheckStorage {
                                                if ( in_array( 'object', $flags ) ) {
                                                        $urlParts = explode( '/', $row->header );
                                                        if ( $urlParts[0] != 'DB:' ) {
-                                                               $this->error( 'unfixable', "Error: unrecognised external storage type \"{$urlParts[0]}", $row->old_id );
+                                                               $this->error(
+                                                                       'unfixable',
+                                                                       "Error: unrecognised external storage type \"{$urlParts[0]}",
+                                                                       $row->old_id
+                                                               );
                                                        } else {
                                                                $cluster = $urlParts[2];
                                                                $id = $urlParts[3];
@@ -283,12 +300,20 @@ class CheckStorage {
                                                                );
                                                        }
                                                } else {
-                                                       $this->error( 'unfixable', "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
+                                                       $this->error(
+                                                               'unfixable',
+                                                               "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
                                                                $concatBlobs[$row->old_id] );
                                                }
-                                       } elseif ( strcasecmp( substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ), self::CONCAT_HEADER ) ) {
-                                               $this->error( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}",
-                                                       $concatBlobs[$row->old_id] );
+                                       } elseif ( strcasecmp(
+                                               substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ),
+                                               self::CONCAT_HEADER
+                                       ) ) {
+                                               $this->error(
+                                                       'restore text',
+                                                       "Error: Incorrect object header for concat bulk row {$row->old_id}",
+                                                       $concatBlobs[$row->old_id]
+                                               );
                                        } # else good
 
                                        unset( $concatBlobs[$row->old_id] );
@@ -298,7 +323,6 @@ class CheckStorage {
 
                        // Check targets of unresolved stubs
                        $this->checkExternalConcatBlobs( $externalConcatBlobs );
-
                        // next chunk
                }
 
@@ -372,17 +396,23 @@ class CheckStorage {
                                array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), __METHOD__ );
                        foreach ( $res as $row ) {
                                if ( strcasecmp( $row->header, self::CONCAT_HEADER ) ) {
-                                       $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
-                                               $oldIds[$row->blob_id] );
+                                       $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] );
-
                        }
                        $extDb->freeResult( $res );
 
                        // Print errors for missing blobs rows
                        foreach ( $oldIds as $blobId => $oldIds2 ) {
-                               $this->error( 'restore text', "Error: missing target $cluster/$blobId for two-part ES URL", $oldIds2 );
+                               $this->error(
+                                       'restore text',
+                                       "Error: missing target $cluster/$blobId for two-part ES URL",
+                                       $oldIds2
+                               );
                        }
                }
        }
@@ -403,6 +433,7 @@ class CheckStorage {
                // Write revision list
                if ( !file_put_contents( $revFileName, implode( "\n", $revIds ) ) ) {
                        echo "Error writing revision list, can't restore text\n";
+
                        return;
                }
 
@@ -419,12 +450,14 @@ class CheckStorage {
 
                if ( $exitStatus ) {
                        echo "mwdumper died with exit status $exitStatus\n";
+
                        return;
                }
 
                $file = fopen( $filteredXmlFileName, 'r' );
                if ( !$file ) {
                        echo "Unable to open filtered XML file\n";
+
                        return;
                }
 
@@ -434,7 +467,10 @@ class CheckStorage {
                $dbw->ping();
 
                $source = new ImportStreamSource( $file );
-               $importer = new WikiImporter( $source );
+               $importer = new WikiImporter(
+                       $source,
+                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
+               );
                $importer->setRevisionCallback( array( &$this, 'importRevision' ) );
                $importer->doImport();
        }
@@ -446,6 +482,7 @@ class CheckStorage {
 
                if ( $content === null ) {
                        echo "Revision $id is broken, we have no content available\n";
+
                        return;
                }
 
@@ -457,12 +494,14 @@ class CheckStorage {
                        // be safe, we'll skip it and leave it broken
 
                        echo "Revision $id is blank in the dump, may have been broken before export\n";
+
                        return;
                }
 
                if ( !$id ) {
                        // No ID, can't import
                        echo "No id tag in revision, can't import\n";
+
                        return;
                }
 
@@ -471,6 +510,7 @@ class CheckStorage {
                $oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), __METHOD__ );
                if ( !$oldId ) {
                        echo "Missing revision row for rev_id $id\n";
+
                        return;
                }