r47241 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47240‎ | r47241 | r47242 >
Date:23:49, 13 February 2009
Author:jnatividad
Status:deferred
Tags:
Comment:
implemented recursive purge of ploticus sharded dir cache per $srfgPloticusCacheAgeHours param in LocalSettings.php (default: delete anything > 7 days old in cache)
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus_cleanCache.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus_cleanCache.php
@@ -38,34 +38,56 @@
3939
4040 $verbose = array_key_exists( 'v', $options );
4141
 42+$now = strftime("%c", time());
4243 if ($fileAge <= 0) {
4344 if ($verbose)
44 - echo "Ploticus cache cleaning disabled.\n";
 45+ echo "$now: Ploticus cache cleaning disabled.\n";
4546 return;
4647 }
4748
48 -$ploticusDirectory = $wgUploadDirectory . '/ploticus';
49 -$deletecount = 0;
 49+$ploticusDirectory = $wgUploadDirectory . '/ploticus/';
5050
51 -// TODO: Modify to be shard dir aware
52 -if( $dirhandle = @opendir($ploticusDirectory) ) {
53 - while( false !== ($filename = readdir($dirhandle)) ) {
54 - if( $filename != '.' && $filename != '..' ) {
55 - $filename = $ploticusDirectory . '/' . $filename;
 51+if (!is_dir($ploticusDirectory)) {
 52+ if ($verbose)
 53+ echo "$now: $ploticusDirectory does not exist!\n";
 54+ return;
 55+}
 56+
 57+if ($verbose)
 58+ echo "$now: Purging $ploticusDirectory cache of files >= $fileAge seconds old.\n";
5659
57 - if( @filemtime($filename) < (time()-$fileAge) ) {
58 - if ($verbose)
59 - echo "deleting $filename...\n";
60 - if (@unlink($filename))
61 - $deletecount ++;
62 - }
63 - }
 60+$deletecount = rfr($ploticusDirectory, "*.*", $fileAge, $verbose);
 61+
 62+if ($verbose) {
 63+ $now = strftime("%c", time());
 64+ if ($deletecount > 0 ) {
 65+ echo "$now: $deletecount files successfully deleted from Ploticus cache.\n";
 66+ } else {
 67+ echo "$now: No files deleted. Check if you have permission to delete files from $ploticusDirectory.\n";
6468 }
65 -} else {
66 - if ($verbose)
67 - echo "$ploticusDirectory not found... Aborting...\n";
6869 }
6970
70 -@closedir($dirhandle);
71 -if ($verbose)
72 - echo "$deletecount files successfully deleted from Ploticus cache.\n";
 71+/* recursive file delete function */
 72+function rfr($path, $match, $fileAge, $verbose) {
 73+ static $deleted = 0;
 74+ $dirs = glob($path."*");
 75+ $files = glob($path.$match);
 76+ foreach($files as $file){
 77+ if(is_file($file) && @filemtime($file) < (time()-$fileAge) ) {
 78+ if ($verbose) echo "$file...";
 79+ if (@unlink($file)) {
 80+ if ($verbose) echo "deleted.\n";
 81+ $deleted++;
 82+ } else {
 83+ if ($verbose) echo "ooops!\n";
 84+ }
 85+ }
 86+ }
 87+ foreach($dirs as $dir) {
 88+ if(is_dir($dir)) {
 89+ $dir = basename($dir) . "/";
 90+ rfr($path.$dir, $match, $fileAge, $verbose);
 91+ }
 92+ }
 93+ return $deleted;
 94+}
\ No newline at end of file

Status & tagging log