MediaWiki  master
purgeExpiredWatchlistItems.php
Go to the documentation of this file.
1 <?php
7 
8 require_once __DIR__ . '/Maintenance.php';
9 
11 
12  public function __construct() {
13  parent::__construct();
14  $this->addDescription( 'Removes expired items from the watchlist and watchlist_expiry tables.' );
15  $this->setBatchSize( 500 );
16  }
17 
21  public function execute() {
22  // Make sure watchlist expiring is enabled.
23  if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'WatchlistExpiry' ) ) {
24  $this->error( "Watchlist expiry is not enabled. Set `\$wgWatchlistExpiry = true;` to enable." );
25  return false;
26  }
27 
28  // Loop through 500 entries at a time and delete them.
29  $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
30  $count = $watchedItemStore->countExpired();
31  $this->output( $count . " expired watchlist entries found.\n" );
32  if ( $count === 0 ) {
33  // None found to delete.
34  return true;
35  }
36  while ( $watchedItemStore->countExpired() > 0 ) {
37  $watchedItemStore->removeExpired( $this->getBatchSize(), true );
38  }
39 
40  // Report success.
41  $this->output( "All expired entries purged.\n" );
42  return true;
43  }
44 }
45 
46 $maintClass = PurgeExpiredWatchlistItems::class;
47 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
PurgeExpiredWatchlistItems\execute
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...
Definition: purgeExpiredWatchlistItems.php:21
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:155
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:327
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:55
PurgeExpiredWatchlistItems\__construct
__construct()
Default constructor.
Definition: purgeExpiredWatchlistItems.php:12
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition: Maintenance.php:366
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:463
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:434
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:374
$maintClass
$maintClass
Definition: purgeExpiredWatchlistItems.php:46
PurgeExpiredWatchlistItems
Definition: purgeExpiredWatchlistItems.php:10