MediaWiki master
purgeExpiredWatchlistItems.php
Go to the documentation of this file.
1<?php
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
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...