Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
UserEditCountInitJob | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
run | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 |
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 | |
21 | use MediaWiki\MediaWikiServices; |
22 | |
23 | /** |
24 | * Job that initializes an user's edit count. |
25 | * |
26 | * This is used by UserEditTracker when a user's editcount isn't yet set. |
27 | * |
28 | * The following job parameters are required: |
29 | * - userId: the user ID |
30 | * - editCount: new edit count to set |
31 | * |
32 | * @internal For use by \MediaWiki\User\UserEditTracker |
33 | * @since 1.36 |
34 | */ |
35 | class UserEditCountInitJob extends Job implements GenericParameterJob { |
36 | |
37 | public function __construct( array $params ) { |
38 | parent::__construct( 'userEditCountInit', $params ); |
39 | $this->removeDuplicates = true; |
40 | } |
41 | |
42 | public function run() { |
43 | $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
44 | |
45 | $dbw->newUpdateQueryBuilder() |
46 | ->update( 'user' ) |
47 | ->set( [ 'user_editcount' => $this->params['editCount'] ] ) |
48 | ->where( [ |
49 | 'user_id' => $this->params['userId'], |
50 | $dbw->expr( 'user_editcount', '=', null )->or( 'user_editcount', '<', $this->params['editCount'] ) |
51 | ] ) |
52 | ->caller( __METHOD__ )->execute(); |
53 | |
54 | return true; |
55 | } |
56 | } |