MediaWiki REL1_39
UserOptionsUpdateJob.php
Go to the documentation of this file.
1<?php
25
36 public function __construct( array $params ) {
37 parent::__construct( 'userOptionsUpdate', $params );
38 $this->removeDuplicates = true;
39 }
40
41 public function run() {
42 if ( !$this->params['options'] ) {
43 return true; // nothing to do
44 }
45
46 $user = User::newFromId( $this->params['userId'] );
47 $user->load( $user::READ_EXCLUSIVE );
48 if ( !$user->isRegistered() ) {
49 return true;
50 }
51
52 $userOptionsManager = MediaWikiServices::getInstance()
53 ->getUserOptionsManager();
54 foreach ( $this->params['options'] as $name => $value ) {
55 $userOptionsManager->setOption( $user, $name, $value );
56 }
57
58 $user->saveSettings();
59
60 return true;
61 }
62}
Class to both describe a background job and handle jobs.
Definition Job.php:39
Service locator for MediaWiki core services.
Job that updates a user's preferences.
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:639
Interface for generic jobs only uses the parameters field and are JSON serializable.