Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / maintenance / includes / TextPassDumper.php
index 03cad5c..00d7c90 100644 (file)
@@ -64,7 +64,8 @@ class TextPassDumper extends BackupDumper {
 
        protected $bufferSize = 524288; // In bytes. Maximum size to read from the stub in on go.
 
-       protected $php = "php";
+       /** @var array */
+       protected $php = [];
        protected $spawn = false;
 
        /**
@@ -73,14 +74,14 @@ class TextPassDumper extends BackupDumper {
        protected $spawnProc = false;
 
        /**
-        * @var bool|resource
+        * @var resource
         */
-       protected $spawnWrite = false;
+       protected $spawnWrite;
 
        /**
-        * @var bool|resource
+        * @var resource
         */
-       protected $spawnRead = false;
+       protected $spawnRead;
 
        /**
         * @var bool|resource
@@ -96,6 +97,7 @@ class TextPassDumper extends BackupDumper {
        protected $firstPageWritten = false;
        protected $lastPageWritten = false;
        protected $checkpointJustWritten = false;
+       /** @var string[] */
        protected $checkpointFiles = [];
 
        /**
@@ -133,7 +135,8 @@ TEXT
                $this->addOption( 'quiet', 'Don\'t dump status reports to stderr.' );
                $this->addOption( 'full', 'Dump all revisions of every page' );
                $this->addOption( 'current', 'Base ETA on number of pages in database instead of all revisions' );
-               $this->addOption( 'spawn', 'Spawn a subprocess for loading text records' );
+               $this->addOption( 'spawn', 'Spawn a subprocess for loading text records, optionally specify ' .
+                       'php[,mwscript] paths' );
                $this->addOption( 'buffersize', 'Buffer size in bytes to use for reading the stub. ' .
                        '(Default: 512KB, Minimum: 4KB)', false, true );
 
@@ -191,7 +194,7 @@ TEXT
                        $this->spawn = true;
                        $val = $this->getOption( 'spawn' );
                        if ( $val !== 1 ) {
-                               $this->php = $val;
+                               $this->php = explode( ',', $val, 2 );
                        }
                }
        }
@@ -206,6 +209,7 @@ TEXT
         * This function resets $this->lb and closes all connections on it.
         *
         * @throws MWException
+        * @suppress PhanTypeObjectUnsetDeclaredProperty
         */
        function rotateDb() {
                // Cleaning up old connections
@@ -239,7 +243,7 @@ TEXT
                }
 
                try {
-                       $this->db = $this->lb->getConnection( DB_REPLICA, 'dump' );
+                       $this->db = $this->lb->getMaintenanceConnectionRef( DB_REPLICA, 'dump' );
                } catch ( Exception $e ) {
                        throw new MWException( __METHOD__
                                . " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
@@ -280,7 +284,7 @@ TEXT
                $this->finalOptionCheck();
 
                // we only want this so we know how to close a stream :-P
-               $this->xmlwriterobj = new XmlDumpWriter();
+               $this->xmlwriterobj = new XmlDumpWriter( XmlDumpWriter::WRITE_CONTENT, $this->schemaVersion );
 
                $input = fopen( $this->input, "rt" );
                $this->readDump( $input );
@@ -300,6 +304,7 @@ TEXT
                        $param = $split[1];
                }
                $fileURIs = explode( ';', $param );
+               $newFileURIs = [];
                foreach ( $fileURIs as $URI ) {
                        switch ( $val ) {
                                case "file":
@@ -372,11 +377,13 @@ TEXT
                                $pageRatePart = '-';
                                $revRatePart = '-';
                        }
+
+                       $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
                        $this->progress( sprintf(
                                "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
                                        . "%d revs (%0.1f|%0.1f/sec all|curr), %0.1f%%|%0.1f%% "
                                        . "prefetched (all|curr), ETA %s [max %d]",
-                               $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate,
+                               $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
                                $pageRatePart, $this->revCount, $revRate, $revRatePart,
                                $fetchRate, $fetchRatePart, $etats, $this->maxCount
                        ) );
@@ -427,7 +434,7 @@ TEXT
 
        /**
         * @throws MWException Failure to parse XML input
-        * @param string $input
+        * @param resource $input
         * @return bool
         */
        function readDump( $input ) {
@@ -756,21 +763,27 @@ TEXT
        function openSpawn() {
                global $IP;
 
-               if ( file_exists( "$IP/../multiversion/MWScript.php" ) ) {
+               $wiki = WikiMap::getWikiIdFromDbDomain( WikiMap::getCurrentWikiDbDomain() );
+               if ( count( $this->php ) == 2 ) {
+                       $mwscriptpath = $this->php[1];
+               } else {
+                       $mwscriptpath = "$IP/../multiversion/MWScript.php";
+               }
+               if ( file_exists( $mwscriptpath ) ) {
                        $cmd = implode( " ",
                                array_map( [ Shell::class, 'escape' ],
                                        [
-                                               $this->php,
-                                               "$IP/../multiversion/MWScript.php",
+                                               $this->php[0],
+                                               $mwscriptpath,
                                                "fetchText.php",
-                                               '--wiki', wfWikiID() ] ) );
+                                               '--wiki', $wiki ] ) );
                } else {
                        $cmd = implode( " ",
                                array_map( [ Shell::class, 'escape' ],
                                        [
-                                               $this->php,
+                                               $this->php[0],
                                                "$IP/maintenance/fetchText.php",
-                                               '--wiki', wfWikiID() ] ) );
+                                               '--wiki', $wiki ] ) );
                }
                $spec = [
                        0 => [ "pipe", "r" ],
@@ -798,11 +811,11 @@ TEXT
                if ( $this->spawnRead ) {
                        fclose( $this->spawnRead );
                }
-               $this->spawnRead = false;
+               $this->spawnRead = null;
                if ( $this->spawnWrite ) {
                        fclose( $this->spawnWrite );
                }
-               $this->spawnWrite = false;
+               $this->spawnWrite = null;
                if ( $this->spawnErr ) {
                        fclose( $this->spawnErr );
                }