27require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
42 $this->
addDescription(
'Delete file cache files older than "agedays"' );
43 $this->
addOption(
'agedays',
'How many days old files must be in order to delete',
true,
true );
44 $this->
addOption(
'subdir',
'Prune one $wgFileCacheDirectory subdirectory name',
false,
true );
51 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
55 if ( !ctype_digit( $age ) ) {
56 $this->
fatalError(
"Non-integer 'age' parameter given." );
59 $this->minSurviveTimestamp = time() - ( 86400 * $age );
62 if ( !is_dir( $dir ) ) {
63 $this->
fatalError(
"Nothing to do -- \$wgFileCacheDirectory directory not found." );
67 if ( $subDir !==
null ) {
68 if ( !is_dir(
"$dir/$subDir" ) ) {
69 $this->
fatalError(
"The specified subdirectory `$subDir` does not exist." );
71 $this->
output(
"Pruning `$dir/$subDir` directory...\n" );
73 $this->
output(
"Done pruning `$dir/$subDir` directory\n" );
75 $this->
output(
"Pruning `$dir` directory...\n" );
78 $this->
output(
"Done pruning `$dir` directory\n" );
88 $dirHandle = opendir( $dir );
90 while ( ( $file = readdir( $dirHandle ) ) !==
false ) {
92 if ( $file[0] !=
"." ) {
94 $path = $dir .
'/' . $file;
95 if ( is_dir(
$path ) ) {
96 if ( $report ===
'report' ) {
97 $this->
output(
"Scanning `$path`...\n" );
101 $mts = filemtime(
$path );
103 if ( $mts < $this->minSurviveTimestamp
104 && preg_match(
'/\.(?:html|cache)(?:\.gz)?$/', $file )
107 $daysOld = round( ( $tsNow - $mts ) / 86400, 2 );
108 $this->
output(
"Deleted `$path` [days=$daysOld]\n" );
113 closedir( $dirHandle );
119require_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.
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.
getOption( $name, $default=null)
Get an option, or return the default.
addDescription( $text)
Set the description text.
Maintenance script that prunes file cache for pages, objects, resources, etc.
__construct()
Default constructor.
prune_directory( $dir, $report=false)
execute()
Do the actual work.
$wgFileCacheDirectory
Config variable stub for the FileCacheDirectory setting, for use by phpdoc and IDEs.
$wgUseFileCache
Config variable stub for the UseFileCache setting, for use by phpdoc and IDEs.