Sha256: d3164958e38c23e538cbd7d281eface0fd9eb768e743a6069b70b93de9658a15
Contents?: true
Size: 1.6 KB
Versions: 36
Compression:
Stored size: 1.6 KB
Contents
module Pageflow module EntryExportImport # Uploads a file attachment associated with an ReusableFile # and publishes the file afterwards class UploadAndPublishFileJob < ApplicationJob queue_as :file_upload def perform(reusable_file, exported_id, archive_file_name) archive = ZipArchive.new(archive_file_name) reusable_file.attachments_for_export.each do |attachment| archive_path = AttachmentFiles.archive_path(reusable_file, attachment, exported_id: exported_id) archive.extract_to_tempfile(archive_path) do |tempfile| # Paperclip skips post processing anyway since the name of # the tempfile does not pass the validation defined in # UploadableFile. To be explicit, we disable post # processing manually as well. attachment.post_processing = false attachment.assign(tempfile) # Calling `attachment.assign` changes the # `<attachment-name>_file_name` attribute based on the # name of the tempfile. To prevent `flush_writes` from # using these new values when constructing the # destionation path, we need to undo the attribute # changes. Restoring the attributes does not reset the # list of files queued for write in the attachment. reusable_file.restore_attributes attachment.flush_writes end end reusable_file.publish! end end end end
Version data entries
36 entries across 36 versions & 1 rubygems