summaryrefslogtreecommitdiff
path: root/app/models/fax_document.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-16 11:10:02 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-16 11:10:02 +0100
commit5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (patch)
tree49ed889b1d10cda98c475f3453abff1b97afb4e7 /app/models/fax_document.rb
parentc9066760fd1f5f2f892ce2be5cf2a83bb5210246 (diff)
parent55784bcffc0678ce6102c0b81447434a8030ebd2 (diff)
Merge branch 'develop'5.1-beta5
Diffstat (limited to 'app/models/fax_document.rb')
-rw-r--r--app/models/fax_document.rb32
1 files changed, 17 insertions, 15 deletions
diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb
index be689e2..564d3bb 100644
--- a/app/models/fax_document.rb
+++ b/app/models/fax_document.rb
@@ -18,8 +18,8 @@ class FaxDocument < ActiveRecord::Base
has_many :fax_thumbnails, :order => :position, :dependent => :destroy
- after_create :render_thumbnails
after_create :convert_pdf_to_tiff
+ after_create :render_thumbnails
# Scopes
scope :inbound, where(:state => 'inbound')
@@ -47,23 +47,25 @@ class FaxDocument < ActiveRecord::Base
transition [:new] => :inbound
end
end
-
+
def to_s
- name
+ "#{self.remote_station_id}-#{self.created_at}-#{self.id}".gsub(/[^a-zA-Z0-9]/,'')
end
-
+
def render_thumbnails
- directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/fax_thumbnails/#{self.id}"
- system('mkdir -p ' + directory)
- system("cd #{directory} && convert #{Rails.root.to_s}/public#{self.document.to_s}[0-100] -colorspace Gray PNG:'fax_page.png'")
- number_of_thumbnails = Dir["#{directory}/fax_page-*.png"].count
- (0..(number_of_thumbnails-1)).each do |i|
+ self.delay.create_thumbnails_and_save_them
+ end
+
+ def create_thumbnails_and_save_them
+ tmp_dir = "/tmp/fax_convertions/#{self.id}"
+ FileUtils.mkdir_p tmp_dir
+ system("cd #{tmp_dir} && convert #{self.document.path} -colorspace Gray PNG:'fax_page.png'")
+ Dir.glob("#{tmp_dir}/fax_page*.png").each do |thumbnail|
fax_thumbnail = self.fax_thumbnails.build
- fax_thumbnail.thumbnail = File.open("#{directory}/fax_page-#{i}.png")
- fax_thumbnail.save!
+ fax_thumbnail.thumbnail = File.open(thumbnail)
+ fax_thumbnail.save
end
- system("rm -rf #{directory}")
- self.update_attributes(:document_total_pages => number_of_thumbnails) if self.document_total_pages.nil?
+ FileUtils.rm_rf tmp_dir
end
private
@@ -71,12 +73,12 @@ class FaxDocument < ActiveRecord::Base
page_size_a4 = '595 842'
page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice"
directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}"
- system('mkdir -p ' + directory)
+ FileUtils.mkdir_p directory
tiff_file_name = File.basename(self.document.to_s.downcase, ".pdf") + '.tiff'
system "cd #{directory} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file_name}\" -c \"#{page_size_command}\" -- \"#{Rails.root.to_s}/public#{self.document.to_s}\""
self.tiff = File.open("#{directory}/#{tiff_file_name}")
self.save
- system("rm -rf #{directory}")
+ FileUtils.rm_rf directory
end
end