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