Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CentralAuthSuppressUserJob
0.00% covered (danger)
0.00%
0 / 18
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 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * @section LICENSE
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 */
21
22namespace MediaWiki\Extension\CentralAuth\User;
23
24use Job;
25use MediaWiki\Logger\LoggerFactory;
26
27/**
28 * A job to do crosswiki suppression in batches, rather than
29 * in one request. Size of batch is changed by changing
30 * $wgCentralAuthWikisPerSuppressJob.
31 */
32class CentralAuthSuppressUserJob extends Job {
33    /**
34     * @param array $params Job parameters
35     */
36    public function __construct( $params ) {
37        parent::__construct( 'crosswikiSuppressUser', $params );
38    }
39
40    /**
41     * Execute the job
42     *
43     * @return bool
44     */
45    public function run() {
46        $username = $this->params['username'];
47        $by = $this->params['by'];
48        $wikis = $this->params['wikis'];
49        $suppress = $this->params['suppress'];
50        $reason = $this->params['reason'];
51        $user = CentralAuthUser::getPrimaryInstanceByName( $username );
52        $logger = LoggerFactory::getInstance( 'CentralAuth' );
53        if ( !$user->exists() ) {
54            $logger->debug( "Requested to suppress non-existent user {$username} by {$by}" );
55        }
56
57        foreach ( $wikis as $wiki ) {
58            $user->doLocalSuppression( $suppress, $wiki, $by, $reason );
59            $logger->debug(
60                $suppress
61                    ? "Suppressed {$username} at {$wiki} by {$by} via job queue"
62                    : "Unsuppressed {$username} at {$wiki} by {$by} via job queue"
63            );
64        }
65        return true;
66    }
67}