Problem/Motivation

Imported content is matched to existing entities by UUID only. Some content is created separately on each site, such as a vocabulary loaded by a migration, so it has a different UUID on every site. Importing an export of that content creates duplicates, and imported references point at the duplicates.

#2698425 only covers entities whose UUID already exists on the site. #2962408 reported this for taxonomy terms and was closed as a duplicate of it.

Steps to reproduce

1. On site A, create a vocabulary with a field that identifies terms independently of Drupal, for example field_external_uri holding an authority URI, and create a term in it.
2. Create a node referencing that term and export it with its references, e.g. drush dcer node 1 --folder=modules/custom/example/content.
3. On site B, create the same term separately (same vocabulary, same field_external_uri value), so it has a different UUID.
4. Import the content on site B, e.g. by installing the module that ships it.
5. The vocabulary now contains the term twice, and the imported node references the new copy rather than the term site B already had.

Proposed resolution

Add an opt-in fallback to the lookup from #2698425. If no entity has the exported UUID, match one in the same bundle by configured "natural key" fields:

parameters:
default_content.natural_key_fields:
taxonomy_term:
- field_external_uri
Empty by default, so nothing changes unless a site configures it.
A matched entity keeps its local UUID and is skipped or updated like a UUID match in #2698425.
References to the exported UUID resolve to the matched entity.
If several entities match, the one with the lowest ID is used and a warning is logged.
The MR builds on !14 from #2698425.

Remaining tasks

- Land #2698425.
- Review.

User interface changes

None

API changes

- New container parameter default_content.natural_key_fields, and new service logger.channel.default_content.
- New optional ContentEntityNormalizer::__construct() arguments: $natural_key_fields and $logger.

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nchiasson created an issue.