diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ae23428f1..b6253de7a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -349,11 +349,16 @@ class Attachment < ActiveRecord::Base # Deletes the file from the file system if it's not referenced by other attachments def delete_from_disk - if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? + #资源存在,且历史记录为0 且 该资源没有存在任何拷贝才能删除资源 + if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0 delete_from_disk! end end + def destroyable + Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0 + end + # Returns file's location on disk def diskfile File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s) diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 653877260..e2d321b51 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -52,7 +52,7 @@ <%end%>