Avoid using User::setOption()

User::setOption() is deprecated and should be replaced with UserOptionsManager::setOption()

Bug: T277818
Change-Id: If867b4f97918db581d337a32b33cbca2315a71f6
This commit is contained in:
ZabeMath 2021-03-30 23:50:11 +02:00 committed by Alexander Vorwerk
parent 2c25d15489
commit e7fbb01aca
2 changed files with 26 additions and 10 deletions

View File

@ -320,7 +320,8 @@ class Hooks {
if ( !$isVectorEnabled && array_key_exists( Constants::PREF_KEY_SKIN_VERSION, $oldPreferences ) ) {
// The setting was cleared. However, this is likely because a different skin was chosen and
// the skin version preference was hidden.
$user->setOption(
MediaWikiServices::getInstance()->getUserOptionsManager()->setOption(
$user,
Constants::PREF_KEY_SKIN_VERSION,
$oldPreferences[ Constants::PREF_KEY_SKIN_VERSION ]
);
@ -337,7 +338,11 @@ class Hooks {
$default = self::getConfig( Constants::CONFIG_KEY_DEFAULT_SKIN_VERSION_FOR_NEW_ACCOUNTS );
// Permanently set the default preference. The user can later change this preference, however,
// self::onLocalUserCreated() will not be executed for that account again.
$user->setOption( Constants::PREF_KEY_SKIN_VERSION, $default );
MediaWikiServices::getInstance()->getUserOptionsManager()->setOption(
$user,
Constants::PREF_KEY_SKIN_VERSION,
$default
);
}
/**

View File

@ -4,6 +4,7 @@
* @ingroup skins
*/
use MediaWiki\User\UserOptionsManager;
use Vector\Constants;
use Vector\FeatureManagement\FeatureManager;
use Vector\Hooks;
@ -263,8 +264,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
];
$form = $this->createMock( HTMLForm::class );
$user = $this->createMock( User::class );
$user->expects( $this->never() )
$userOptionsManager = $this->createMock( UserOptionsManager::class );
$userOptionsManager->expects( $this->never() )
->method( 'setOption' );
$this->setService( 'UserOptionsManager', $userOptionsManager );
$result = true;
$oldPreferences = [];
@ -280,8 +283,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
];
$form = $this->createMock( HTMLForm::class );
$user = $this->createMock( User::class );
$user->expects( $this->never() )
$userOptionsManager = $this->createMock( UserOptionsManager::class );
$userOptionsManager->expects( $this->never() )
->method( 'setOption' );
$this->setService( 'UserOptionsManager', $userOptionsManager );
$result = true;
$oldPreferences = [];
@ -297,9 +302,11 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
];
$form = $this->createMock( HTMLForm::class );
$user = $this->createMock( User::class );
$user->expects( $this->once() )
$userOptionsManager = $this->createMock( UserOptionsManager::class );
$userOptionsManager->expects( $this->once() )
->method( 'setOption' )
->with( 'VectorSkinVersion', 'old' );
->with( $user, 'VectorSkinVersion', 'old' );
$this->setService( 'UserOptionsManager', $userOptionsManager );
$result = true;
$oldPreferences = [
'VectorSkinVersion' => 'old',
@ -318,9 +325,11 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
$this->setService( 'Vector.Config', $config );
$user = $this->createMock( User::class );
$user->expects( $this->once() )
$userOptionsManager = $this->createMock( UserOptionsManager::class );
$userOptionsManager->expects( $this->once() )
->method( 'setOption' )
->with( 'VectorSkinVersion', Constants::SKIN_VERSION_LEGACY );
->with( $user, 'VectorSkinVersion', Constants::SKIN_VERSION_LEGACY );
$this->setService( 'UserOptionsManager', $userOptionsManager );
$isAutoCreated = false;
Hooks::onLocalUserCreated( $user, $isAutoCreated );
}
@ -335,9 +344,11 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
$this->setService( 'Vector.Config', $config );
$user = $this->createMock( User::class );
$user->expects( $this->once() )
$userOptionsManager = $this->createMock( UserOptionsManager::class );
$userOptionsManager->expects( $this->once() )
->method( 'setOption' )
->with( 'VectorSkinVersion', Constants::SKIN_VERSION_LATEST );
->with( $user, 'VectorSkinVersion', Constants::SKIN_VERSION_LATEST );
$this->setService( 'UserOptionsManager', $userOptionsManager );
$isAutoCreated = false;
Hooks::onLocalUserCreated( $user, $isAutoCreated );
}