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

Version Path
pageflow-17.0.4 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-17.0.3 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-17.0.2 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-17.0.1 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-17.0.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-16.2.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-16.1.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-16.0.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.8.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.7.1 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.7.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.6.1 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.6.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.5.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.4.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.3.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.2.2 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.2.1 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.2.0 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb
pageflow-15.1.2 app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb