Migrate usage of Database::select to SelectQueryBuilder

We can simplify the code in Hooks.php to use revision.rev_actor
unconditionally, reverting 391c30da67
(the migration is done: T275246).

Bug: T312472
Change-Id: Iaab268409ec4ad0a8d3a835057321aa3c01a2cc7
This commit is contained in:
Bartosz Dziewoński 2022-08-12 23:58:14 +02:00
parent 54d0268847
commit 84433157aa
2 changed files with 27 additions and 39 deletions

View file

@ -10,7 +10,6 @@
namespace MediaWiki\Extension\VisualEditor;
use ActorMigration;
use Article;
use Config;
use DeferredUpdates;
@ -519,28 +518,21 @@ class Hooks {
!$userOptionsLookup->getOption( $user, 'visualeditor-hidetabdialog' ) &&
$userOptionsLookup->getOption( $user, 'visualeditor-tabs' ) === 'remember-last'
) {
// Check if the user has made any edits before the SET switch time
$dbr = wfGetDB( DB_REPLICA );
$revWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
foreach ( $revWhere['orconds'] as $key => $cond ) {
$tsField = $key === 'actor' ? 'revactor_timestamp' : 'rev_timestamp';
if (
$dbr->select(
[ 'revision' ] + $revWhere['tables'],
'1',
[
$cond,
$tsField . ' < ' . $dbr->addQuotes( $dbr->timestamp(
$config->get( 'VisualEditorSingleEditTabSwitchTime' )
) )
],
__METHOD__,
[ 'LIMIT' => 1 ],
$revWhere['joins']
)->numRows() === 1
) {
$links['views']['edit']['class'] .= ' visualeditor-showtabdialog';
break;
}
$revExists = $dbr->newSelectQueryBuilder()
->from( 'revision' )
->field( '1' )
->where( [
'rev_actor' => $user->getActorId(),
'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp(
$config->get( 'VisualEditorSingleEditTabSwitchTime' )
) )
] )
->caller( __METHOD__ )
->fetchField();
if ( $revExists ) {
$links['views']['edit']['class'] .= ' visualeditor-showtabdialog';
}
}

View file

@ -41,27 +41,23 @@ class AutodisableVisualEditorPref extends Maintenance {
$lastUserId = -1;
do {
$results = $dbr->select(
[ 'user', 'user_properties' ],
'user_id',
[
$results = $dbr->newSelectQueryBuilder()
->from( 'user' )
->leftJoin( 'user_properties', null, [
'user_id = up_user',
'up_property' => "visualeditor-enable"
] )
->field( 'user_id' )
->where( [
'user_id > ' . $dbr->addQuotes( $lastUserId ),
// only select users with no entry in user_properties
'up_value IS NULL',
'user_editcount > 0'
],
__METHOD__,
[
'LIMIT' => $this->mBatchSize,
'ORDER BY' => 'user_id'
],
[
'user_properties' => [
'LEFT OUTER JOIN',
'user_id = up_user and up_property = "visualeditor-enable"'
]
]
);
] )
->limit( $this->mBatchSize )
->orderBy( 'user_id' )
->caller( __METHOD__ )
->fetchResultSet();
foreach ( $results as $userRow ) {
$user = User::newFromId( $userRow->user_id );
$user->load( User::READ_LATEST );