MediaWiki master
purgeExpiredWatchlistItems.php
Go to the documentation of this file.
1<?php
5
8
9// @codeCoverageIgnoreStart
10require_once __DIR__ . '/Maintenance.php';
11// @codeCoverageIgnoreEnd
12
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
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;
51require_once RUN_MAINTENANCE_IF_MAIN;
52// @codeCoverageIgnoreEnd
$maintClass
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config\get().
countExpired()
Get the number of watchlist items that expire before the current time.
removeExpired(int $limit, bool $deleteOrphans=false)
Remove some number of expired watchlist items.