summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Pawlowski <julian.pawlowski@gmail.com>2013-02-18 13:14:48 +0100
committerJulian Pawlowski <julian.pawlowski@gmail.com>2013-02-18 13:14:48 +0100
commitac61082ea770d88e2ab7d9459771c25bfc73c13a (patch)
tree3f63e9e4f351734e3c8f1323ca40a750a9658b5d
parent251e15fc292deed58d1d2b4fec2ce1172c2d8f75 (diff)
parent24208a654fe65a2016244f0ebb99af66ed0bd8d7 (diff)
Merge branch 'develop' of https://github.com/amooma/GS5 into develop
-rw-r--r--app/controllers/config_snom_controller.rb2
-rw-r--r--app/controllers/trigger_controller.rb31
-rw-r--r--app/models/fax_document.rb23
3 files changed, 30 insertions, 26 deletions
diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb
index 76fa633..eb94038 100644
--- a/app/controllers/config_snom_controller.rb
+++ b/app/controllers/config_snom_controller.rb
@@ -799,7 +799,7 @@ AAAA'
end
phone_book_entry.phone_numbers.each do |phone_number|
if phone_book_entry.phone_numbers.count > 1
- entry_name = " #{phone_number.name} #{phone_number.number}"
+ entry_name = "- #{phone_number.name} #{phone_number.number}"
else
entry_name = "#{phone_book_entry.to_s} #{phone_number.number}"
end
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb
index 9a03979..7840498 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 = "/var/spool/freeswitch/"
def voicemail
if !params[:sip_account_id].blank?
@@ -68,25 +65,9 @@ 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, tiff_file = fax_document.tiff_to_pdf.blank?
- if !File.exists?( "#{TMP_DIR}#{tiff_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 )
+ if !pdf_file
fax_document.state = 'unsuccessful'
fax_document.save
next
@@ -98,14 +79,14 @@ class TriggerController < ApplicationController
if fax_document.save
Notifications.new_fax(fax_document).deliver
begin
- File.delete("#{TMP_DIR}#{tiff_file}");
+ File.delete(tiff_file)
rescue => e
- logger.error "Raw fax file could not be deleted: #{TMP_DIR}#{tiff_file} => #{e.inspect}"
+ logger.error "Raw fax file could not be deleted: #{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
diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb
index 2e37998..c73fa3d 100644
--- a/app/models/fax_document.rb
+++ b/app/models/fax_document.rb
@@ -68,6 +68,29 @@ class FaxDocument < ActiveRecord::Base
FileUtils.rm_rf tmp_dir
end
+ def tiff_to_pdf()
+ tiff_file = self.tiff.to_s.gsub(self.tiff.store_path, '')
+ if !File.exists?(tiff_file)
+ return nil
+ end
+
+ working_path, file_name = File.split(tiff_file)
+ pdf_file = "#{working_path}/#{File.basename(tiff_file, '.tiff')}.pdf"
+
+ system "tiff2pdf \\
+ -o \"#{pdf_file}\" \\
+ -p letter \\
+ -a \"#{self.remote_station_id}\" \\
+ -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\
+ -t \"#{self.remote_station_id}\" \"#{tiff_file}\""
+
+ if !File.exists?(pdf_file)
+ return nil
+ end
+
+ return pdf_file, tiff_file
+ end
+
private
def convert_pdf_to_tiff
page_size_a4 = '595 842'