MediaWiki REL1_40
purgeExpiredWatchlistItems.php
Go to the documentation of this file.
1<?php
8
9require_once __DIR__ . '/Maintenance.php';
10
12
13 public function __construct() {
14 parent::__construct();
15 $this->addDescription( 'Removes expired items from the watchlist and watchlist_expiry tables.' );
16 $this->setBatchSize( 500 );
17 }
18
22 public function execute() {
23 // Make sure watchlist expiring is enabled.
24 if ( !MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::WatchlistExpiry ) ) {
25 $this->error( "Watchlist expiry is not enabled. Set `\$wgWatchlistExpiry = true;` to enable." );
26 return false;
27 }
28
29 // Loop through 500 entries at a time and delete them.
30 $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
31 $count = $watchedItemStore->countExpired();
32 $this->output( $count . " expired watchlist entries found.\n" );
33 if ( $count === 0 ) {
34 // None found to delete.
35 return true;
36 }
37 while ( $watchedItemStore->countExpired() > 0 ) {
38 $watchedItemStore->removeExpired( $this->getBatchSize(), true );
39 }
40
41 // Report success.
42 $this->output( "All expired entries purged.\n" );
43 return true;
44 }
45}
46
47$maintClass = PurgeExpiredWatchlistItems::class;
48require_once RUN_MAINTENANCE_IF_MAIN;
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.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...