summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/trigger_controller.rb13
-rw-r--r--app/models/fax_document.rb12
2 files changed, 17 insertions, 8 deletions
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