MediaWiki master
UserOptionsUpdateJob.php
Go to the documentation of this file.
1<?php
8
14
26 public function __construct( array $params ) {
27 parent::__construct( 'userOptionsUpdate', $params );
28 $this->removeDuplicates = true;
29 }
30
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
55class_alias( UserOptionsUpdateJob::class, 'UserOptionsUpdateJob' );
Describe and execute a background job.
Definition Job.php:28
array $params
Array of job parameters.
Definition Job.php:33
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Job that updates a user's preferences.
run()
Run the job.If this method returns false or completes exceptionally, the job runner will retry execut...
User class for the MediaWiki software.
Definition User.php:130
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:648
Interface for generic jobs only uses the parameters field and are JSON serializable.
Interface for database access objects.