6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/models/presentation_observer.rb', line 6
def after_save(presentation)
Rails.logger.info "Executing PresentationObserver after_save hook (#{__FILE__}:#{__LINE__})"
compressed_file = presentation.contents.path
destination_path = File.join(File.dirname(presentation.contents.path),
Presentation::UNPACKED_DIRNAME)
if File.exists?(destination_path)
Paperclip.run("rm", "-rf #{destination_path}")
end
Dir.mktmpdir {|tmpdir_path|
Rails.logger.info "Temporarily unpacking presentation into #{tmpdir_path}"
Paperclip.run("unzip", "#{compressed_file} -d #{tmpdir_path}")
index_container = Find.find(tmpdir_path) do |file|
break File.dirname(file) if file =~ /index\.html/
end
if index_container.blank?
Rails.logger.warn "No index.html file found in uploaded zipfile for presentation with ID of #{presentation.id}! Skipping."
else
Rails.logger.info "Moving #{index_container} to #{destination_path}"
FileUtils.move index_container, destination_path
Presentation.update_all({:unzipped_location => destination_path}, {:id => presentation.id})
end
Rails.logger.info "Uncompressing uploaded presentation completed successfully."
}
end
|