Clean up temporary folder in DailyCleanUpCronjob
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 20 Mar 2015 18:01:06 +0000 (19:01 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 20 Mar 2015 18:01:06 +0000 (19:01 +0100)
wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php

index d415c3da8aa4b5ab1b752cc997389a207cc869a0..2778be1ac799aa3a458cacfa5504b211670700ea 100644 (file)
@@ -3,7 +3,10 @@ namespace wcf\system\cronjob;
 use wcf\data\cronjob\Cronjob;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\visitTracker\VisitTracker;
+use wcf\system\Callback;
 use wcf\system\WCF;
+use wcf\util\DirectoryUtil;
+use wcf\util\FileUtil;
 
 /**
  * Cronjob for a daily system cleanup.
@@ -162,5 +165,21 @@ class DailyCleanUpCronjob extends AbstractCronjob {
                                }
                        }
                }
+               
+               // clean up temporary folder
+               $tempFolder = FileUtil::getTempFolder();
+               DirectoryUtil::getInstance($tempFolder)->executeCallback(new Callback(function($filename, $object) use ($tempFolder) {
+                       if ($filename === $tempFolder) return;
+                       if ($filename === $tempFolder.'.htaccess') return;
+                       
+                       if ($object->getMTime() < TIME_NOW - 86400) {
+                               if ($object->isDir()) {
+                                       @rmdir($filename);
+                               }
+                               else if ($object->isFile()) {
+                                       @unlink($filename);
+                               }
+                       }
+               }));
        }
 }