Skip to content
Snippets Groups Projects
Commit ded72cc5 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge branch '1.11.x' into develop-next

parents d202c940 2159ac0b
No related branches found
No related tags found
No related merge requests found
......@@ -636,17 +636,20 @@ class AttachmentFile extends VerySimpleModel {
* canned-response, or faq point to any more.
*/
static function deleteOrphans() {
$sql = "SELECT `id` FROM ".FILE_TABLE.
" A1 WHERE (A1.ft = 'T' AND A1.created < NOW() - INTERVAL 1 DAY)".
" AND NOT EXISTS (SELECT id FROM ".ATTACHMENT_TABLE.
" A2 WHERE A1.`id` = A2.`file_id`)";
if (($res=db_query($sql)) && db_num_rows($res)) {
while (list($id) = db_fetch_row($res)) {
if ($f = static::lookup((int) $id))
if (!$f->delete())
break;
}
// XXX: Allow plugins to define filetypes which do not represent
// files attached to tickets or other things in the attachment
// table and are not logos
$files = static::objects()
->filter(array(
'attachments__object_id__isnull' => true,
'ft' => 'T',
'created__lt' => SqlFunction::NOW()->minus(SqlInterval::DAY(1)),
));
foreach ($files as $f) {
if (!$f->delete())
break;
}
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment