MediaWiki 1.42.0
UserOptionsUpdateJob.php
Go to the documentation of this file.
1<?php
23
35 public function __construct( array $params ) {
36 parent::__construct( 'userOptionsUpdate', $params );
37 $this->removeDuplicates = true;
38 }
39
40 public function run() {
41 if ( !$this->params['options'] ) {
42 return true; // nothing to do
43 }
44
45 $user = User::newFromId( $this->params['userId'] );
46 $user->load( IDBAccessObject::READ_EXCLUSIVE );
47 if ( !$user->isNamed() ) {
48 return true;
49 }
50
51 $userOptionsManager = MediaWikiServices::getInstance()
52 ->getUserOptionsManager();
53 foreach ( $this->params['options'] as $name => $value ) {
54 $userOptionsManager->setOption( $user, $name, $value );
55 }
56
57 $user->saveSettings();
58
59 return true;
60 }
61}
array $params
The job parameters.
Describe and execute a background job.
Definition Job.php:40
Service locator for MediaWiki core services.
internal since 1.36
Definition User.php:93
Job that updates a user's preferences.
Interface for generic jobs only uses the parameters field and are JSON serializable.