From 22d581aa38ae4e015c654356fb61d110456e69ee Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 14:05:11 +0100 Subject: preserve tiff file --- app/controllers/trigger_controller.rb | 13 +++++++------ app/models/fax_document.rb | 12 ++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 894c18b..64a5f91 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -73,16 +73,17 @@ class TriggerController < ApplicationController next end + working_path, tiff_file = File.split(fax_document.tiff) + if fax_document.store_dir != working_path + FileUtils.mkdir(fax_document.store_dir) + FileUtils.mv(fax_document.tiff, fax_document.store_dir) + fax_document.tiff = "#{fax_document.store_dir}/#{tiff_file}" + end + fax_document.document = File.open(pdf_file) fax_document.state = 'successful' if fax_document.save - Notifications.new_fax(fax_document).deliver - begin - File.delete(tiff_file) - rescue => e - logger.error "Raw fax file could not be deleted: #{tiff_file} => #{e.inspect}" - end begin File.delete(pdf_file) rescue => e diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index e9bb5f1..5b27965 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -19,6 +19,8 @@ class FaxDocument < ActiveRecord::Base after_save :convert_to_tiff after_create :render_thumbnails + + after_destroy :remove_storage_dir # Scopes scope :inbound, where(:state => 'inbound') @@ -105,9 +107,9 @@ class FaxDocument < ActiveRecord::Base def store_dir if self.try(:inbound) - "/var/opt/gemeinschaft/fax/in/#{self.id}" + "/var/opt/gemeinschaft/fax/in/#{self.id.to_i}" else - "/var/opt/gemeinschaft/fax/out/#{self.id}" + "/var/opt/gemeinschaft/fax/out/#{self.id.to_i}" end end @@ -121,4 +123,10 @@ class FaxDocument < ActiveRecord::Base end end + def remove_storage_dir + if File.directory?(self.store_dir) + FileUtils.rm_rf(self.store_dir) + end + end + end -- cgit v1.2.3