Revert r97788
[lhc/web/wiklou.git] / maintenance / purgeParserCache.php
1 <?php
2
3 require( dirname( __FILE__ ) . '/Maintenance.php' );
4
5 class PurgeParserCache extends Maintenance {
6 function __construct() {
7 parent::__construct();
8 $this->addDescription( "Remove old objects from the parser cache. " .
9 "This only works when the parser cache is in an SQL database." );
10 $this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
11 $this->addOption( 'age',
12 'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime '.
13 'has been consistent.',
14 false, true );
15 }
16
17 function execute() {
18 $inputDate = $this->getOption( 'expiredate' );
19 $inputAge = $this->getOption( 'age' );
20 if ( $inputDate !== null ) {
21 $date = wfTimestamp( TS_MW, strtotime( $inputDate ) );
22 } elseif ( $inputAge !== null ) {
23 global $wgParserCacheExpireTime;
24 $date = wfTimestamp( TS_MW, time() + $wgParserCacheExpireTime - intval( $inputAge ) );
25 } else {
26 echo "Must specify either --expiredate or --age\n";
27 exit( 1 );
28 }
29
30 $english = Language::factory( 'en' );
31 echo "Deleting objects expiring before " . $english->timeanddate( $date ) . "\n";
32
33 $pc = wfGetParserCacheStorage();
34 $success = $pc->deleteObjectsExpiringBefore( $date );
35 if ( !$success ) {
36 echo "Cannot purge this kind of parser cache.\n";
37 exit( 1 );
38 }
39 echo "Done\n";
40 }
41 }
42 $maintClass = 'PurgeParserCache';
43 require_once( RUN_MAINTENANCE_IF_MAIN );