Migrate usage of Database::select (and friends) to SelectQueryBuilder

Bug: T312466
Change-Id: I99d4402d796421221a1c6c56ef88b023cb495833
This commit is contained in:
Bartosz Dziewoński 2022-08-13 00:15:24 +02:00
parent 077d292434
commit 4c17819a76
3 changed files with 44 additions and 45 deletions

View file

@ -99,15 +99,15 @@ class SubscriptionStore {
$conditions[ 'sub_state' ] = $state;
}
return $db->select(
'discussiontools_subscription',
[
return $db->newSelectQueryBuilder()
->from( 'discussiontools_subscription' )
->fields( [
'sub_user', 'sub_item', 'sub_namespace', 'sub_title', 'sub_section', 'sub_state',
'sub_created', 'sub_notified'
],
$conditions,
__METHOD__
);
] )
->where( $conditions )
->caller( __METHOD__ )
->fetchResultSet();
}
/**

View file

@ -379,12 +379,12 @@ class ThreadItemStore {
$dbw->doAtomicSection( $method, function ( $dbw ) use ( $method, $rev, $threadItemSet, &$didInsert ) {
$itemRevisionsIds = [];
foreach ( $threadItemSet->getThreadItems() as $item ) {
$itemIdsId = $dbw->selectField(
'discussiontools_item_ids',
'itid_id',
[ 'itid_itemid' => $item->getId() ],
$method
);
$itemIdsId = $dbw->newSelectQueryBuilder()
->from( 'discussiontools_item_ids' )
->field( 'itid_id' )
->where( [ 'itid_itemid' => $item->getId() ] )
->caller( $method )
->fetchField();
if ( $itemIdsId === false ) {
$dbw->insert(
'discussiontools_item_ids',
@ -397,12 +397,12 @@ class ThreadItemStore {
$didInsert = true;
}
$itemsId = $dbw->selectField(
'discussiontools_items',
'it_id',
[ 'it_itemname' => $item->getName() ],
$method
);
$itemsId = $dbw->newSelectQueryBuilder()
->from( 'discussiontools_items' )
->field( 'it_id' )
->where( [ 'it_itemname' => $item->getName() ] )
->caller( $method )
->fetchField();
if ( $itemsId === false ) {
$dbw->insert(
'discussiontools_items',
@ -421,15 +421,15 @@ class ThreadItemStore {
$didInsert = true;
}
$itemRevisionsId = $dbw->selectField(
'discussiontools_item_revisions',
'itr_id',
[
$itemRevisionsId = $dbw->newSelectQueryBuilder()
->from( 'discussiontools_item_revisions' )
->field( 'itr_id' )
->where( [
'itr_itemid_id' => $itemIdsId,
'itr_revision_id' => $rev->getId(),
],
$method
);
] )
->caller( $method )
->fetchField();
if ( $itemRevisionsId === false ) {
$transcl = $item->getTranscludedFrom();
$dbw->insert(
@ -539,18 +539,18 @@ class ThreadItemStore {
// Delete rows that we don't care about, to save space (item revisions with the same ID and
// name as the one we just inserted, which are not the oldest or newest revision).
$oldestRevisionSql = $dbw->selectSQLText(
'discussiontools_item_pages',
'itp_oldest_revision_id',
[ 'itp_items_id' => $itemsId ],
$method
);
$newestRevisionSql = $dbw->selectSQLText(
'discussiontools_item_pages',
'itp_newest_revision_id',
[ 'itp_items_id' => $itemsId ],
$method
);
$oldestRevisionSql = $dbw->newSelectQueryBuilder()
->from( 'discussiontools_item_pages' )
->field( 'itp_oldest_revision_id' )
->where( [ 'itp_items_id' => $itemsId ] )
->caller( $method )
->getSQL();
$newestRevisionSql = $dbw->newSelectQueryBuilder()
->from( 'discussiontools_item_pages' )
->field( 'itp_newest_revision_id' )
->where( [ 'itp_items_id' => $itemsId ] )
->caller( $method )
->getSQL();
$dbw->delete(
'discussiontools_item_revisions',
[

View file

@ -67,13 +67,12 @@ class ThreadItemStoreTest extends IntegrationTestCase {
foreach ( $tables as $table ) {
$expected[$table] = static::getJson( "../$dir/$table.json", true );
$res = wfGetDb( DB_REPLICA )->select(
$table,
'*',
[],
__METHOD__,
[ 'ORDER BY' => 1 ]
);
$res = wfGetDb( DB_REPLICA )->newSelectQueryBuilder()
->from( $table )
->field( '*' )
->caller( __METHOD__ )
->orderBy( 1 )
->fetchResultSet();
foreach ( $res as $i => $row ) {
foreach ( $row as $key => $val ) {
$actual[$table][$i][$key] = $val;