8require_once __DIR__ .
'/Maintenance.php';
13use Wikimedia\Timestamp\ConvertibleTimestamp;
14use Wikimedia\Timestamp\TimestampFormat as TS;
29 private $lastProgress;
32 private $lastTimestamp;
35 private $tmpCount = 0;
40 parent::__construct();
41 $this->
addDescription(
"Remove old objects from the parser cache. " .
42 "This only works when the parser cache is in an SQL database." );
43 $this->
addOption(
'expiredate',
'Delete objects expiring before this date.',
false,
true );
46 'Delete objects created more than this many seconds ago, assuming ' .
47 '$wgParserCacheExpireTime has remained consistent.',
50 $this->
addOption(
'dry-run',
'Perform a dry run, to verify age and date calculation.' );
51 $this->
addOption(
'msleep',
'Milliseconds to sleep between purge chunks of $wgUpdateRowsPerQuery.',
56 'Purge a single server only. This feature is designed for use by large wiki farms where ' .
57 'one has to purge multiple servers concurrently in order to keep up with new writes. ' .
58 'This requires using the SqlBagOStuff "servers" option in $wgObjectCaches.',
64 $inputDate = $this->
getOption(
'expiredate' );
67 if ( $inputDate !==
null ) {
68 $timestamp = strtotime( $inputDate );
69 } elseif ( $inputAge !==
null ) {
70 $expireTime = (int)$this->
getConfig()->get( MainConfigNames::ParserCacheExpireTime );
71 $timestamp = time() + $expireTime - intval( $inputAge );
73 $this->
fatalError(
"Must specify either --expiredate or --age" );
75 $this->usleep = 1e3 * $this->
getOption(
'msleep', 0 );
76 $this->lastTimestamp = microtime(
true );
78 $humanDate = ConvertibleTimestamp::convert( TS::RFC2822, $timestamp );
80 $this->
fatalError(
"\nDry run mode, would delete objects having an expiry before " . $humanDate .
"\n" );
83 $this->
output(
"Deleting objects expiring before " . $humanDate .
"\n" );
86 $success = $pc->deleteObjectsExpiringBefore(
88 $this->showProgressAndWait( ... ),
94 $this->
fatalError(
"\nCannot purge this kind of parser cache." );
96 $this->showProgressAndWait( 100 );
97 $this->
output(
"\nDone\n" );
100 private function showProgressAndWait(
int $percent ) {
110 usleep( $this->usleep );
113 $percentString = sprintf(
"%.1f", $percent );
114 if ( $percentString === $this->lastProgress ) {
122 $now = microtime(
true );
123 $sec = sprintf(
"%.1f", $now - $this->lastTimestamp );
127 $this->
output(
"... {$percentString}% done (+{$this->tmpCount} iterations in {$sec}s)\n" );
129 $this->lastProgress = $percentString;
131 $this->lastTimestamp = $now;
137require_once RUN_MAINTENANCE_IF_MAIN;
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Remove expired objects from the parser cache database.
execute()
Do the actual work.
__construct()
Default constructor.