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