Module: Pageflow::EntryExportImport::EntrySerialization

Extended by:
EntrySerialization
Included in:
EntrySerialization
Defined in:
lib/pageflow/entry_export_import/entry_serialization.rb

Constant Summary collapse

DEFAULT_REMOVAL_COLUMNS =
%w[id updated_at].freeze

Instance Method Summary collapse

Instance Method Details

#dump(entry, publication = nil) ⇒ Object

Turn entry into JSON compatible data structure.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pageflow/entry_export_import/entry_serialization.rb', line 9

def dump(entry, publication = nil)
  {
    'page_type_versions' => PageTypeVersions.dump,
    # features_configuration is specifically excluded via `Entry#blacklist_for_serialization`
    # to prevent it from showing up in Active Admin JSON exports.
    # It is included separately as part of the entry export.
    'entry' => entry
      .as_json(except: [:folder_id, :password_digest, :users_count])
      .merge('features_configuration' => entry.features_configuration,
             'draft' => RevisionSerialization.dump(entry.draft),
             'last_publication' => dump_publication(publication))
  }
end

#import(data, options) ⇒ Object

Create entry from serialized JSON export



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pageflow/entry_export_import/entry_serialization.rb', line 24

def import(data, options)
  PageTypeVersions.verify_compatibility!(data['page_type_versions'])

  entry_data = data['entry']
  entry = create_entry(entry_data.except('draft', 'last_publication'), options)

  file_mappings = options.fetch(:file_mappings, FileMappings.new)

  import_draft(entry_data, options, entry, file_mappings)
  import_last_publication(entry_data, options, entry, file_mappings)

  entry
end