Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserOptionsUpdateJob
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21use MediaWiki\MediaWikiServices;
22use MediaWiki\User\User;
23
24/**
25 * Job that updates a user's preferences.
26 *
27 * The following job parameters are required:
28 *   - userId: the user ID
29 *   - options: a map of (option => value)
30 *
31 * @since 1.33
32 * @ingroup JobQueue
33 */
34class UserOptionsUpdateJob extends Job implements GenericParameterJob {
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}