Replace last remaining wfGetDB() calls in core, except ResourceLoader
Bug: T330641 Change-Id: I6d30af6ff9f667e367d39befb80c2bb0bf5fb29e
This commit is contained in:
parent
51cc850272
commit
060a1b1668
15 changed files with 57 additions and 33 deletions
|
|
@ -235,7 +235,10 @@ class RecentChange implements Taggable {
|
|||
$fname = __METHOD__,
|
||||
$dbType = DB_REPLICA
|
||||
) {
|
||||
$db = wfGetDB( $dbType );
|
||||
$icp = MediaWikiServices::getInstance()->getConnectionProvider();
|
||||
|
||||
$db = ( $dbType === DB_REPLICA ) ? $icp->getReplicaDatabase() : $icp->getPrimaryDatabase();
|
||||
|
||||
$rcQuery = self::getQueryInfo();
|
||||
$row = $db->selectRow(
|
||||
$rcQuery['tables'], $rcQuery['fields'], $conds, $fname, [], $rcQuery['joins']
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Context\IContextSource;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\Status\Status;
|
||||
|
|
@ -69,7 +70,7 @@ abstract class ChangeTagsList extends RevisionListBase {
|
|||
* Reload the list data from the primary DB.
|
||||
*/
|
||||
public function reloadFromPrimary() {
|
||||
$dbw = wfGetDB( DB_PRIMARY );
|
||||
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
|
||||
$this->res = $this->doQuery( $dbw );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use MediaWiki\Html\Html;
|
|||
use MediaWiki\Language\RawMessage;
|
||||
use MediaWiki\Linker\LinkRenderer;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\ProperPageIdentity;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
|
|
@ -431,7 +432,7 @@ class IntroMessageBuilder {
|
|||
): void {
|
||||
# Give a notice if the user is editing a deleted/moved page...
|
||||
if ( !$page->exists() ) {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
||||
|
||||
$messages->addWithKey(
|
||||
'recreate-moveddeleted-warn',
|
||||
|
|
|
|||
|
|
@ -386,7 +386,7 @@ abstract class DatabaseInstaller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set up LBFactory so that wfGetDB() etc. works.
|
||||
* Set up LBFactory so that getPrimaryDatabase() etc. works.
|
||||
* We set up a special LBFactory instance which returns the current
|
||||
* installer connection.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ class DeleteLinksJob extends Job {
|
|||
$pageId = $this->params['pageId'];
|
||||
|
||||
// Serialize links updates by page ID so they see each others' changes
|
||||
$scopedLock = LinksUpdate::acquirePageLock( wfGetDB( DB_PRIMARY ), $pageId, 'job' );
|
||||
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
|
||||
$scopedLock = LinksUpdate::acquirePageLock( $dbw, $pageId, 'job' );
|
||||
if ( $scopedLock === null ) {
|
||||
$this->setLastError( 'LinksUpdate already running for this page, try again later.' );
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -572,7 +572,9 @@ class MessageCache implements LoggerAwareInterface {
|
|||
* @return array Loaded messages for storing in caches
|
||||
*/
|
||||
private function loadFromDB( $code, $mode = null ) {
|
||||
$dbr = wfGetDB( ( $mode === self::FOR_UPDATE ) ? DB_PRIMARY : DB_REPLICA );
|
||||
$icp = MediaWikiServices::getInstance()->getConnectionProvider();
|
||||
|
||||
$dbr = ( $mode === self::FOR_UPDATE ) ? $icp->getPrimaryDatabase() : $icp->getReplicaDatabase();
|
||||
|
||||
$cache = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -120,9 +120,15 @@ class RCDatabaseLogEntry extends DatabaseLogEntry {
|
|||
}
|
||||
|
||||
public function getComment() {
|
||||
return MediaWikiServices::getInstance()->getCommentStore()
|
||||
$services = MediaWikiServices::getInstance();
|
||||
|
||||
return $services->getCommentStore()
|
||||
// Legacy because the row may have used RecentChange::selectFields()
|
||||
->getCommentLegacy( wfGetDB( DB_REPLICA ), 'rc_comment', $this->row )->text;
|
||||
->getCommentLegacy(
|
||||
$services->getConnectionProvider()->getReplicaDatabase(),
|
||||
'rc_comment',
|
||||
$this->row
|
||||
)->text;
|
||||
}
|
||||
|
||||
public function getDeleted() {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
use MediaWiki\Context\ContextSource;
|
||||
use MediaWiki\Context\IContextSource;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
use MediaWiki\Title\Title;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -116,7 +117,9 @@ abstract class RevisionListBase extends ContextSource implements Iterator {
|
|||
*/
|
||||
public function reset() {
|
||||
if ( !$this->res ) {
|
||||
$this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
|
||||
$this->res = $this->doQuery(
|
||||
MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase()
|
||||
);
|
||||
} else {
|
||||
$this->res->rewind();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ class MWEval extends Maintenance {
|
|||
MediaWikiServices::resetGlobalInstance();
|
||||
}
|
||||
if ( $d > 1 ) {
|
||||
wfGetDB( DB_PRIMARY )->setFlag( DBO_DEBUG );
|
||||
wfGetDB( DB_REPLICA )->setFlag( DBO_DEBUG );
|
||||
$this->getServiceContainer()->getConnectionProvider()->getPrimaryDatabase()->setFlag( DBO_DEBUG );
|
||||
$this->getServiceContainer()->getConnectionProvider()->getReplicaDatabase()->setFlag( DBO_DEBUG );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,8 +167,10 @@ class RecompressTracked {
|
|||
* previous part of this batch process.
|
||||
*/
|
||||
private function syncDBs() {
|
||||
$dbw = wfGetDB( DB_PRIMARY );
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$icp = MediaWikiServices::getInstance()->getConnectionProvider();
|
||||
$dbw = $icp->getPrimaryDatabase();
|
||||
|
||||
$dbr = $icp->getReplicaDatabase();
|
||||
$pos = $dbw->getPrimaryPos();
|
||||
$dbr->primaryPosWait( $pos, 100_000 );
|
||||
}
|
||||
|
|
@ -204,7 +206,8 @@ class RecompressTracked {
|
|||
* @return bool
|
||||
*/
|
||||
private function checkTrackingTable() {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
// TOOD: Use ICP::getConnection() – but that returns an IDatabase not a Database and so no tableExists()
|
||||
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnectionRef( DB_REPLICA );
|
||||
if ( !$dbr->tableExists( 'blob_tracking', __METHOD__ ) ) {
|
||||
$this->critical( "Error: blob_tracking table does not exist" );
|
||||
|
||||
|
|
@ -328,7 +331,7 @@ class RecompressTracked {
|
|||
* Move all tracked pages to the new clusters
|
||||
*/
|
||||
private function doAllPages() {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
||||
$i = 0;
|
||||
$startId = 0;
|
||||
if ( $this->noCount ) {
|
||||
|
|
@ -391,7 +394,7 @@ class RecompressTracked {
|
|||
* Move all orphan text to the new clusters
|
||||
*/
|
||||
private function doAllOrphans() {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
||||
$startId = 0;
|
||||
$i = 0;
|
||||
if ( $this->noCount ) {
|
||||
|
|
@ -492,7 +495,7 @@ class RecompressTracked {
|
|||
} else {
|
||||
$titleText = '[deleted]';
|
||||
}
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
||||
|
||||
// Finish any incomplete transactions
|
||||
if ( !$this->copyOnly ) {
|
||||
|
|
@ -569,7 +572,8 @@ class RecompressTracked {
|
|||
$this->critical( "Internal error: can't call moveTextRow() in --copy-only mode" );
|
||||
exit( 1 );
|
||||
}
|
||||
$dbw = wfGetDB( DB_PRIMARY );
|
||||
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
|
||||
|
||||
$dbw->begin( __METHOD__ );
|
||||
$dbw->update( 'text',
|
||||
[ // set
|
||||
|
|
@ -600,7 +604,7 @@ class RecompressTracked {
|
|||
* @param array $conds
|
||||
*/
|
||||
private function finishIncompleteMoves( $conds ) {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
|
||||
$startId = 0;
|
||||
|
|
@ -659,7 +663,7 @@ class RecompressTracked {
|
|||
$trx = new CgzCopyTransaction( $this, $this->orphanBlobClass );
|
||||
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
$res = wfGetDB( DB_REPLICA )->newSelectQueryBuilder()
|
||||
$res = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase()->newSelectQueryBuilder()
|
||||
->select( [ 'old_id', 'old_text', 'old_flags' ] )
|
||||
->distinct()
|
||||
->from( 'text' )
|
||||
|
|
@ -766,7 +770,7 @@ class CgzCopyTransaction {
|
|||
*
|
||||
* We do a locking read to prevent closer-run race conditions.
|
||||
*/
|
||||
$dbw = wfGetDB( DB_PRIMARY );
|
||||
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
|
||||
$dbw->begin( __METHOD__ );
|
||||
$res = $dbw->newSelectQueryBuilder()
|
||||
->select( [ 'bt_text_id', 'bt_moved' ] )
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ The new option is NOT validated.' );
|
|||
$defaultOptions = $userOptionsLookup->getDefaultOptions();
|
||||
|
||||
// We list user by user_id from one of the replica DBs
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$dbr = $this->getServiceContainer()->getConnectionProvider()->getReplicaDatabase();
|
||||
|
||||
$result = $dbr->newSelectQueryBuilder()
|
||||
->select( [ 'user_id' ] )
|
||||
->from( 'user' )
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
require_once __DIR__ . '/../../maintenance/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Settings\SettingsBuilder;
|
||||
use MediaWiki\Specials\SpecialVersion;
|
||||
use MediaWiki\Tests\AnsiTermColorer;
|
||||
|
|
@ -118,8 +119,8 @@ class ParserTestsMaintenance extends Maintenance {
|
|||
// Cases of weird db corruption were encountered when running tests on earlyish
|
||||
// versions of SQLite
|
||||
if ( $wgDBtype == 'sqlite' ) {
|
||||
$db = wfGetDB( DB_PRIMARY );
|
||||
$version = $db->getServerVersion();
|
||||
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
|
||||
$version = $dbw->getServerVersion();
|
||||
if ( version_compare( $version, '3.6' ) < 0 ) {
|
||||
die( "Parser tests require SQLite version 3.6 or later, you have $version\n" );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2278,9 +2278,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
throw new LogicException( 'When testing database state, the test must use @group Database.' );
|
||||
}
|
||||
|
||||
$db = wfGetDB( DB_REPLICA );
|
||||
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
|
||||
|
||||
$res = $db->select(
|
||||
$res = $dbr->select(
|
||||
$table,
|
||||
$fields,
|
||||
$condition,
|
||||
|
|
@ -2288,7 +2288,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
|
|||
$options + [ 'ORDER BY' => $fields ],
|
||||
$join_conds
|
||||
);
|
||||
$this->assertNotFalse( $res, "query failed: " . $db->lastError() );
|
||||
$this->assertNotFalse( $res, "query failed: " . $dbr->lastError() );
|
||||
|
||||
$i = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -937,7 +937,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
|
|||
);
|
||||
|
||||
// Redefine the DBLoadBalancer service to verify Title doesn't attempt to resolve its ID
|
||||
// via wfGetDB()
|
||||
// via getPrimaryDatabase() etc.
|
||||
$localLoadBalancerMock = $this->createMock( ILoadBalancer::class );
|
||||
$localLoadBalancerMock->expects( $this->never() )
|
||||
->method( $this->anything() );
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Pager\RangeChronologicalPager;
|
||||
|
||||
/**
|
||||
|
|
@ -53,29 +54,29 @@ class RangeChronologicalPagerTest extends MediaWikiIntegrationTestCase {
|
|||
* Data provider in [ start, end, [ expected output has start condition, has end cond ] ] format
|
||||
*/
|
||||
public static function getDateRangeCondProvider() {
|
||||
$db = wfGetDB( DB_PRIMARY );
|
||||
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
|
||||
|
||||
return [
|
||||
[
|
||||
'20161201000000',
|
||||
'20161202235959',
|
||||
[
|
||||
$db->buildComparison( '>=', [ '' => $db->timestamp( '20161201000000' ) ] ),
|
||||
$db->buildComparison( '<', [ '' => $db->timestamp( '20161203000000' ) ] ),
|
||||
$dbw->buildComparison( '>=', [ '' => $dbw->timestamp( '20161201000000' ) ] ),
|
||||
$dbw->buildComparison( '<', [ '' => $dbw->timestamp( '20161203000000' ) ] ),
|
||||
],
|
||||
],
|
||||
[
|
||||
'',
|
||||
'20161202235959',
|
||||
[
|
||||
$db->buildComparison( '<', [ '' => $db->timestamp( '20161203000000' ) ] ),
|
||||
$dbw->buildComparison( '<', [ '' => $dbw->timestamp( '20161203000000' ) ] ),
|
||||
],
|
||||
],
|
||||
[
|
||||
'20161201000000',
|
||||
'',
|
||||
[
|
||||
$db->buildComparison( '>=', [ '' => $db->timestamp( '20161201000000' ) ] ),
|
||||
$dbw->buildComparison( '>=', [ '' => $dbw->timestamp( '20161201000000' ) ] ),
|
||||
],
|
||||
],
|
||||
[ '', '', [] ],
|
||||
|
|
|
|||
Loading…
Reference in a new issue