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