Sha256: 99211c124fe3785d65e7fb53d37ef78953abc399600be1759aa8cc346b920e8e

Contents?: true

Size: 1.37 KB

Versions: 36

Compression:

Stored size: 1.37 KB

Contents

module Pageflow
  module EntryExportImport
    extend self

    def export(entry, archive_file_path)
      archive = ZipArchive.new(archive_file_path)
      publication = most_recent_publication(entry)

      archive.add('entry.json', StringIO.new(EntrySerialization.dump(entry, publication).to_json))

      AttachmentFiles.download_and_archive_originals(entry.draft, archive)
      AttachmentFiles.download_and_archive_originals(publication, archive) if publication

      archive.close
    end

    def import(archive_file_path, creator:)
      archive = ZipArchive.new(archive_file_path)
      file_mappings = FileMappings.new

      entry = extract_entry(archive, creator, file_mappings)
      AttachmentFiles.extract_and_upload_originals(entry,
                                                   archive_file_path,
                                                   file_mappings)
      entry
    end

    private

    def extract_entry(archive, creator, file_mappings)
      archive.extract_to_tempfile('entry.json') do |tempfile|
        EntrySerialization.import(JSON.parse(tempfile.read),
                                  creator: creator,
                                  account: creator.accounts.first,
                                  file_mappings: file_mappings)
      end
    end

    def most_recent_publication(entry)
      entry.revisions.publications.first
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

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