21 require_once __DIR__ .
'/Maintenance.php';
24 use Wikimedia\Timestamp\ConvertibleTimestamp;
39 private $lastProgress;
42 private $lastTimestamp;
44 private $tmpCount = 0;
48 parent::__construct();
49 $this->
addDescription(
"Remove old objects from the parser cache. " .
50 "This only works when the parser cache is in an SQL database." );
51 $this->
addOption(
'expiredate',
'Delete objects expiring before this date.',
false,
true );
54 'Delete objects created more than this many seconds ago, assuming ' .
55 '$wgParserCacheExpireTime has remained consistent.',
58 $this->
addOption(
'dry-run',
'Perform a dry run, to verify age and date calculation.' );
59 $this->
addOption(
'msleep',
'Milliseconds to sleep between purge chunks of $wgUpdateRowsPerQuery.',
64 'Purge a single server only. This feature is designed for use by large wiki farms where ' .
65 'one has to purge multiple servers concurrently in order to keep up with new writes. ' .
66 'This requires using the SqlBagOStuff "servers" option in $wgObjectCaches.',
72 $inputDate = $this->
getOption(
'expiredate' );
75 if ( $inputDate !==
null ) {
76 $timestamp = strtotime( $inputDate );
77 } elseif ( $inputAge !==
null ) {
78 $expireTime = (int)$this->
getConfig()->get( MainConfigNames::ParserCacheExpireTime );
79 $timestamp = time() + $expireTime - intval( $inputAge );
81 $this->
fatalError(
"Must specify either --expiredate or --age" );
83 $this->usleep = 1e3 * $this->
getOption(
'msleep', 0 );
84 $this->lastTimestamp = microtime(
true );
86 $humanDate = ConvertibleTimestamp::convert( TS_RFC2822, $timestamp );
88 $this->
fatalError(
"\nDry run mode, would delete objects having an expiry before " . $humanDate .
"\n" );
91 $this->
output(
"Deleting objects expiring before " . $humanDate .
"\n" );
94 $success = $pc->deleteObjectsExpiringBefore(
96 [ $this,
'showProgressAndWait' ],
102 $this->
fatalError(
"\nCannot purge this kind of parser cache." );
105 $this->
output(
"\nDone\n" );
118 usleep( $this->usleep );
121 $percentString = sprintf(
"%.1f", $percent );
122 if ( $percentString === $this->lastProgress ) {
130 $now = microtime(
true );
131 $sec = sprintf(
"%.1f", $now - $this->lastTimestamp );
135 $this->
output(
"... {$percentString}% done (+{$this->tmpCount} iterations in {$sec}s)\n" );
137 $this->lastProgress = $percentString;
139 $this->lastTimestamp = $now;
144 require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
A class containing constants representing the names of configuration variables.
Remove expired objects from the parser cache database.
execute()
Do the actual work.
__construct()
Default constructor.
showProgressAndWait( $percent)