MediaWiki
master
Toggle main menu visibility
purgeExpiredWatchlistItems.php
Go to the documentation of this file.
1
<?php
5
6
use
MediaWiki\MainConfigNames
;
7
use
MediaWiki\Maintenance\Maintenance
;
8
9
// @codeCoverageIgnoreStart
10
require_once __DIR__ .
'/Maintenance.php'
;
11
// @codeCoverageIgnoreEnd
12
13
class
PurgeExpiredWatchlistItems
extends
Maintenance
{
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;
51
require_once RUN_MAINTENANCE_IF_MAIN;
52
// @codeCoverageIgnoreEnd
$maintClass
$maintClass
Definition
addChangeTag.php:56
MediaWiki\MainConfigNames
A class containing constants representing the names of configuration variables.
Definition
MainConfigNames.php:22
MediaWiki\MainConfigNames\WatchlistExpiry
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config\get().
Definition
MainConfigNames.php:3866
PurgeExpiredWatchlistItems
Definition
purgeExpiredWatchlistItems.php:13
PurgeExpiredWatchlistItems\execute
execute()
Definition
purgeExpiredWatchlistItems.php:24
PurgeExpiredWatchlistItems\__construct
__construct()
Definition
purgeExpiredWatchlistItems.php:15
MediaWiki\Watchlist\WatchedItemStoreInterface\countExpired
countExpired()
Get the number of watchlist items that expire before the current time.
MediaWiki\Watchlist\WatchedItemStoreInterface\removeExpired
removeExpired(int $limit, bool $deleteOrphans=false)
Remove some number of expired watchlist items.
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
maintenance
purgeExpiredWatchlistItems.php
Generated on
for MediaWiki by
1.18.0