aboutsummaryrefslogtreecommitdiffstats
path: root/includes/watchlist/WatchlistExpiryJob.php
blob: 7d00b09ae375cbbb05a90e1f29fb46566c06a158 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

namespace MediaWiki\Watchlist;

use MediaWiki\JobQueue\Job;
use MediaWiki\MediaWikiServices;

/**
 * @internal For use by WatchedItemStore
 * @ingroup JobQueue
 */
class WatchlistExpiryJob extends Job {

	public function __construct( string $command = 'watchlistExpiry', array $params = [] ) {
		parent::__construct( $command, $params );
	}

	/**
	 * Run the job recursively in batches of 100 until there are no more expired items.
	 *
	 * @return bool Always true, to indicate success.
	 */
	public function run() {
		$services = MediaWikiServices::getInstance();
		$watchedItemStore = $services->getWatchedItemStore();
		$watchedItemStore->removeExpired( 100 );
		if ( $watchedItemStore->countExpired() ) {
			// If there are still items, add a new job.
			$services->getJobQueueGroup()->push( new static() );
		}
		return true;
	}

}
/** @deprecated class alias since 1.43 */
class_alias( WatchlistExpiryJob::class, 'WatchlistExpiryJob' );