wiki.techinc.nl/maintenance/purgeExpiredWatchlistItems.php
Aryeh Gregor 79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00

48 lines
1.4 KiB
PHP

<?php
/**
* Purge expired watchlist items, looping through 500 at a time.
*/
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
require_once __DIR__ . '/Maintenance.php';
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 ( !MediaWikiServices::getInstance()->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 = MediaWikiServices::getInstance()->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;
}
}
$maintClass = PurgeExpiredWatchlistItems::class;
require_once RUN_MAINTENANCE_IF_MAIN;