Merge "Change the autonym of Javanese from "Basa Jawa" to "Jawa""
[lhc/web/wiklou.git] / maintenance / storage / trackBlobs.php
index a1e157d..385ae6a 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\SlotRecord;
 use Wikimedia\Rdbms\DBConnectionError;
 
 require __DIR__ . '/../commandLine.inc';
@@ -87,25 +88,6 @@ class TrackBlobs {
                        exit( 1 );
                }
 
-               // Scan the archive table for HistoryBlobStub objects or external flags (T24624)
-               $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";
        }
 
@@ -141,7 +123,7 @@ class TrackBlobs {
                return [
                        'cluster' => $m[1],
                        'id' => intval( $m[2] ),
-                       'hash' => isset( $m[3] ) ? $m[3] : null
+                       'hash' => $m[3] ?? null
                ];
        }
 
@@ -149,6 +131,8 @@ class TrackBlobs {
         *  Scan the revision table for rows stored in the specified clusters
         */
        function trackRevisions() {
+               global $wgMultiContentRevisionSchemaMigrationStage;
+
                $dbw = wfGetDB( DB_MASTER );
                $dbr = wfGetDB( DB_REPLICA );
 
@@ -160,20 +144,40 @@ class TrackBlobs {
 
                echo "Finding revisions...\n";
 
+               $fields = [ 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ];
+               $options = [
+                       'ORDER BY' => 'rev_id',
+                       'LIMIT' => $this->batchSize
+               ];
+               $conds = [
+                       $textClause,
+                       'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
+               ];
+               if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
+                       $tables = [ 'revision', 'text' ];
+                       $conds = array_merge( [
+                               'rev_text_id=old_id',
+                       ], $conds );
+               } else {
+                       $slotRoleStore = MediaWikiServices::getInstance()->getSlotRoleStore();
+                       $tables = [ 'revision', 'slots', 'content', 'text' ];
+                       $conds = array_merge( [
+                               'rev_id=slot_revision_id',
+                               'slot_role_id=' . $slotRoleStore->getId( SlotRecord::MAIN ),
+                               'content_id=slot_content_id',
+                               'SUBSTRING(content_address, 1, 3)=' . $dbr->addQuotes( 'tt:' ),
+                               'SUBSTRING(content_address, 4)=old_id',
+                       ], $conds );
+               }
+
                while ( true ) {
-                       $res = $dbr->select( [ 'revision', 'text' ],
-                               [ 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ],
-                               [
+                       $res = $dbr->select( $tables,
+                               $fields,
+                               array_merge( [
                                        'rev_id > ' . $dbr->addQuotes( $startId ),
-                                       'rev_text_id=old_id',
-                                       $textClause,
-                                       'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
-                               ],
+                               ], $conds ),
                                __METHOD__,
-                               [
-                                       'ORDER BY' => 'rev_id',
-                                       'LIMIT' => $this->batchSize
-                               ]
+                               $options
                        );
                        if ( !$res->numRows() ) {
                                break;