Module: Pageflow::EntryExportImport

Extended by:
EntryExportImport
Included in:
EntryExportImport
Defined in:
lib/pageflow/entry_export_import.rb,
lib/pageflow/entry_export_import/zip_archive.rb,
lib/pageflow/entry_export_import/file_mappings.rb,
lib/pageflow/entry_export_import/attachment_files.rb,
lib/pageflow/entry_export_import/page_type_versions.rb,
lib/pageflow/entry_export_import/entry_serialization.rb,
lib/pageflow/entry_export_import/revision_serialization.rb,
lib/pageflow/entry_export_import/revision_serialization/import.rb,
app/jobs/pageflow/entry_export_import/upload_and_publish_file_job.rb

Defined Under Namespace

Modules: AttachmentFiles, EntrySerialization, PageTypeVersions, RevisionSerialization Classes: FileMappings, UploadAndPublishFileJob, ZipArchive

Instance Method Summary collapse

Instance Method Details

#export(entry, archive_file_path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/pageflow/entry_export_import.rb', line 5

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

#import(archive_file_path, creator:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/pageflow/entry_export_import.rb', line 17

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