Reduce memory usage in DailyCleanUpCronjob
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Sep 2016 16:06:30 +0000 (18:06 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Sep 2016 16:16:04 +0000 (18:16 +0200)
wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php

index 67b9c072b29e5785eed0c97704e6ee24b8182ff7..cc2c8f18d5c881be32b82d9a0cb67e4cabf5b686 100644 (file)
@@ -166,29 +166,27 @@ 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;
+               $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tempFolder, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
+               foreach ($it as $file) {
+                       if ($file->getPathname() === $tempFolder) continue;
+                       if ($file->getPathname() === $tempFolder.'/.htaccess') continue;
                        
-                       if ($object->getMTime() < TIME_NOW - 86400) {
-                               if ($object->isDir()) {
-                                       @rmdir($filename);
-                               }
-                               else if ($object->isFile()) {
-                                       @unlink($filename);
-                               }
+                       if ($file->getMTime() < TIME_NOW - 86400) {
+                               if ($file->isDir()) @rmdir($file->getPathname());
+                               else if ($file->isFile()) @unlink($file->getPathname());
                        }
-               }));
+               }
                
                // clean up proxy images
                if (MODULE_IMAGE_PROXY) {
-                       DirectoryUtil::getInstance(WCF_DIR.'images/proxy/')->executeCallback(new Callback(function($filename, $object) {
-                               if ($filename === WCF_DIR.'images/proxy/.htaccess') return;
+                       $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(WCF_DIR.'images/proxy/', \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
+                       foreach ($it as $file) {
+                               if ($file->getPathname() === WCF_DIR.'images/proxy/.htaccess') continue;
                                
-                               if ($object->isFile() && $object->getMTime() < TIME_NOW - 86400 * IMAGE_PROXY_EXPIRATION) {
-                                       @unlink($filename);
+                               if ($file->isFile() && $file->getMTime() < (TIME_NOW - 86400 * IMAGE_PROXY_EXPIRATION)) {
+                                       @unlink($file->getPathname());
                                }
-                       }));
+                       }
                }
        }
 }