summaryrefslogtreecommitdiff
path: root/app/controllers/trigger_controller.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-27 12:22:29 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-27 12:22:29 +0100
commit67c1a0a951403a546250ea860a3e3d199cae2fce (patch)
treef86ec6cedf081a1a57005eca1661e9bead34e4de /app/controllers/trigger_controller.rb
parent5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (diff)
parent211f558a86ae30cdd5b392ab1376e1393f97e22c (diff)
Merge branch 'develop'5.1-beta6
Diffstat (limited to 'app/controllers/trigger_controller.rb')
-rw-r--r--app/controllers/trigger_controller.rb36
1 files changed, 9 insertions, 27 deletions
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb
index 2b491be..64a5f91 100644
--- a/app/controllers/trigger_controller.rb
+++ b/app/controllers/trigger_controller.rb
@@ -1,7 +1,4 @@
class TriggerController < ApplicationController
- TIFF_FUFFIX = ".tiff"
- PDF_SUFFIX = ".pdf"
- TMP_DIR = "/tmp/"
def voicemail
if !params[:sip_account_id].blank?
@@ -68,44 +65,29 @@ class TriggerController < ApplicationController
if fax_account
fax_account.fax_documents.where(:state => 'received').each do |fax_document|
- tiff_file = File.basename(fax_document.tiff.to_s)
+ pdf_file = fax_document.tiff_to_pdf
- if !File.exists?( "#{TMP_DIR}#{tiff_file}" )
+ if !pdf_file
fax_document.state = 'unsuccessful'
fax_document.save
next
end
- paper_size = "letter"
- pdf_file = "#{TMP_DIR}#{File.basename(tiff_file, TIFF_FUFFIX)}#{PDF_SUFFIX}"
-
- system "tiff2pdf \\
- -o \"#{pdf_file}\" \\
- -p #{paper_size} \\
- -a \"#{fax_document.remote_station_id}\" \\
- -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\
- -t \"#{fax_document.remote_station_id}\" \"#{TMP_DIR}#{tiff_file}\""
-
- if !File.exists?( pdf_file )
- fax_document.state = 'unsuccessful'
- fax_document.save
- next
+ 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("#{TMP_DIR}#{tiff_file}");
- rescue => e
- logger.error "Raw fax file could not be deleted: #{TMP_DIR}#{tiff_file} => #{e.inspect}"
- end
begin
- File.delete(pdf_file);
+ File.delete(pdf_file)
rescue => e
- logger.error "PDF fax file could not be deleted: #{TMP_DIR}#{pdf_file} => #{e.inspect}"
+ logger.error "PDF fax file could not be deleted: #{pdf_file} => #{e.inspect}"
end
fax_document.tiff = nil
fax_document.save