Commit f162a5dd1af6ec7194dd246b2b36f100eb6a8448

Authored by kevin_fourie
1 parent 1776e5f3

Merged in from DEV trunk...

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/STABLE/trunk@9105 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 23 additions and 9 deletions
search2/bin/cronCleanup.php
... ... @@ -43,25 +43,39 @@ require_once(realpath('../../config/dmsDefaults.php'));
43 43 $config = KTConfig::getSingleton();
44 44 $temp_dir =$config->get("urls/tmpDirectory");
45 45  
46   -
47 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 50 $dir = str_replace('\\','/', $dir);
56 51  
  52 + if (strpos($dir, '/tmp') === false) return;
  53 +
57 54 $dh = opendir($dir);
58 55 while (($name = readdir($dh)) !== false)
59 56 {
60   - if (substr($name, 0, 9) != 'ktindexer')
  57 + if (substr($name, 0, 1) == '.') continue;
  58 +
  59 + $kti = (substr($name, 0, 3) == 'kti'); // remove files starting with kti (indexer temp files created by open office)
  60 +
  61 + $fullname = $dir . '/' . $name;
  62 +
  63 + if (!$kti && !$force)
61 64 {
62   - continue;
  65 + $info = stat($fullname);
  66 + if ($info['ctime'] >= time() - 24 * 60 * 60) continue; // remove files that have been accessed in the last 24 hours
63 67 }
64   - unlink($dir . '/' . $name);
  68 +
  69 + if (is_dir($fullname))
  70 + {
  71 + cleanupTempDirectory($fullname, true);
  72 + rmdir($fullname);
  73 + }
  74 + else
  75 + {
  76 + unlink($fullname);
  77 + }
  78 +
65 79 }
66 80 closedir($dh);
67 81 }
... ...