Revert r106521: creates lots of long, unwrappable lines in help output
[mediawiki.git] / maintenance / purgeParserCache.php
blob7a8f6f7c11ce238f95c184a3c5d040eea8b065f7
1 <?php
3 require( dirname( __FILE__ ) . '/Maintenance.php' );
5 class PurgeParserCache extends Maintenance {
6 var $lastProgress;
8 function __construct() {
9 parent::__construct();
10 $this->addDescription( "Remove old objects from the parser cache. " .
11 "This only works when the parser cache is in an SQL database." );
12 $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
13 $this->addOption( 'age',
14 'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime '.
15 'has been consistent.',
16 false, true );
19 function execute() {
20 $inputDate = $this->getOption( 'expiredate' );
21 $inputAge = $this->getOption( 'age' );
22 if ( $inputDate !== null ) {
23 $date = wfTimestamp( TS_MW, strtotime( $inputDate ) );
24 } elseif ( $inputAge !== null ) {
25 global $wgParserCacheExpireTime;
26 $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) );
27 } else {
28 echo "Must specify either --expiredate or --age\n";
29 exit( 1 );
32 $english = Language::factory( 'en' );
33 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n";
35 $pc = wfGetParserCacheStorage();
36 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
37 if ( !$success ) {
38 echo "\nCannot purge this kind of parser cache.\n";
39 exit( 1 );
41 $this->showProgress( 100 );
42 echo "\nDone\n";
45 function showProgress( $percent ) {
46 $percentString = sprintf( "%.2f", $percent );
47 if ( $percentString === $this->lastProgress ) {
48 return;
50 $this->lastProgress = $percentString;
52 $stars = floor( $percent / 2 );
53 echo '[' . str_repeat( '*', $stars ), str_repeat( '.', 50 - $stars ) . '] ' .
54 "$percentString%\r";
58 $maintClass = 'PurgeParserCache';
59 require_once( RUN_MAINTENANCE_IF_MAIN );