Skip to content
Snippets Groups Projects
Commit 719baf32 authored by JediKev's avatar JediKev
Browse files

issue: Orphaned File Query Rewrite

This addresses an issue that was introduced by a previous attempt to
address the orphaned file query. The previous attempt addressed the
original issue but slowed database performance so this addresses the
performance issue.
parent b7ef532d
No related branches found
No related tags found
No related merge requests found
...@@ -627,20 +627,17 @@ class AttachmentFile extends VerySimpleModel { ...@@ -627,20 +627,17 @@ class AttachmentFile extends VerySimpleModel {
* canned-response, or faq point to any more. * canned-response, or faq point to any more.
*/ */
static function deleteOrphans() { static function deleteOrphans() {
$sql = "SELECT `id` FROM ".FILE_TABLE.
// XXX: Allow plugins to define filetypes which do not represent " A1 WHERE (A1.ft = 'T' AND A1.created < NOW() - INTERVAL 1 DAY)".
// files attached to tickets or other things in the attachment " AND NOT EXISTS (SELECT id FROM ".ATTACHMENT_TABLE.
// table and are not logos " A2 WHERE A1.`id` = A2.`file_id`)";
$files = static::objects()
->filter(array( if (($res=db_query($sql)) && db_num_rows($res)) {
'attachments__object_id__isnull' => true, while (list($id) = db_fetch_row($res)) {
'ft' => 'T', if ($f = static::lookup((int) $id))
'created__lt' => SqlFunction::NOW()->minus(SqlInterval::DAY(1)), if (!$f->delete())
)); break;
}
foreach ($files as $f) {
if (!$f->delete())
break;
} }
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment