MediaWiki  REL1_19
purgeParserCache.php
Go to the documentation of this file.
00001 <?php
00007 require( dirname( __FILE__ ) . '/Maintenance.php' );
00008 
00009 class PurgeParserCache extends Maintenance {
00010         var $lastProgress;
00011 
00012         function __construct() {
00013                 parent::__construct();
00014                 $this->addDescription( "Remove old objects from the parser cache. " . 
00015                         "This only works when the parser cache is in an SQL database." );
00016                 $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
00017                 $this->addOption( 'age', 
00018                         'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime '.
00019                                 'has been consistent.', 
00020                         false, true );
00021         }
00022 
00023         function execute() {
00024                 $inputDate = $this->getOption( 'expiredate' );
00025                 $inputAge = $this->getOption( 'age' );
00026                 if ( $inputDate !== null ) {
00027                         $date = wfTimestamp( TS_MW, strtotime( $inputDate ) );
00028                 } elseif ( $inputAge !== null ) {
00029                         global $wgParserCacheExpireTime;
00030                         $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) );
00031                 } else {
00032                         echo "Must specify either --expiredate or --age\n";
00033                         exit( 1 );
00034                 }
00035 
00036                 $english = Language::factory( 'en' );
00037                 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n";
00038 
00039                 $pc = wfGetParserCacheStorage();
00040                 $success = $pc->deleteObjectsExpiringBefore( $date, array( $this, 'showProgress' ) );
00041                 if ( !$success ) {
00042                         echo "\nCannot purge this kind of parser cache.\n";
00043                         exit( 1 );
00044                 }
00045                 $this->showProgress( 100 );
00046                 echo "\nDone\n";
00047         }
00048 
00049         function showProgress( $percent ) {
00050                 $percentString = sprintf( "%.2f", $percent );
00051                 if ( $percentString === $this->lastProgress ) {
00052                         return;
00053                 }
00054                 $this->lastProgress = $percentString;
00055 
00056                 $stars = floor( $percent / 2 );
00057                 echo '[' . str_repeat( '*', $stars ), str_repeat( '.', 50 - $stars ) . '] ' .
00058                         "$percentString%\r";
00059 
00060         }
00061 }
00062 $maintClass = 'PurgeParserCache';
00063 require_once( RUN_MAINTENANCE_IF_MAIN );