Merge "Title: Add scripts for generating/updating phpCharToUpper.js"
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index b638b42..3476a32 100644 (file)
@@ -862,14 +862,7 @@ abstract class Maintenance {
                                        $this->setParam( $options, $option, $param );
                                } else {
                                        $bits = explode( '=', $option, 2 );
-                                       if ( count( $bits ) > 1 ) {
-                                               $option = $bits[0];
-                                               $param = $bits[1];
-                                       } else {
-                                               $param = 1;
-                                       }
-
-                                       $this->setParam( $options, $option, $param );
+                                       $this->setParam( $options, $bits[0], $bits[1] ?? 1 );
                                }
                        } elseif ( $arg == '-' ) {
                                # Lonely "-", often used to indicate stdin or stdout.
@@ -1252,11 +1245,8 @@ abstract class Maintenance {
                }
                if ( isset( $this->mOptions['wiki'] ) ) {
                        $bits = explode( '-', $this->mOptions['wiki'], 2 );
-                       if ( count( $bits ) == 1 ) {
-                               $bits[] = '';
-                       }
                        define( 'MW_DB', $bits[0] );
-                       define( 'MW_PREFIX', $bits[1] );
+                       define( 'MW_PREFIX', $bits[1] ?? '' );
                } elseif ( isset( $this->mOptions['server'] ) ) {
                        // Provide the option for site admins to detect and configure
                        // multiple wikis based on server names. This offers --server
@@ -1281,27 +1271,45 @@ abstract class Maintenance {
         * @author Rob Church <robchur@gmail.com>
         */
        public function purgeRedundantText( $delete = true ) {
+               global $wgMultiContentRevisionSchemaMigrationStage;
+
                # Data should come off the master, wrapped in a transaction
                $dbw = $this->getDB( DB_MASTER );
                $this->beginTransaction( $dbw, __METHOD__ );
 
-               # Get "active" text records from the revisions table
-               $cur = [];
-               $this->output( 'Searching for active text records in revisions table...' );
-               $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] );
-               foreach ( $res as $row ) {
-                       $cur[] = $row->rev_text_id;
-               }
-               $this->output( "done.\n" );
+               if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
+                       # Get "active" text records from the revisions table
+                       $cur = [];
+                       $this->output( 'Searching for active text records in revisions table...' );
+                       $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] );
+                       foreach ( $res as $row ) {
+                               $cur[] = $row->rev_text_id;
+                       }
+                       $this->output( "done.\n" );
 
-               # Get "active" text records from the archive table
-               $this->output( 'Searching for active text records in archive table...' );
-               $res = $dbw->select( 'archive', 'ar_text_id', [], __METHOD__, [ 'DISTINCT' ] );
-               foreach ( $res as $row ) {
-                       # old pre-MW 1.5 records can have null ar_text_id's.
-                       if ( $row->ar_text_id !== null ) {
-                               $cur[] = $row->ar_text_id;
+                       # Get "active" text records from the archive table
+                       $this->output( 'Searching for active text records in archive table...' );
+                       $res = $dbw->select( 'archive', 'ar_text_id', [], __METHOD__, [ 'DISTINCT' ] );
+                       foreach ( $res as $row ) {
+                               # old pre-MW 1.5 records can have null ar_text_id's.
+                               if ( $row->ar_text_id !== null ) {
+                                       $cur[] = $row->ar_text_id;
+                               }
                        }
+                       $this->output( "done.\n" );
+               } else {
+                       # Get "active" text records via the content table
+                       $cur = [];
+                       $this->output( 'Searching for active text records via contents table...' );
+                       $res = $dbw->select( 'content', 'content_address', [], __METHOD__, [ 'DISTINCT' ] );
+                       $blobStore = MediaWikiServices::getInstance()->getBlobStore();
+                       foreach ( $res as $row ) {
+                               $textId = $blobStore->getTextIdFromAddress( $row->content_address );
+                               if ( $textId ) {
+                                       $cur[] = $textId;
+                               }
+                       }
+                       $this->output( "done.\n" );
                }
                $this->output( "done.\n" );
 
@@ -1427,7 +1435,7 @@ abstract class Maintenance {
                        'user',
                        'page_restrictions'
                ];
-               $db->lockTables( $read, $write, __CLASS__ . '::' . __METHOD__ );
+               $db->lockTables( $read, $write, __CLASS__ . '-searchIndexLock' );
        }
 
        /**
@@ -1435,7 +1443,7 @@ abstract class Maintenance {
         * @param IMaintainableDatabase &$db
         */
        private function unlockSearchindex( $db ) {
-               $db->unlockTables( __CLASS__ . '::' . __METHOD__ );
+               $db->unlockTables( __CLASS__ . '-searchIndexLock' );
        }
 
        /**