Migrate callers of Database::insert() to InsertQueryBuilder

Bug: T351905
Change-Id: I298f3807b68d042b2fa92bca789dd6a2b271d4c8
This commit is contained in:
Taavi Väänänen 2023-11-23 20:30:01 +02:00
parent f2c34614de
commit 033f9192ee
No known key found for this signature in database
GPG key ID: EF242F709F912FBE
4 changed files with 31 additions and 28 deletions

View file

@ -103,11 +103,11 @@ class UpdateForMultipleDevicesSupport extends LoggedUpdateMaintenance {
}
if ( $toAdd ) {
$dbw->insert(
'oathauth_devices',
$toAdd,
__METHOD__
);
$dbw->newInsertQueryBuilder()
->insertInto( 'oathauth_devices' )
->rows( $toAdd )
->caller( __METHOD__ )
->execute();
}
$this->waitForReplication();

View file

@ -99,14 +99,17 @@ class OATHAuthModuleRegistry {
);
if ( $missing ) {
$rows = [];
$insert = $this->dbProvider
->getPrimaryDatabase( 'virtual-oathauth' )
->newInsertQueryBuilder()
->insertInto( 'oathauth_types' )
->caller( __METHOD__ );
foreach ( $missing as $name ) {
$rows[] = [ 'oat_name' => $name ];
$insert->row( [ 'oat_name' => $name ] );
}
$this->dbProvider
->getPrimaryDatabase( 'virtual-oathauth' )
->insert( 'oathauth_types', $rows, __METHOD__ );
$insert->execute();
$this->moduleIds = $this->getModuleIdsFromDatabase( true );
}

View file

@ -130,14 +130,6 @@ class OATHUserRepository implements LoggerAwareInterface {
$userId = $this->centralIdLookupFactory->getLookup()->centralIdFromLocalUser( $user->getUser() );
$moduleId = $this->moduleRegistry->getModuleId( $user->getModule()->getName() );
$rows = [];
foreach ( $user->getKeys() as $key ) {
$rows[] = [
'oad_user' => $userId,
'oad_type' => $moduleId,
'oad_data' => FormatJson::encode( $key->jsonSerialize() )
];
}
$dbw = $this->dbProvider->getPrimaryDatabase( 'virtual-oathauth' );
$dbw->startAtomic( __METHOD__ );
@ -148,11 +140,19 @@ class OATHUserRepository implements LoggerAwareInterface {
[ 'oad_user' => $userId ],
__METHOD__
);
$dbw->insert(
'oathauth_devices',
$rows,
__METHOD__
);
$insert = $dbw->newInsertQueryBuilder()
->insertInto( 'oathauth_devices' )
->caller( __METHOD__ );
foreach ( $user->getKeys() as $key ) {
$insert->row( [
'oad_user' => $userId,
'oad_type' => $moduleId,
'oad_data' => FormatJson::encode( $key->jsonSerialize() )
] );
}
$insert->execute();
$dbw->endAtomic( __METHOD__ );
$userName = $user->getUser()->getName();

View file

@ -33,11 +33,11 @@ class OATHAuthModuleRegistryTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry::getModuleIds
*/
public function testGetModuleIds() {
$this->db->insert(
'oathauth_types',
[ 'oat_name' => 'first' ],
__METHOD__
);
$this->db->newInsertQueryBuilder()
->insertInto( 'oathauth_types' )
->row( [ 'oat_name' => 'first' ] )
->caller( __METHOD__ )
->execute();
$database = $this->createMock( IConnectionProvider::class );
$database->method( 'getPrimaryDatabase' )->with( 'virtual-oathauth' )->willReturn( $this->db );