Replace deprecated usage of wfGetDB

Bug: T330641
Change-Id: I863dc67e3196ea20c4f6145c5d3bb68b445b5195
This commit is contained in:
Sergio Gimeno 2024-02-13 19:55:34 +01:00
parent 15895ad922
commit 152db8a06f
7 changed files with 24 additions and 9 deletions

View file

@ -95,7 +95,9 @@ return [
},
'EchoRevisionLocalCache' => static function ( MediaWikiServices $services ): RevisionLocalCache {
return new RevisionLocalCache();
return new RevisionLocalCache(
$services->getConnectionProvider()
);
}
];

View file

@ -3,18 +3,29 @@
namespace MediaWiki\Extension\Notifications\Cache;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IConnectionProvider;
/**
* Cache class that maps revision id to RevisionStore object
* @xxx Like TitleLocalCache, this class shouldn't need to exist.
*/
class RevisionLocalCache extends LocalCache {
private IConnectionProvider $dbProvider;
/**
* @param IConnectionProvider $dbProvider
*/
public function __construct( IConnectionProvider $dbProvider ) {
parent::__construct();
$this->dbProvider = $dbProvider;
}
/**
* @inheritDoc
*/
protected function resolve( array $lookups ) {
$store = MediaWikiServices::getInstance()->getRevisionStore();
$dbr = wfGetDB( DB_REPLICA );
$dbr = $this->dbProvider->getReplicaDatabase();
$revQuery = $store->getQueryInfo( [ 'page', 'user' ] );
$res = $dbr->select(
$revQuery['tables'],

View file

@ -108,7 +108,7 @@ class DbFactory {
}
/**
* Wrapper function for wfGetDB, some extensions like MobileFrontend is
* Wrapper function for LBFactory::getExternalLB/getMainLB, some extensions like MobileFrontend is
* using this to issue sql queries against Echo database directly. This
* is totally not accepted and should be updated to use Echo database access
* objects

View file

@ -26,9 +26,9 @@ class UserLocator {
if ( !$title ) {
return [];
}
$provider = MediaWikiServices::getInstance()->getConnectionProvider();
$batchRowIt = new BatchRowIterator(
wfGetDB( DB_REPLICA, 'watchlist' ),
$provider->getReplicaDatabase( false, 'watchlist' ),
/* $table = */ 'watchlist',
/* $primaryKeys = */ [ 'wl_user' ],
$batchSize

View file

@ -40,7 +40,7 @@ class BackfillUnreadWikis extends Maintenance {
} else {
$userQuery = User::getQueryInfo();
$iterator = new BatchRowIterator(
wfGetDB( DB_REPLICA ), $userQuery['tables'], 'user_id', $this->getBatchSize()
$this->getReplicaDB(), $userQuery['tables'], 'user_id', $this->getBatchSize()
);
$iterator->setFetchColumns( $userQuery['fields'] );
$iterator->addJoinConditions( $userQuery['joins'] );

View file

@ -38,7 +38,6 @@ class RecomputeNotifCounts extends Maintenance {
public function execute() {
$dbFactory = DbFactory::newFromDefault();
$dbrEcho = $dbFactory->getEchoDb( DB_REPLICA );
$dbr = wfGetDB( DB_REPLICA );
$userIDs = $this->getOption( 'user-ids' );
$userIDs = $userIDs ? explode( ',', $userIDs ) : null;
@ -67,7 +66,9 @@ class RecomputeNotifCounts extends Maintenance {
$userIterator->setCaller( __METHOD__ );
} else {
$userQuery = User::getQueryInfo();
$userIterator = new BatchRowIterator( $dbr, $userQuery['tables'], 'user_id', $this->getBatchSize() );
$userIterator = new BatchRowIterator(
$this->getReplicaDB(), $userQuery['tables'], 'user_id', $this->getBatchSize()
);
$userIterator->setFetchColumns( $userQuery['fields'] );
$userIterator->addJoinConditions( $userQuery['joins'] );
$userIterator->setCaller( __METHOD__ );

View file

@ -27,7 +27,8 @@ class UserLocatorTest extends MediaWikiIntegrationTestCase {
'wl_title' => $key
];
}
wfGetDB( DB_PRIMARY )->insert( 'watchlist', $rows, __METHOD__ );
$this->getDb()->insert( 'watchlist', $rows, __METHOD__ );
$event = $this->createMock( Event::class );
$event->method( 'getTitle' )