Commit 7b45c629a3a7c5ada3e368e894297a45ccd4148d
1 parent
33d2b7c0
KTS-3598
"KnowledgeTree's temp folder has too many smarty files in it. over time, the directory gets very large." Implemented. We clean up files and directories created more than a day ago. Ideally, we'd use smarty better so this would not happen. Committed By: Conrad Vermeulen Reviewed By: Megan Watson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9103 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
21 additions
and
9 deletions
search2/bin/cronCleanup.php
| @@ -43,25 +43,37 @@ require_once(realpath('../../config/dmsDefaults.php')); | @@ -43,25 +43,37 @@ require_once(realpath('../../config/dmsDefaults.php')); | ||
| 43 | $config = KTConfig::getSingleton(); | 43 | $config = KTConfig::getSingleton(); |
| 44 | $temp_dir =$config->get("urls/tmpDirectory"); | 44 | $temp_dir =$config->get("urls/tmpDirectory"); |
| 45 | 45 | ||
| 46 | - | ||
| 47 | cleanupTempDirectory($temp_dir); | 46 | cleanupTempDirectory($temp_dir); |
| 48 | 47 | ||
| 49 | -function cleanupTempDirectory($dir) | 48 | +function cleanupTempDirectory($dir, $force = false) |
| 50 | { | 49 | { |
| 51 | - if (!is_dir($dir)) | ||
| 52 | - { | ||
| 53 | - return; | ||
| 54 | - } | ||
| 55 | $dir = str_replace('\\','/', $dir); | 50 | $dir = str_replace('\\','/', $dir); |
| 56 | 51 | ||
| 57 | $dh = opendir($dir); | 52 | $dh = opendir($dir); |
| 58 | while (($name = readdir($dh)) !== false) | 53 | while (($name = readdir($dh)) !== false) |
| 59 | { | 54 | { |
| 60 | - if (substr($name, 0, 9) != 'ktindexer') | 55 | + if (substr($name, 0, 1) == '.') continue; |
| 56 | + | ||
| 57 | + $kti = (substr($name, 0, 3) == 'kti'); // remove files starting with kti (indexer temp files created by open office) | ||
| 58 | + | ||
| 59 | + $fullname = $dir . '/' . $name; | ||
| 60 | + | ||
| 61 | + if (!$kti && !$force) | ||
| 61 | { | 62 | { |
| 62 | - continue; | 63 | + $info = stat($fullname); |
| 64 | + if ($info['ctime'] >= time() - 24 * 60 * 60) continue; // remove files that have been accessed in the last 24 hours | ||
| 63 | } | 65 | } |
| 64 | - unlink($dir . '/' . $name); | 66 | + |
| 67 | + if (is_dir($fullname)) | ||
| 68 | + { | ||
| 69 | + cleanupTempDirectory($fullname, true); | ||
| 70 | + rmdir($fullname); | ||
| 71 | + } | ||
| 72 | + else | ||
| 73 | + { | ||
| 74 | + unlink($fullname); | ||
| 75 | + } | ||
| 76 | + | ||
| 65 | } | 77 | } |
| 66 | closedir($dh); | 78 | closedir($dh); |
| 67 | } | 79 | } |