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