Migrate various callers away from wfWikiId() to WikiMap
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Jul 2019 07:31:06 +0000 (00:31 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 12 Jul 2019 01:02:00 +0000 (01:02 +0000)
Change-Id: Idc2980c05873c428fb5ffa6ab89f723d33217a8e

includes/Storage/DerivedPageDataUpdater.php
maintenance/attachLatest.php
maintenance/cleanupInvalidDbKeys.php
maintenance/createAndPromote.php
maintenance/includes/BackupDumper.php
maintenance/includes/TextPassDumper.php
maintenance/initEditCount.php
maintenance/storage/recompressTracked.php
maintenance/syncFileBackend.php
maintenance/update.php
maintenance/updateSearchIndex.php

index b4d6f05..53c6d99 100644 (file)
@@ -343,14 +343,6 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
                }
        }
 
-       /**
-        * @return bool|string
-        */
-       private function getWikiId() {
-               // TODO: get from RevisionStore
-               return false;
-       }
-
        /**
         * Checks whether this DerivedPageDataUpdater can be re-used for running updates targeting
         * the given revision.
@@ -1574,7 +1566,10 @@ class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
 
                // TODO: In the wiring, register a listener for this on the new PageEventEmitter
                ResourceLoaderWikiModule::invalidateModuleCache(
-                       $title, $oldLegacyRevision, $legacyRevision, $this->getWikiId() ?: wfWikiID()
+                       $title,
+                       $oldLegacyRevision,
+                       $legacyRevision,
+                       $this->loadbalancerFactory->getLocalDomainID()
                );
 
                $this->doTransition( 'done' );
index 4da0901..e1d7fca 100644 (file)
@@ -56,6 +56,8 @@ class AttachLatest extends Maintenance {
                        __METHOD__ );
 
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $dbDomain = $lbFactory->getLocalDomainID();
+
                $n = 0;
                foreach ( $result as $row ) {
                        $pageId = intval( $row->page_id );
@@ -66,18 +68,19 @@ class AttachLatest extends Maintenance {
                                [ 'rev_page' => $pageId ],
                                __METHOD__ );
                        if ( !$latestTime ) {
-                               $this->output( wfWikiID() . " $pageId [[$name]] can't find latest rev time?!\n" );
+                               $this->output( "$dbDomain $pageId [[$name]] can't find latest rev time?!\n" );
                                continue;
                        }
 
                        $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
                        if ( is_null( $revision ) ) {
-                               $this->output( wfWikiID()
-                                       . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
+                               $this->output(
+                                       "$dbDomain $pageId [[$name]] latest time $latestTime, can't find revision id\n"
+                               );
                                continue;
                        }
                        $id = $revision->getId();
-                       $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, rev id $id\n" );
+                       $this->output( "$dbDomain $pageId [[$name]] latest time $latestTime, rev id $id\n" );
                        if ( $this->hasOption( 'fix' ) ) {
                                $page = WikiPage::factory( $title );
                                $page->updateRevisionOn( $dbw, $revision );
index eb45cfc..536e6db 100644 (file)
@@ -87,7 +87,8 @@ TEXT
 
                $this->outputStatus( 'Done!' );
                if ( $this->hasOption( 'fix' ) ) {
-                       $this->outputStatus( ' Cleaned up invalid DB keys on ' . wfWikiID() . "!\n" );
+                       $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
+                       $this->outputStatus( " Cleaned up invalid DB keys on $dbDomain!\n" );
                }
        }
 
index 93614e0..acc2817 100644 (file)
@@ -103,11 +103,12 @@ class CreateAndPromote extends Maintenance {
 
                        return;
                } elseif ( count( $promotions ) !== 0 ) {
+                       $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
                        $promoText = "User:{$username} into " . implode( ', ', $promotions ) . "...\n";
                        if ( $exists ) {
-                               $this->output( wfWikiID() . ": Promoting $promoText" );
+                               $this->output( "$dbDomain: Promoting $promoText" );
                        } else {
-                               $this->output( wfWikiID() . ": Creating and promoting $promoText" );
+                               $this->output( "$dbDomain: Creating and promoting $promoText" );
                        }
                }
 
index 0118c94..df3b4a1 100644 (file)
@@ -412,10 +412,12 @@ abstract class BackupDumper extends Maintenance {
                                $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), ETA %s [max %d]",
-                               $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate,
+                               $now, $dbDomain, $this->ID, $this->pageCount, $pageRate,
                                $pageRatePart, $this->revCount, $revRate, $revRatePart, $etats,
                                $this->maxCount
                        ) );
index b37fec1..c6738bc 100644 (file)
@@ -373,11 +373,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
                        ) );
index 938503c..f4cd2d3 100644 (file)
@@ -87,7 +87,7 @@ in the load balancer, usually indicating a replication environment.' );
                                $delta = microtime( true ) - $start;
                                $rate = ( $delta == 0.0 ) ? 0.0 : $migrated / $delta;
                                $this->output( sprintf( "%s %d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).\n",
-                                       wfWikiID(),
+                                       WikiMap::getCurrentWikiDbDomain()->getId(),
                                        $migrated,
                                        min( $max, $lastUser ) / $lastUser * 100.0,
                                        $delta,
index e6733a1..8a8f4d8 100644 (file)
@@ -148,7 +148,7 @@ class RecompressTracked {
                if ( $this->replicaId !== false ) {
                        $header .= "({$this->replicaId})";
                }
-               $header .= ' ' . wfWikiID();
+               $header .= ' ' . WikiMap::getCurrentWikiDbDomain()->getId();
                LegacyLogger::emit( sprintf( "%-50s %s\n", $header, $msg ), $file );
        }
 
index 76a5721..7d343b2 100644 (file)
@@ -49,7 +49,11 @@ class SyncFileBackend extends Maintenance {
                $src = FileBackendGroup::singleton()->get( $this->getOption( 'src' ) );
 
                $posDir = $this->getOption( 'posdir' );
-               $posFile = $posDir ? $posDir . '/' . wfWikiID() : false;
+               if ( $posDir != '' ) {
+                       $posFile = "$posDir/" . rawurlencode( $src->getDomainId() );
+               } else {
+                       $posFile = false;
+               }
 
                if ( $this->hasOption( 'posdump' ) ) {
                        // Just dump the current position into the specified position dir
index fe40536..bb9ba50 100755 (executable)
@@ -28,6 +28,7 @@
 require_once __DIR__ . '/Maintenance.php';
 
 use Wikimedia\Rdbms\IMaintainableDatabase;
+use Wikimedia\Rdbms\DatabaseSqlite;
 
 /**
  * Maintenance script to run database schema updates.
@@ -160,7 +161,8 @@ class UpdateMediaWiki extends Maintenance {
                        $this->fatalError( $text );
                }
 
-               $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
+               $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
+               $this->output( "Going to run database updates for $dbDomain\n" );
                if ( $db->getType() === 'sqlite' ) {
                        /** @var IMaintainableDatabase|DatabaseSqlite $db */
                        $this->output( "Using SQLite file: '{$db->getDbFilePath()}'\n" );
index af2d828..0216b28 100644 (file)
@@ -61,7 +61,8 @@ class UpdateSearchIndex extends Maintenance {
        }
 
        public function execute() {
-               $posFile = $this->getOption( 'p', 'searchUpdate.' . wfWikiID() . '.pos' );
+               $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
+               $posFile = $this->getOption( 'p', 'searchUpdate.' . rawurlencode( $dbDomain ) . '.pos' );
                $end = $this->getOption( 'e', wfTimestampNow() );
                if ( $this->hasOption( 's' ) ) {
                        $start = $this->getOption( 's' );