Skip to content
Snippets Groups Projects
Commit b778736f authored by Jared Hancock's avatar Jared Hancock
Browse files

Revert "issue: Orphaned File Query Rewrite"

An index was added to the v1.11 branch to support the ORM query. Because the
index cannot be applied to v1.10, the query was rewritten for the 1.10.x
branch to provide better performance without changes to the database. When
1.10.x was merged into 1.11.x the rewritten SQL accidentally showed up. This
reverts that merge to use the original ORM query.
parent e3219829
Branches
Tags
No related merge requests found
...@@ -636,17 +636,20 @@ class AttachmentFile extends VerySimpleModel { ...@@ -636,17 +636,20 @@ 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.
" A1 WHERE (A1.ft = 'T' AND A1.created < NOW() - INTERVAL 1 DAY)". // XXX: Allow plugins to define filetypes which do not represent
" AND NOT EXISTS (SELECT id FROM ".ATTACHMENT_TABLE. // files attached to tickets or other things in the attachment
" A2 WHERE A1.`id` = A2.`file_id`)"; // table and are not logos
$files = static::objects()
if (($res=db_query($sql)) && db_num_rows($res)) { ->filter(array(
while (list($id) = db_fetch_row($res)) { 'attachments__object_id__isnull' => true,
if ($f = static::lookup((int) $id)) 'ft' => 'T',
if (!$f->delete()) 'created__lt' => SqlFunction::NOW()->minus(SqlInterval::DAY(1)),
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