我在下面编写了Drupal 8 migration yml配置,以导入和创建分类词汇。这是自定义实体的迁移依赖项脚本。在我的数据集中,标记不是唯一的,因为它们分配给了不同的帐户。我需要的是创建具有唯一术语的词汇表。在底部查看最终结果。
我的数据源:
TagRelId,TagName,TagId,TagCat,AccountId,TargetEntityType
a9d100fb440b,Front End,a345012d20d1,,89d3b52a,Accounts
8af9efb2,Full Stack,a50e01555656,Skills,89d3b52a,Accounts
2ae5c16d,Front End,a345012d20d1, ef718f66,Accounts
我的配置:
id: skills
label: Imports all Skills per Account.
migration_group: migrate_basic
migration_tags:
- skills
# Source.
source:
plugin: csv
path: 'public://import/_combinedTagsAccountsSkills.csv'
header_row_count: 1
# Unique ID.
keys:
- TagRelId
# Source field definitions.
fields:
TagRelId: Unique a Tag Relationship ID.
TagName: The tag name.
TagId: The unique Tag ID.
TagCat: The Tag category (Skills)
AccountId: unique ID for the related account entity.
TargetEntityType: The Target entity type (Accounts).
# Destination.
destination:
plugin: entity:taxonomy_term
# Vocabulary for the terms.
default_bundle: tech_stack
# Mappings.
process:
# tech_stack is the Field to be populated in my custom account entity
tech_stack:
plugin: entity_generate
# Field from source configuration
source: TagName
# Value to compare in the bundle
value_key: name
bundle_key: vid
# Bundle machine name
bundle: tech_stack
# Type of entity
entity_type: taxonomy_term
# Set to true to ignore case on lookup
ignore_case: true
# Dependencies.
dependencies:
enforced:
module:
- migrate_module
除了创建正确的术语外,我还有带有随机数值的额外术语。我的源代码中的总行数与创建的术语数相对应。名称属性应包含术语名称,而不是数字值。
┌──────────────────────────────────────────────────────────────────────────────┐
│ $Source │
└──────────────────────────────────────────────────────────────────────────────┘
array (17) [
'TagRelId' => string (36) "6aebbfa4-4fc2-4496-a76e-a9d100fb440b"
'TagName' => string (9) "Front End"
'TagId' => string (36) "9faaa97b-ace2-4875-b403-a345012d20d1"
'TagCat' => string (0) ""
'AccountId' => string (36) "89d3b52a-40e9-47bc-9872-a78a012e0ff8"
'TargetEntityType' => string (8) "Accounts"
'fields' => array (6) [
'TagRelId' => string (35) "Unique Crelate Tag Relationship ID."
'TagName' => string (13) "The tag name."
'TagId' => string (18) "The unique Tag ID."
'TagCat' => string (25) "The Tag category (Skills)"
'AccountId' => string (49) "Crelate unique ID for the related account entity."
'TargetEntityType' => string (34) "The Target entity type (Accounts)."
]
'keys' => array (1) [
string (8) "TagRelId"
]
'column_names' => array (0)
'header_row_count' => integer 1
'file_flags' => integer 15
'delimiter' => string (1) ","
'enclosure' => string (1) """
'escape' => string (1) "\"
'path' => string (55) "public://import/crelate/_combinedTagsAccountsSkills.csv"
'file_class' => string (39) "Drupal\migrate_source_csv\CSVFileObject"
'plugin' => string (3) "csv"
]
┌──────────────────────────────────────────────────────────────────────────────┐
│ $Destination │
└──────────────────────────────────────────────────────────────────────────────┘
array (2) [
'name' => string (2) "63"
'vid' => string (10) "tech_stack"
]
┌──────────────────────────────────────────────────────────────────────────────┐
│ $DestinationIDValues │
└──────────────────────────────────────────────────────────────────────────────┘
array (1) [
string (3) "916"
]