]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - maintenance/storage/trackBlobs.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / maintenance / storage / trackBlobs.php
index 63327d5389a205322ced3733dd1925057bf7810a..15aeec3ba0d65f3064ab5369d80ca433df8f0304 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-require( dirname( __FILE__ ) .'/../commandLine.inc' );
+require( dirname( __FILE__ ) . '/../commandLine.inc' );
 
 
 if ( count( $args ) < 1 ) {
@@ -35,6 +35,7 @@ class TrackBlobs {
        }
 
        function run() {
+               $this->checkIntegrity();
                $this->initTrackingTable();
                $this->trackRevisions();
                $this->trackOrphanText();
@@ -43,6 +44,47 @@ class TrackBlobs {
                }
        }
 
+       function checkIntegrity() {
+               echo "Doing integrity check...\n";
+               $dbr = wfGetDB( DB_SLAVE );
+
+               // Scan for HistoryBlobStub objects in the text table (bug 20757)
+
+               $exists = $dbr->selectField( 'text', 1,
+                       'old_flags LIKE \'%object%\' AND old_flags NOT LIKE \'%external%\' ' .
+                       'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
+                       __METHOD__
+               );
+
+               if ( $exists ) {
+                       echo "Integrity check failed: found HistoryBlobStub objects in your text table.\n" .
+                               "This script could destroy these objects if it continued. Run resolveStubs.php\n" .
+                               "to fix this.\n";
+                       exit( 1 );
+               }
+
+               // Scan the archive table for HistoryBlobStub objects or external flags (bug 22624)
+               $flags = $dbr->selectField( 'archive', 'ar_flags',
+                       'ar_flags LIKE \'%external%\' OR (' .
+                       'ar_flags LIKE \'%object%\' ' .
+                       'AND LOWER(CONVERT(LEFT(ar_text,22) USING latin1)) = \'o:15:"historyblobstub"\' )',
+                       __METHOD__
+               );
+
+               if ( strpos( $flags, 'external' ) !== false ) {
+                       echo "Integrity check failed: found external storage pointers in your archive table.\n" .
+                               "Run normaliseArchiveTable.php to fix this.\n";
+                       exit( 1 );
+               } elseif ( $flags ) {
+                       echo "Integrity check failed: found HistoryBlobStub objects in your archive table.\n" .
+                               "These objects are probably already broken, continuing would make them\n" .
+                               "unrecoverable. Run \"normaliseArchiveTable.php --fix-cgz-bug\" to fix this.\n";
+                       exit( 1 );
+               }
+
+               echo "Integrity check OK\n";
+       }
+
        function initTrackingTable() {
                $dbw = wfGetDB( DB_MASTER );
                if ( $dbw->tableExists( 'blob_tracking' ) ) {
@@ -170,9 +212,9 @@ class TrackBlobs {
 
                # Scan the text table for orphan text
                while ( true ) {
-                       $res = $dbr->select( array( 'text', 'blob_tracking' ), 
+                       $res = $dbr->select( array( 'text', 'blob_tracking' ),
                                array( 'old_id', 'old_flags', 'old_text' ),
-                               array( 
+                               array(
                                        'old_id>' . $dbr->addQuotes( $startId ),
                                        $textClause,
                                        'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
@@ -181,7 +223,7 @@ class TrackBlobs {
                                __METHOD__,
                                array(
                                        'ORDER BY' => 'old_id',
-                                       'LIMIT' => $this->batchSize 
+                                       'LIMIT' => $this->batchSize
                                ),
                                array( 'blob_tracking' => array( 'LEFT JOIN', 'bt_text_id=old_id' ) )
                        );
@@ -275,8 +317,8 @@ class TrackBlobs {
 
                        // Build a bitmap of actual blob rows
                        while ( true ) {
-                               $res = $extDB->select( $table, 
-                                       array( 'blob_id' ), 
+                               $res = $extDB->select( $table,
+                                       array( 'blob_id' ),
                                        array( 'blob_id > ' . $extDB->addQuotes( $startId ) ),
                                        __METHOD__,
                                        array( 'LIMIT' => $this->batchSize, 'ORDER BY' => 'blob_id' )
@@ -301,7 +343,7 @@ class TrackBlobs {
                        // Find actual blobs that weren't tracked by the previous passes
                        // This is a set-theoretic difference A \ B, or in bitwise terms, A & ~B
                        $orphans = gmp_and( $actualBlobs, gmp_com( $this->trackedBlobs[$cluster] ) );
-                       
+
                        // Traverse the orphan list
                        $insertBatch = array();
                        $id = 0;