diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:01:45 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:01:45 +0100 |
commit | b80bd744ad873f6fc43018bc4bfb90677de167bd (patch) | |
tree | 072c4b0e33d442528555b82c415f5e7a1712b2b0 /lib/tasks/send_fax_notifications.rake | |
parent | 3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff) |
Start of GS5.
Diffstat (limited to 'lib/tasks/send_fax_notifications.rake')
-rw-r--r-- | lib/tasks/send_fax_notifications.rake | 49 |
1 files changed, 49 insertions, 0 deletions
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 |