From: Umherirrender Date: Sun, 25 Feb 2018 09:05:07 +0000 (+0100) Subject: Replace wfGetLBFactory X-Git-Tag: 1.31.0-rc.0~410^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/supprimer.php?a=commitdiff_plain;h=554f9c857c5bde9adf143bed2cf661640fdb7992;p=lhc%2Fweb%2Fwiklou.git Replace wfGetLBFactory @deprecated since 1.27 Change-Id: I11a7253cebe525948a55cebee183e6de128fdc39 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5b809e4994..9cebf7e50f 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3052,7 +3052,8 @@ function wfWaitForSlaves( } try { - wfGetLBFactory()->waitForReplication( [ + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory->waitForReplication( [ 'wiki' => $wiki, 'cluster' => $cluster, 'timeout' => $timeout, diff --git a/includes/externalstore/ExternalStoreDB.php b/includes/externalstore/ExternalStoreDB.php index b43bd210aa..ad0c217150 100644 --- a/includes/externalstore/ExternalStoreDB.php +++ b/includes/externalstore/ExternalStoreDB.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\LoadBalancer; use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\DBConnRef; @@ -114,7 +115,8 @@ class ExternalStoreDB extends ExternalStoreMedium { * @return LoadBalancer */ private function getLoadBalancer( $cluster ) { - return wfGetLBFactory()->getExternalLB( $cluster ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + return $lbFactory->getExternalLB( $cluster ); } /** diff --git a/includes/user/BotPassword.php b/includes/user/BotPassword.php index b898d8a5da..f102d49c3b 100644 --- a/includes/user/BotPassword.php +++ b/includes/user/BotPassword.php @@ -18,6 +18,7 @@ * http://www.gnu.org/copyleft/gpl.html */ +use MediaWiki\MediaWikiServices; use MediaWiki\Session\BotPasswordSessionProvider; use Wikimedia\Rdbms\IMaintainableDatabase; @@ -74,9 +75,10 @@ class BotPassword implements IDBAccessObject { public static function getDB( $db ) { global $wgBotPasswordsCluster, $wgBotPasswordsDatabase; + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $lb = $wgBotPasswordsCluster - ? wfGetLBFactory()->getExternalLB( $wgBotPasswordsCluster ) - : wfGetLB( $wgBotPasswordsDatabase ); + ? $lbFactory->getExternalLB( $wgBotPasswordsCluster ) + : $lbFactory->getMainLB( $wgBotPasswordsDatabase ); return $lb->getConnectionRef( $db, [], $wgBotPasswordsDatabase ); } diff --git a/maintenance/backup.inc b/maintenance/backup.inc index ffc75c6bbf..0fdd417fc3 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -26,6 +26,7 @@ require_once __DIR__ . '/Maintenance.php'; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\LoadBalancer; use Wikimedia\Rdbms\IDatabase; @@ -323,7 +324,8 @@ class BackupDumper extends Maintenance { return $this->forcedDb; } - $this->lb = wfGetLBFactory()->newMainLB(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $this->lb = $lbFactory->newMainLB(); $db = $this->lb->getConnection( DB_REPLICA, 'dump' ); // Discourage the server from disconnecting us if it takes a long time diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 57e09a71ae..59a6b5178c 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -28,6 +28,7 @@ require_once __DIR__ . '/backup.inc'; require_once __DIR__ . '/7zip.inc'; require_once __DIR__ . '/../includes/export/WikiExporter.php'; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IMaintainableDatabase; /** @@ -218,7 +219,8 @@ TEXT // individually retrying at different layers of code. try { - $this->lb = wfGetLBFactory()->newMainLB(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $this->lb = $lbFactory->newMainLB(); } catch ( Exception $e ) { throw new MWException( __METHOD__ . " rotating DB failed to obtain new load balancer (" . $e->getMessage() . ")" ); diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php index 6c7dbff953..a259484f7f 100644 --- a/maintenance/rebuildrecentchanges.php +++ b/maintenance/rebuildrecentchanges.php @@ -24,7 +24,9 @@ */ require_once __DIR__ . '/Maintenance.php'; + use MediaWiki\MediaWikiServices; +use Wikimedia\Rdbms\ILBFactory; /** * Maintenance script that rebuilds recent changes from scratch. @@ -64,11 +66,12 @@ class RebuildRecentchanges extends Maintenance { $this->fatalError( "Both 'from' and 'to' must be given, or neither" ); } - $this->rebuildRecentChangesTablePass1(); - $this->rebuildRecentChangesTablePass2(); - $this->rebuildRecentChangesTablePass3(); - $this->rebuildRecentChangesTablePass4(); - $this->rebuildRecentChangesTablePass5(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $this->rebuildRecentChangesTablePass1( $lbFactory ); + $this->rebuildRecentChangesTablePass2( $lbFactory ); + $this->rebuildRecentChangesTablePass3( $lbFactory ); + $this->rebuildRecentChangesTablePass4( $lbFactory ); + $this->rebuildRecentChangesTablePass5( $lbFactory ); if ( !( $this->hasOption( 'from' ) && $this->hasOption( 'to' ) ) ) { $this->purgeFeeds(); } @@ -78,7 +81,7 @@ class RebuildRecentchanges extends Maintenance { /** * Rebuild pass 1: Insert `recentchanges` entries for page revisions. */ - private function rebuildRecentChangesTablePass1() { + private function rebuildRecentChangesTablePass1( ILBFactory $lbFactory ) { $dbw = $this->getDB( DB_MASTER ); $commentStore = CommentStore::getStore(); @@ -110,7 +113,7 @@ class RebuildRecentchanges extends Maintenance { ); foreach ( array_chunk( $rcids, $this->getBatchSize() ) as $rcidBatch ) { $dbw->delete( 'recentchanges', [ 'rc_id' => $rcidBatch ], __METHOD__ ); - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } $this->output( "Loading from page and revision tables...\n" ); @@ -166,7 +169,7 @@ class RebuildRecentchanges extends Maintenance { __METHOD__ ); if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) { - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } } } @@ -175,7 +178,7 @@ class RebuildRecentchanges extends Maintenance { * Rebuild pass 2: Enhance entries for page revisions with references to the previous revision * (rc_last_oldid, rc_new etc.) and size differences (rc_old_len, rc_new_len). */ - private function rebuildRecentChangesTablePass2() { + private function rebuildRecentChangesTablePass2( ILBFactory $lbFactory ) { $dbw = $this->getDB( DB_MASTER ); $this->output( "Updating links and size differences...\n" ); @@ -256,7 +259,7 @@ class RebuildRecentchanges extends Maintenance { $lastSize = $size; if ( ( ++$updated % $this->getBatchSize() ) == 0 ) { - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } } } @@ -265,7 +268,7 @@ class RebuildRecentchanges extends Maintenance { /** * Rebuild pass 3: Insert `recentchanges` entries for action logs. */ - private function rebuildRecentChangesTablePass3() { + private function rebuildRecentChangesTablePass3( ILBFactory $lbFactory ) { global $wgLogTypes, $wgLogRestrictions; $dbw = $this->getDB( DB_MASTER ); @@ -338,7 +341,7 @@ class RebuildRecentchanges extends Maintenance { ); if ( ( ++$inserted % $this->getBatchSize() ) == 0 ) { - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } } } @@ -346,7 +349,7 @@ class RebuildRecentchanges extends Maintenance { /** * Rebuild pass 4: Mark bot and autopatrolled entries. */ - private function rebuildRecentChangesTablePass4() { + private function rebuildRecentChangesTablePass4( ILBFactory $lbFactory ) { global $wgUseRCPatrol, $wgMiserMode; $dbw = $this->getDB( DB_MASTER ); @@ -405,7 +408,7 @@ class RebuildRecentchanges extends Maintenance { [ 'rc_id' => $rcidBatch ], __METHOD__ ); - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } } } @@ -444,7 +447,7 @@ class RebuildRecentchanges extends Maintenance { ], __METHOD__ ); - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } } } @@ -454,7 +457,7 @@ class RebuildRecentchanges extends Maintenance { * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry * for a single action (upload only, at the moment, but potentially also move, protect, ...). */ - private function rebuildRecentChangesTablePass5() { + private function rebuildRecentChangesTablePass5( ILBFactory $lbFactory ) { $dbw = wfGetDB( DB_MASTER ); $this->output( "Removing duplicate revision and logging entries...\n" ); @@ -493,7 +496,7 @@ class RebuildRecentchanges extends Maintenance { ); if ( ( ++$updates % $this->getBatchSize() ) == 0 ) { - wfGetLBFactory()->waitForReplication(); + $lbFactory->waitForReplication(); } } } diff --git a/maintenance/sql.php b/maintenance/sql.php index 2c8bdb67ce..e8b7448104 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -24,6 +24,7 @@ require_once __DIR__ . '/Maintenance.php'; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\ResultWrapper; use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\DBQueryError; @@ -54,10 +55,11 @@ class MwSql extends Maintenance { // We wan't to allow "" for the wikidb, meaning don't call select_db() $wiki = $this->hasOption( 'wikidb' ) ? $this->getOption( 'wikidb' ) : false; // Get the appropriate load balancer (for this wiki) + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); if ( $this->hasOption( 'cluster' ) ) { - $lb = wfGetLBFactory()->getExternalLB( $this->getOption( 'cluster' ) ); + $lb = $lbFactory->getExternalLB( $this->getOption( 'cluster' ) ); } else { - $lb = wfGetLB( $wiki ); + $lb = $lbFactory->getMainLB( $wiki ); } // Figure out which server to use $replicaDB = $this->getOption( 'replicadb', $this->getOption( 'slave', '' ) ); diff --git a/maintenance/storage/orphanStats.php b/maintenance/storage/orphanStats.php index 4feb95e05c..9e3138e1b1 100644 --- a/maintenance/storage/orphanStats.php +++ b/maintenance/storage/orphanStats.php @@ -23,6 +23,8 @@ require_once __DIR__ . '/../Maintenance.php'; +use MediaWiki\MediaWikiServices; + /** * Maintenance script that shows some statistics on the blob_orphans table, * created with trackBlobs.php. @@ -37,7 +39,8 @@ class OrphanStats extends Maintenance { } protected function &getDB( $cluster, $groups = [], $wiki = false ) { - $lb = wfGetLBFactory()->getExternalLB( $cluster ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lb = $lbFactory->getExternalLB( $cluster ); return $lb->getConnection( DB_REPLICA ); } diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 54a9102758..49b8e0a69d 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -643,7 +643,8 @@ class RecompressTracked { * @return Database */ function getExtDB( $cluster ) { - $lb = wfGetLBFactory()->getExternalLB( $cluster ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lb = $lbFactory->getExternalLB( $cluster ); return $lb->getConnection( DB_MASTER ); } diff --git a/maintenance/storage/trackBlobs.php b/maintenance/storage/trackBlobs.php index b4514ecbdf..7fe91bcfcb 100644 --- a/maintenance/storage/trackBlobs.php +++ b/maintenance/storage/trackBlobs.php @@ -22,6 +22,7 @@ * @see wfWaitForSlaves() */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\DBConnectionError; require __DIR__ . '/../commandLine.inc'; @@ -317,7 +318,8 @@ class TrackBlobs { foreach ( $this->clusters as $cluster ) { echo "Searching for orphan blobs in $cluster...\n"; - $lb = wfGetLBFactory()->getExternalLB( $cluster ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lb = $lbFactory->getExternalLB( $cluster ); try { $extDB = $lb->getConnection( DB_REPLICA ); } catch ( DBConnectionError $e ) { diff --git a/tests/parser/parserTests.php b/tests/parser/parserTests.php index 2735f93e0d..6a423d5cb3 100644 --- a/tests/parser/parserTests.php +++ b/tests/parser/parserTests.php @@ -30,6 +30,8 @@ define( 'MW_PARSER_TEST', true ); require __DIR__ . '/../../maintenance/Maintenance.php'; +use MediaWiki\MediaWikiServices; + class ParserTestsMaintenance extends Maintenance { function __construct() { parent::__construct(); @@ -145,7 +147,8 @@ class ParserTestsMaintenance extends Maintenance { $recorderLB = false; if ( $record || $compare ) { - $recorderLB = wfGetLBFactory()->newMainLB(); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $recorderLB = $lbFactory->newMainLB(); // This connection will have the wiki's table prefix, not parsertest_ $recorderDB = $recorderLB->getConnection( DB_MASTER ); diff --git a/tests/phpunit/includes/deferred/DeferredUpdatesTest.php b/tests/phpunit/includes/deferred/DeferredUpdatesTest.php index 8332d2ccc2..6b41707333 100644 --- a/tests/phpunit/includes/deferred/DeferredUpdatesTest.php +++ b/tests/phpunit/includes/deferred/DeferredUpdatesTest.php @@ -207,7 +207,8 @@ class DeferredUpdatesTest extends MediaWikiTestCase { ]; // clear anything - wfGetLBFactory()->commitMasterChanges( __METHOD__ ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory->commitMasterChanges( __METHOD__ ); DeferredUpdates::addCallableUpdate( function () use ( $updates ) { @@ -271,7 +272,8 @@ class DeferredUpdatesTest extends MediaWikiTestCase { $x = false; $y = false; // clear anything - wfGetLBFactory()->commitMasterChanges( __METHOD__ ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbFactory->commitMasterChanges( __METHOD__ ); DeferredUpdates::addCallableUpdate( function () use ( &$x, &$y ) {