25require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
40 $this->addDescription(
'Delete file cache files older than "agedays"' );
41 $this->addOption(
'agedays',
'How many days old files must be in order to delete',
true,
true );
42 $this->addOption(
'subdir',
'Prune one $wgFileCacheDirectory subdirectory name',
false,
true );
49 $this->fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
52 $age = $this->getOption(
'agedays' );
53 if ( !ctype_digit( $age ) ) {
54 $this->fatalError(
"Non-integer 'age' parameter given." );
57 $this->minSurviveTimestamp = time() - ( 86400 * $age );
60 if ( !is_dir( $dir ) ) {
61 $this->fatalError(
"Nothing to do -- \$wgFileCacheDirectory directory not found." );
64 $subDir = $this->getOption(
'subdir' );
65 if ( $subDir !==
null ) {
66 if ( !is_dir(
"$dir/$subDir" ) ) {
67 $this->fatalError(
"The specified subdirectory `$subDir` does not exist." );
69 $this->output(
"Pruning `$dir/$subDir` directory...\n" );
71 $this->output(
"Done pruning `$dir/$subDir` directory\n" );
73 $this->output(
"Pruning `$dir` directory...\n" );
76 $this->output(
"Done pruning `$dir` directory\n" );
86 $dirHandle = opendir( $dir );
88 while ( ( $file = readdir( $dirHandle ) ) !==
false ) {
90 if ( $file[0] !=
"." ) {
92 $path = $dir .
'/' . $file;
93 if ( is_dir(
$path ) ) {
94 if ( $report ===
'report' ) {
95 $this->output(
"Scanning `$path`...\n" );
99 $mts = filemtime(
$path );
101 if ( $mts < $this->minSurviveTimestamp
102 && preg_match(
'/\.(?:html|cache)(?:\.gz)?$/', $file )
105 $daysOld = round( ( $tsNow - $mts ) / 86400, 2 );
106 $this->output(
"Deleted `$path` [days=$daysOld]\n" );
111 closedir( $dirHandle );
117require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that prunes file cache for pages, objects, resources, etc.
prune_directory( $dir, $report=false)
$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.