mirror of
https://github.com/redmine/redmine.git
synced 2026-05-13 01:47:12 +02:00
Copy attachments on issue and project copy (#3055).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8676 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -49,8 +49,16 @@ class Attachment < ActiveRecord::Base
|
||||
before_save :files_to_final_location
|
||||
after_destroy :delete_from_disk
|
||||
|
||||
# Returns an unsaved copy of the attachment
|
||||
def copy(attributes=nil)
|
||||
copy = self.class.new
|
||||
copy.attributes = self.attributes.dup.except("id", "downloads")
|
||||
copy.attributes = attributes if attributes
|
||||
copy
|
||||
end
|
||||
|
||||
def validate_max_file_size
|
||||
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||
if @temp_file && self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||
errors.add(:base, :too_long, :count => Setting.attachment_max_size.to_i.kilobytes)
|
||||
end
|
||||
end
|
||||
@@ -96,9 +104,11 @@ class Attachment < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Deletes file on the disk
|
||||
# Deletes the file from the file system if it's not referenced by other attachments
|
||||
def delete_from_disk
|
||||
File.delete(diskfile) if !filename.blank? && File.exist?(diskfile)
|
||||
if Attachment.first(:conditions => ["disk_filename = ? AND id <> ?", disk_filename, id]).nil?
|
||||
delete_from_disk!
|
||||
end
|
||||
end
|
||||
|
||||
# Returns file's location on disk
|
||||
@@ -173,7 +183,15 @@ class Attachment < ActiveRecord::Base
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
# Physically deletes the file from the file system
|
||||
def delete_from_disk!
|
||||
if disk_filename.present? && File.exist?(diskfile)
|
||||
File.delete(diskfile)
|
||||
end
|
||||
end
|
||||
|
||||
def sanitize_filename(value)
|
||||
# get only the filename, not the whole path
|
||||
just_filename = value.gsub(/^.*(\\|\/)/, '')
|
||||
|
||||
@@ -135,6 +135,9 @@ class Issue < ActiveRecord::Base
|
||||
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||||
self.status = issue.status
|
||||
self.author = User.current
|
||||
self.attachments = issue.attachments.map do |attachement|
|
||||
attachement.copy(:container => self)
|
||||
end
|
||||
@copied_from = issue
|
||||
self
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user