I'm currently trying to migrate a Wordpress blog to contentful. The new contentful space will have the content model posts which has a many reference field "sections" which will then consist of different other content models (text, youtube embed etc). To make the import fairly simple I've also added a "legacy content" model which has a text "html" field. The import should now take all posts, import them into contentful with their title and slug and then use the wordpress html content to create the legacy content entries. Those entries should be connected to the post of course.
So the legacy content entry with the id 555 should be linked to the sections field of the post with the id 555.
require 'contentful/database_importer'
class LegacyContent
include Contentful::DatabaseImporter::Resource
self.table_name = 'dQiVHYroposts' # Optional - By default it's the class name in snake case. E.g. 'my_table'
self.content_type_id = 'legacyContent' # Optional - By default it's the class name in snake case. E.g 'my_table'
self.content_type_name = 'Legacy Content' # Optional - By default it's the class name
self.query = "post_type = 'post' AND post_status = 'publish' AND post_content != ''"
id Contentful::DatabaseImporter::IdGenerator::Base#, template: '{{content_type_id}}_{{id}}'
field :post_title, maps_to: :title, type: :string
field :post_content, maps_to: :html, type: :text
end
class Posts
include Contentful::DatabaseImporter::Resource
self.table_name = 'dQiVHYroposts' # Optional - By default it's the class name in snake case. E.g. 'my_table'
self.content_type_id = 'post' # Optional - By default it's the class name in snake case. E.g 'my_table'
self.content_type_name = 'Post' # Optional - By default it's the class name
self.query = "post_type = 'post' AND post_status = 'publish' AND post_content != ''"
id Contentful::DatabaseImporter::IdGenerator::Base#, template: ''#, template: '{{content_type_id}}_{{id}}'
field :post_title, maps_to: :title, type: :string
field :post_name, maps_to: :slug, type: :string
field :post_excerpt, maps_to: :sharing_description, type: :text
field :sections, type: LegacyContent, relationship: :many, id_field: :id, key: :id
end
Contentful::DatabaseImporter.setup do |config|
config.space_name = 'testspace'
config.space_id = '3bh67gu8ux38'
config.database_connection = 'mysql2://root@localhost:3306/diffus'
end
What I struggle with is using this code the sections will not end up as references but as JSON objects and the contentful web app then says that the widget for that type is not available.
If I remove the sections field after that and add is as a many reference field and run the import (udpate_space!) again the legacy content will be referenced with in the sections field of each post BUT post_0 will have legacy_content_0, post_1 legacy_content_0 and so on.
I'm currently trying to migrate a Wordpress blog to contentful. The new contentful space will have the content model posts which has a many reference field "sections" which will then consist of different other content models (text, youtube embed etc). To make the import fairly simple I've also added a "legacy content" model which has a text "html" field. The import should now take all posts, import them into contentful with their title and slug and then use the wordpress html content to create the legacy content entries. Those entries should be connected to the post of course.
So the legacy content entry with the id 555 should be linked to the sections field of the post with the id 555.
What I struggle with is using this code the sections will not end up as references but as JSON objects and the contentful web app then says that the widget for that type is not available.
If I remove the sections field after that and add is as a many reference field and run the import (udpate_space!) again the legacy content will be referenced with in the sections field of each post BUT post_0 will have legacy_content_0, post_1 legacy_content_0 and so on.
Currently:
Should be: