24 require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
37 $this->
addDescription(
'Delete file cache files older than "agedays"' );
38 $this->
addOption(
'agedays',
'How many days old files must be in order to delete',
true,
true );
39 $this->
addOption(
'subdir',
'Prune one $wgFileCacheDirectory subdirectory name',
false,
true );
46 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
50 if ( !ctype_digit( $age ) ) {
51 $this->
fatalError(
"Non-integer 'age' parameter given." );
54 $this->minSurviveTimestamp = time() - ( 86400 * $age );
57 if ( !is_dir( $dir ) ) {
58 $this->
fatalError(
"Nothing to do -- \$wgFileCacheDirectory directory not found." );
62 if ( $subDir !==
null ) {
63 if ( !is_dir(
"$dir/$subDir" ) ) {
64 $this->
fatalError(
"The specified subdirectory `$subDir` does not exist." );
66 $this->
output(
"Pruning `$dir/$subDir` directory...\n" );
68 $this->
output(
"Done pruning `$dir/$subDir` directory\n" );
70 $this->
output(
"Pruning `$dir` directory...\n" );
73 $this->
output(
"Done pruning `$dir` directory\n" );
83 $dirHandle = opendir( $dir );
84 while ( (
$file = readdir( $dirHandle ) ) !==
false ) {
86 if (
$file[0] !=
"." ) {
89 if ( is_dir(
$path ) ) {
90 if ( $report ===
'report' ) {
91 $this->
output(
"Scanning `$path`...\n" );
95 $mts = filemtime(
$path );
97 if ( $mts < $this->minSurviveTimestamp
98 && preg_match(
'/\.(?:html|cache)(?:\.gz)?$/',
$file )
101 $daysOld = round( ( $tsNow - $mts ) / 86400, 2 );
102 $this->
output(
"Deleted `$path` [days=$daysOld]\n" );
107 closedir( $dirHandle );
112 require_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.
addDescription( $text)
Set the description text.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.