From b05dcbda54b306d37a7e4f0df987fc184deba744 Mon Sep 17 00:00:00 2001
From: JediKev <kevin@enhancesoft.com>
Date: Wed, 25 Apr 2018 14:43:08 -0500
Subject: [PATCH] issue: Files - deleteOrphans()

This addresses the issue where files were being deleted before being sent
out in Agent responses. This was due to a bug in the query that gets the
orphaned files. This query was getting files created within the last 24
hours not after the last 24 hours. The query also had another bug that
would use the time from PHP instead of MySQL which could cause issues.
This updates the query as per @greezybacon's suggestions to delete
orphaned files that were created more than 24 hours ago.
---
 include/class.file.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/class.file.php b/include/class.file.php
index bcdb9e0ed..2a0073b4b 100644
--- a/include/class.file.php
+++ b/include/class.file.php
@@ -635,7 +635,7 @@ class AttachmentFile extends VerySimpleModel {
             ->filter(array(
                 'attachments__object_id__isnull' => true,
                 'ft' => 'T',
-                'created__gt' => new DateTime('now -1 day'),
+                'created__lt' => SqlFunction::NOW()->minus(SqlInterval::DAY(1)),
             ));
 
         foreach ($files as $f) {
-- 
GitLab