Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
PurgeExpiredWatchlistItems | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | /** |
3 | * Purge expired watchlist items, looping through 500 at a time. |
4 | */ |
5 | |
6 | use MediaWiki\MainConfigNames; |
7 | use MediaWiki\Maintenance\Maintenance; |
8 | |
9 | // @codeCoverageIgnoreStart |
10 | require_once __DIR__ . '/Maintenance.php'; |
11 | // @codeCoverageIgnoreEnd |
12 | |
13 | class PurgeExpiredWatchlistItems extends Maintenance { |
14 | |
15 | public function __construct() { |
16 | parent::__construct(); |
17 | $this->addDescription( 'Removes expired items from the watchlist and watchlist_expiry tables.' ); |
18 | $this->setBatchSize( 500 ); |
19 | } |
20 | |
21 | /** |
22 | * @inheritDoc |
23 | */ |
24 | public function execute() { |
25 | // Make sure watchlist expiring is enabled. |
26 | if ( !$this->getServiceContainer()->getMainConfig()->get( MainConfigNames::WatchlistExpiry ) ) { |
27 | $this->error( "Watchlist expiry is not enabled. Set `\$wgWatchlistExpiry = true;` to enable." ); |
28 | return false; |
29 | } |
30 | |
31 | // Loop through 500 entries at a time and delete them. |
32 | $watchedItemStore = $this->getServiceContainer()->getWatchedItemStore(); |
33 | $count = $watchedItemStore->countExpired(); |
34 | $this->output( $count . " expired watchlist entries found.\n" ); |
35 | if ( $count === 0 ) { |
36 | // None found to delete. |
37 | return true; |
38 | } |
39 | while ( $watchedItemStore->countExpired() > 0 ) { |
40 | $watchedItemStore->removeExpired( $this->getBatchSize(), true ); |
41 | } |
42 | |
43 | // Report success. |
44 | $this->output( "All expired entries purged.\n" ); |
45 | return true; |
46 | } |
47 | } |
48 | |
49 | // @codeCoverageIgnoreStart |
50 | $maintClass = PurgeExpiredWatchlistItems::class; |
51 | require_once RUN_MAINTENANCE_IF_MAIN; |
52 | // @codeCoverageIgnoreEnd |