I'm writing migrations to import source data as paragraphs.
This is the main migration (which is working).
id: resource_chapter_section_text
label: Import content from the resource.body column in the source database as chapter_section_text paragraphs.
migration_group: redacted_web
source:
plugin: resource_chapter_section_text
key: migrate_web
process:
# a real value will be placed here by the resource_chapter_section_text_content migration
# we have to do it in a second pass to avoid creating a circular dependency
field_text/value:
plugin: default_value
default_value: 'placeholder'
field_text/format:
plugin: default_value
default_value: 'plain_text'
destination:
plugin: entity_reference_revisions:paragraph
default_bundle: chapter_section_text
dependencies:
enforced:
module:
- redacted_migration
Note that field_text
is being populated with a placeholder value. That's because the source data for that field needs to be transformed in certain ways before I can import it. In order to avoid a circular dependency, this transformation must be done after all chapter_section_text
paragraphs have been imported.
So, I'm trying to write a second migration, which will do a second pass over the same source table, and will update the paragraphs that were created by the first migration. This is that migration.
id: resource_chapter_section_text_content
label: Converts the contents of resource_chapter_section_text paragraphs from pseudo-Markdown to HTML, and updates link URLs.
migration_group: redacted_web
source:
plugin: resource_chapter_section_text_content
key: migrate_web
process:
id:
plugin: migration_lookup
migration: resource_chapter_section_text
source: section_id
field_text/value: content_converted
field_text/format:
plugin: default_value
default_value: 'full_html'
destination:
plugin: entity_reference_revisions:paragraph
default_bundle: chapter_section_text
overwrite_properties:
- field_text/value
- field_text/format
migration_dependencies:
required:
- resource_chapter_section_text
- collection_term
- document_node
- theme
- resource
dependencies:
enforced:
module:
- redacted_migration
As you can see, I'm specifying the existing paragraph ID, and using destination.overwrite_properties
to specify the fields to be updated.
I've successfully used the same technique in another migration to update existing nodes. However, it's not working here. Migrate seems to be trying to create new paragraphs instead. I get this error:
[error] Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062
Duplicate entry '3829' for key 'PRIMARY': INSERT INTO "paragraphs_item" ("id", "revision_id", "type", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4);
Is it possible to do this with paragraph entities?