Debian Codegraph @

maintenance/purgeExpiredWatchlistItems.php

raw symbols SCIP
1 <?php
2 /**
3 * Purge expired watchlist items, looping through 500 at a time.
4 */
5
6 use MediaWiki\MainConfigNames;
7
8 // @codeCoverageIgnoreStart
9 require_once __DIR__ . '/Maintenance.php';
10 // @codeCoverageIgnoreEnd
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 * @inheritDoc
22 */
23 public function execute() {
24 // Make sure watchlist expiring is enabled.
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 // Loop through 500 entries at a time and delete them.
31 $watchedItemStore = $this->getServiceContainer()->getWatchedItemStore();
32 $count = $watchedItemStore->countExpired();
33 $this->output( $count . " expired watchlist entries found.\n" );
34 if ( $count === 0 ) {
35 // None found to delete.
36 return true;
37 }
38 while ( $watchedItemStore->countExpired() > 0 ) {
39 $watchedItemStore->removeExpired( $this->getBatchSize(), true );
40 }
41
42 // Report success.
43 $this->output( "All expired entries purged.\n" );
44 return true;
45 }
46 }
47
48 // @codeCoverageIgnoreStart
49 $maintClass = PurgeExpiredWatchlistItems::class;
50 require_once RUN_MAINTENANCE_IF_MAIN;
51 // @codeCoverageIgnoreEnd