From b80bd744ad873f6fc43018bc4bfb90677de167bd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 17 Dec 2012 12:01:45 +0100 Subject: Start of GS5. --- lib/tasks/send_fax_notifications.rake | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/tasks/send_fax_notifications.rake (limited to 'lib/tasks/send_fax_notifications.rake') diff --git a/lib/tasks/send_fax_notifications.rake b/lib/tasks/send_fax_notifications.rake new file mode 100644 index 0000000..039c509 --- /dev/null +++ b/lib/tasks/send_fax_notifications.rake @@ -0,0 +1,49 @@ +# encoding: UTF-8 + +desc "Import inbound fax" + +task :send_fax_notifications => :environment do + FaxDocument.where(:state => 'received').each do |fax_document| + TIFF_FUFFIX = ".tiff" + PDF_SUFFIX = ".pdf" + TMP_DIR = "/tmp/" + + tiff_file = File.basename(fax_document.tiff.to_s) + + 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 #{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 + end + + fax_document.document = File.open(pdf_file) + fax_document.state = 'successful' + + if fax_document.save + Notifications.new_fax(fax_document).deliver + File.delete("#{TMP_DIR}#{tiff_file}"); + File.delete(pdf_file); + fax_document.tiff = nil + fax_document.save + else + fax_document.state = 'unsuccessful' + fax_document.save + end + end +end -- cgit v1.2.3