Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PurgeExpiredUserrights
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7use MediaWiki\Maintenance\Maintenance;
8
9// @codeCoverageIgnoreStart
10require_once __DIR__ . '/Maintenance.php';
11// @codeCoverageIgnoreEnd
12
13/**
14 * Remove expired userrights from user_groups table and move them to former_user_groups.
15 *
16 * By default, this does not need to be run. The UserGroupManager service naturally
17 * takes care of detecting expired rows when it is written to (e.g. from SpecialUserrights)
18 * and queues UserGroupExpiryJob to purge expired rows.
19 *
20 * Large wiki farms may experience stale rows if their users manage local groups
21 * via a central wiki. In that case, UserGroupExpiryJob may run rarely or never
22 * from local wikis, in which case this script can help to periodically clean up
23 * expired rows.
24 *
25 * @since 1.31
26 * @ingroup Maintenance
27 * @author Eddie Greiner-Petter <wikimedia.org at eddie-sh.de>
28 */
29class PurgeExpiredUserrights extends Maintenance {
30    public function __construct() {
31        parent::__construct();
32        $this->addDescription( 'Move expired userrights from user_groups to former_user_groups table.' );
33    }
34
35    public function execute() {
36        $this->output( "Purging expired user rights...\n" );
37        $res = $this->getServiceContainer()->getUserGroupManager()->purgeExpired();
38        if ( $res === false ) {
39            $this->output( "Purging failed.\n" );
40        } else {
41            $this->output( "$res rows purged.\n" );
42        }
43    }
44}
45
46// @codeCoverageIgnoreStart
47$maintClass = PurgeExpiredUserrights::class;
48require_once RUN_MAINTENANCE_IF_MAIN;
49// @codeCoverageIgnoreEnd