Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Created April 19, 2012 05:14
Show Gist options
  • Select an option

  • Save hSATAC/2418763 to your computer and use it in GitHub Desktop.

Select an option

Save hSATAC/2418763 to your computer and use it in GitHub Desktop.
delete Redmine duplicated attachments
def del_dup
for a in Attachment.all
dup = Attachment.find(:all, :conditions=>{:filename => a.filename, :filesize=>a.filesize})
if dup.count > 1
puts "Duplicated Attachment found! Start purging..."
puts "item # #{a.id} #{a.filename} (#{a.filesize}) got #{dup.count} duplicated items."
for as in dup[1..-1]
puts "Deleting #{as.id}..."
as.delete_from_disk
as.destroy
end
break
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment