diff --git a/app/models/web_zip_export.rb b/app/models/web_zip_export.rb index 6c16b208025..7708ce8c104 100644 --- a/app/models/web_zip_export.rb +++ b/app/models/web_zip_export.rb @@ -1,4 +1,5 @@ class WebZipExport < EpubExport + include CC::Exporter::WebZip::Exportable def export MustViewModuleProgressor.new(user, course).make_progress @@ -12,19 +13,23 @@ class WebZipExport < EpubExport end handle_asynchronously :generate, priority: Delayed::LOW_PRIORITY, max_attempts: 1 + # WebZip Exportable overrides + def content_cartridge + self.content_export.attachment + end + def convert_to_offline_web_zip begin set_locale - # TODO: connect to cameron's patchset - # file_path = super - file_path = "/Users/mysti/canvas/chaos.mov.zip" + file_path = super I18n.locale = :en + + create_attachment_from_path!(file_path) rescue => e mark_as_failed raise e end - create_attachment_from_path!(file_path) mark_as_generated cleanup_file_path!(file_path) end diff --git a/lib/cc/exporter/web_zip/exportable.rb b/lib/cc/exporter/web_zip/exportable.rb index 5679860f2d2..44931ab3b4b 100644 --- a/lib/cc/exporter/web_zip/exportable.rb +++ b/lib/cc/exporter/web_zip/exportable.rb @@ -7,9 +7,9 @@ module CC::Exporter::WebZip def convert_to_offline_web_zip exporter = CC::Exporter::WebZip::Exporter.new(content_cartridge.open, false) zip = CC::Exporter::WebZip::ZipPackage.new(exporter) - result = zip.create + file_path = zip.create || zip.empty_zip_file exporter.cleanup_files - result + file_path end end end \ No newline at end of file diff --git a/lib/cc/exporter/web_zip/zip_package.rb b/lib/cc/exporter/web_zip/zip_package.rb index 02f67cf4ebf..8a96bd6843c 100644 --- a/lib/cc/exporter/web_zip/zip_package.rb +++ b/lib/cc/exporter/web_zip/zip_package.rb @@ -1,5 +1,22 @@ module CC::Exporter::WebZip class ZipPackage < CC::Exporter::Epub::FilesDirectory + def initialize(exporter) + @files = exporter.unsupported_files + exporter.cartridge_json[:files] + @filename_prefix = exporter.filename_prefix + end + attr_reader :files + + def empty_zip_file + zip_file = Zip::File.new( + File.join(export_directory, filename), + Zip::File::CREATE + ) + tempfile = 'empty.txt' + f = File.new(tempfile, "w+") + zip_file.add(tempfile, f) { f.close } + zip_file.close + zip_file.name + end end end \ No newline at end of file diff --git a/spec/models/web_zip_export_spec.rb b/spec/models/web_zip_export_spec.rb index 2e8b10d14af..486d8f9956b 100644 --- a/spec/models/web_zip_export_spec.rb +++ b/spec/models/web_zip_export_spec.rb @@ -24,5 +24,14 @@ describe WebZipExport do web_zip_export.generate_without_send_later expect(web_zip_export.generating?).to be_truthy end + + it 'should create and associate an attachment' do + web_zip_export.export_without_send_later + web_zip_export.content_export.export_without_send_later + expect(web_zip_export.zip_attachment).to be_nil, 'precondition' + expect{web_zip_export.convert_to_offline_web_zip_without_send_later}.to change{Attachment.count}.by(1) + web_zip_export.reload + expect(web_zip_export.zip_attachment).not_to be_nil + end end end