diff options
Diffstat (limited to 'models/attachment.go')
-rw-r--r-- | models/attachment.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/models/attachment.go b/models/attachment.go index 330e965bb1..96048db00a 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -272,3 +272,16 @@ func IterateAttachment(f func(attach *Attachment) error) error { } } } + +// CountOrphanedAttachments returns the number of bad attachments +func CountOrphanedAttachments() (int64, error) { + return x.Where("(issue_id > 0 and issue_id not in (select id from issue)) or (release_id > 0 and release_id not in (select id from `release`))"). + Count(new(Attachment)) +} + +// DeleteOrphanedAttachments delete all bad attachments +func DeleteOrphanedAttachments() error { + _, err := x.Where("(issue_id > 0 and issue_id not in (select id from issue)) or (release_id > 0 and release_id not in (select id from `release`))"). + Delete(new(Attachment)) + return err +} |