From f82a44910b6c783d9bded95f04dec0dcec76ade6 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 15 Oct 2014 10:35:34 -0500
Subject: [PATCH] files: Cleanup orphaned files on autocron

---
 include/class.cron.php | 4 +++-
 scp/autocron.php       | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/class.cron.php b/include/class.cron.php
index af5a14768..f231ac5b3 100644
--- a/include/class.cron.php
+++ b/include/class.cron.php
@@ -98,7 +98,9 @@ class Cron {
         self::MailFetcher();
         self::TicketMonitor();
         self::PurgeLogs();
-        self::CleanOrphanedFiles();
+        // Run file purging about every 10 cron runs
+        if (mt_rand(1, 9) == 4)
+            self::CleanOrphanedFiles();
         self::PurgeDrafts();
         self::MaybeOptimizeTables();
 
diff --git a/scp/autocron.php b/scp/autocron.php
index b6016399e..eabc67151 100644
--- a/scp/autocron.php
+++ b/scp/autocron.php
@@ -44,6 +44,11 @@ require_once(INCLUDE_DIR.'class.cron.php');
 
 $thisstaff = null; //Clear staff obj to avoid false credit internal notes & auto-assignment
 Cron::TicketMonitor(); //Age tickets: We're going to age tickets regardless of cron settings.
+
+// Run file purging about every 30 minutes
+if (mt_rand(1, 9) == 4)
+    Cron::CleanOrphanedFiles();
+
 if($cfg && $cfg->isAutoCronEnabled()) { //ONLY fetch tickets if autocron is enabled!
     Cron::MailFetcher();  //Fetch mail.
     $ost->logDebug(_S('Auto Cron'), sprintf(_S('Mail fetcher cron call [%s]'), $caller));
-- 
GitLab