diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-08-21 14:19:44 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-09-16 12:42:19 +0100 |
commit | 5b42308b116ee0bbdecf3f1c0e1c5f0c0e25b757 (patch) | |
tree | aa3e75d0bfaaf2f2c8c6436dfea69c6ffc58c7cd /app/controllers/request_controller.rb | |
parent | ef17ef91cd3a7bf109a6a9e9c845e1bea6ea9edf (diff) |
Move zip file creation to its own method.
Diffstat (limited to 'app/controllers/request_controller.rb')
-rw-r--r-- | app/controllers/request_controller.rb | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 86ee4552d..17b836f8f 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -886,22 +886,7 @@ class RequestController < ApplicationController file_path = File.expand_path(File.join(download_zip_dir(), @url_path)) if !File.exists?(file_path) FileUtils.mkdir_p(File.dirname(file_path)) - Zip::ZipFile.open(file_path, Zip::ZipFile::CREATE) { |zipfile| - - file_info = make_request_summary_file(@info_request) - zipfile.get_output_stream(file_info[:filename]) { |f| f.puts(file_info[:data]) } - - for message in @info_request.incoming_messages - next unless message.user_can_view?(authenticated_user) - attachments = message.get_attachments_for_display - for attachment in attachments - filename = "#{attachment.url_part_number}_#{attachment.display_filename}" - zipfile.get_output_stream(filename) { |f| - f.puts(attachment.body) - } - end - end - } + make_request_zip(info_request, file_path) File.chmod(0644, file_path) end redirect_to @url_path @@ -941,6 +926,20 @@ class RequestController < ApplicationController @last_response = info_request.get_last_response end + def make_request_zip(info_request, file_path) + Zip::ZipFile.open(file_path, Zip::ZipFile::CREATE) do |zipfile| + file_info = make_request_summary_file(info_request) + zipfile.get_output_stream(file_info[:filename]) { |f| f.puts(file_info[:data]) } + info_request.incoming_messages.each do |message| + next unless message.user_can_view?(authenticated_user) + message.get_attachments_for_display.each do |attachment| + filename = "#{attachment.url_part_number}_#{attachment.display_filename}" + zipfile.get_output_stream(filename) { |f| f.puts(attachment.body) } + end + end + end + end + def make_request_summary_file(info_request) done = false convert_command = AlaveteliConfiguration::html_to_pdf_command |