@@ -46,6 +46,8 class Attachment < ActiveRecord::Base | |||||
46 | cattr_accessor :storage_path |
|
46 | cattr_accessor :storage_path | |
47 | @@storage_path = Redmine::Configuration['attachments_storage_path'] || "#{Rails.root}/files" |
|
47 | @@storage_path = Redmine::Configuration['attachments_storage_path'] || "#{Rails.root}/files" | |
48 |
|
48 | |||
|
49 | before_save :files_to_final_location | |||
|
50 | ||||
49 | def validate_max_file_size |
|
51 | def validate_max_file_size | |
50 | if self.filesize > Setting.attachment_max_size.to_i.kilobytes |
|
52 | if self.filesize > Setting.attachment_max_size.to_i.kilobytes | |
51 | errors.add(:base, :too_long, :count => Setting.attachment_max_size.to_i.kilobytes) |
|
53 | errors.add(:base, :too_long, :count => Setting.attachment_max_size.to_i.kilobytes) | |
@@ -73,7 +75,7 class Attachment < ActiveRecord::Base | |||||
73 |
|
75 | |||
74 | # Copies the temporary file to its final location |
|
76 | # Copies the temporary file to its final location | |
75 | # and computes its MD5 hash |
|
77 | # and computes its MD5 hash | |
76 | def before_save |
|
78 | def files_to_final_location | |
77 | if @temp_file && (@temp_file.size > 0) |
|
79 | if @temp_file && (@temp_file.size > 0) | |
78 | logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)") |
|
80 | logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)") | |
79 | md5 = Digest::MD5.new |
|
81 | md5 = Digest::MD5.new |
General Comments 0
You need to be logged in to leave comments.
Login now