22require_once __DIR__ .
'/Maintenance.php';
27use Wikimedia\Timestamp\ConvertibleTimestamp;
42 private $lastProgress;
45 private $lastTimestamp;
48 private $tmpCount = 0;
53 parent::__construct();
54 $this->
addDescription(
"Remove old objects from the parser cache. " .
55 "This only works when the parser cache is in an SQL database." );
56 $this->
addOption(
'expiredate',
'Delete objects expiring before this date.',
false,
true );
59 'Delete objects created more than this many seconds ago, assuming ' .
60 '$wgParserCacheExpireTime has remained consistent.',
63 $this->
addOption(
'dry-run',
'Perform a dry run, to verify age and date calculation.' );
64 $this->
addOption(
'msleep',
'Milliseconds to sleep between purge chunks of $wgUpdateRowsPerQuery.',
69 'Purge a single server only. This feature is designed for use by large wiki farms where ' .
70 'one has to purge multiple servers concurrently in order to keep up with new writes. ' .
71 'This requires using the SqlBagOStuff "servers" option in $wgObjectCaches.',
77 $inputDate = $this->
getOption(
'expiredate' );
80 if ( $inputDate !==
null ) {
81 $timestamp = strtotime( $inputDate );
82 } elseif ( $inputAge !==
null ) {
83 $expireTime = (int)$this->
getConfig()->get( MainConfigNames::ParserCacheExpireTime );
84 $timestamp = time() + $expireTime - intval( $inputAge );
86 $this->
fatalError(
"Must specify either --expiredate or --age" );
88 $this->usleep = 1e3 * $this->
getOption(
'msleep', 0 );
89 $this->lastTimestamp = microtime(
true );
91 $humanDate = ConvertibleTimestamp::convert( TS_RFC2822, $timestamp );
93 $this->
fatalError(
"\nDry run mode, would delete objects having an expiry before " . $humanDate .
"\n" );
96 $this->
output(
"Deleting objects expiring before " . $humanDate .
"\n" );
99 $success = $pc->deleteObjectsExpiringBefore(
101 [ $this,
'showProgressAndWait' ],
107 $this->
fatalError(
"\nCannot purge this kind of parser cache." );
110 $this->
output(
"\nDone\n" );
123 usleep( $this->usleep );
126 $percentString = sprintf(
"%.1f", $percent );
127 if ( $percentString === $this->lastProgress ) {
135 $now = microtime(
true );
136 $sec = sprintf(
"%.1f", $now - $this->lastTimestamp );
140 $this->
output(
"... {$percentString}% done (+{$this->tmpCount} iterations in {$sec}s)\n" );
142 $this->lastProgress = $percentString;
144 $this->lastTimestamp = $now;
150require_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.
showProgressAndWait(int $percent)
execute()
Do the actual work.
__construct()
Default constructor.