3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\MediaWikiServices
;
22 use MediaWiki\User\User
;
23 use Wikimedia\Rdbms\IDBAccessObject
;
26 * Job that updates a user's preferences.
28 * The following job parameters are required:
29 * - userId: the user ID
30 * - options: a map of (option => value)
35 class UserOptionsUpdateJob
extends Job
implements GenericParameterJob
{
36 public function __construct( array $params ) {
37 parent
::__construct( 'userOptionsUpdate', $params );
38 $this->removeDuplicates
= true;
41 public function run() {
42 if ( !$this->params
['options'] ) {
43 return true; // nothing to do
46 $user = User
::newFromId( $this->params
['userId'] );
47 $user->load( IDBAccessObject
::READ_EXCLUSIVE
);
48 if ( !$user->isNamed() ) {
52 $userOptionsManager = MediaWikiServices
::getInstance()
53 ->getUserOptionsManager();
54 foreach ( $this->params
['options'] as $name => $value ) {
55 $userOptionsManager->setOption( $user, $name, $value );
58 $user->saveSettings();