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