Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| UserOptionsUpdateJob | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| run | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\User\Options; |
| 8 | |
| 9 | use MediaWiki\JobQueue\GenericParameterJob; |
| 10 | use MediaWiki\JobQueue\Job; |
| 11 | use MediaWiki\MediaWikiServices; |
| 12 | use MediaWiki\User\User; |
| 13 | use Wikimedia\Rdbms\IDBAccessObject; |
| 14 | |
| 15 | /** |
| 16 | * Job that updates a user's preferences. |
| 17 | * |
| 18 | * The following job parameters are required: |
| 19 | * - userId: the user ID |
| 20 | * - options: a map of (option => value) |
| 21 | * |
| 22 | * @since 1.33 |
| 23 | * @ingroup User |
| 24 | */ |
| 25 | class UserOptionsUpdateJob extends Job implements GenericParameterJob { |
| 26 | public function __construct( array $params ) { |
| 27 | parent::__construct( 'userOptionsUpdate', $params ); |
| 28 | $this->removeDuplicates = true; |
| 29 | } |
| 30 | |
| 31 | /** @inheritDoc */ |
| 32 | public function run() { |
| 33 | if ( !$this->params['options'] ) { |
| 34 | // nothing to do |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | $user = User::newFromId( $this->params['userId'] ); |
| 39 | $user->load( IDBAccessObject::READ_EXCLUSIVE ); |
| 40 | if ( !$user->isNamed() ) { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | $userOptionsManager = MediaWikiServices::getInstance()->getUserOptionsManager(); |
| 45 | foreach ( $this->params['options'] as $name => $value ) { |
| 46 | $userOptionsManager->setOption( $user, $name, $value ); |
| 47 | } |
| 48 | |
| 49 | $user->saveSettings(); |
| 50 | |
| 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | class_alias( UserOptionsUpdateJob::class, 'UserOptionsUpdateJob' ); |