2017-06-03 36 views
0

我試圖從CSV文件中使用內核的遷移模塊,遷移源CSV,遷移工具和遷移來填充新的Drupal 8(8.3.2)網站加。我可以用單個圖像成功導入每個節點,但我不確定如何將多個圖像遷移到節點的多值圖像字段中。Drupal 8 - 從多個值CSV遷移圖像字段

我模塊目前看起來是這樣的:

id: product_data 
label: Products 
migration_group: product_migration 
migration_tags: 
    - node 
    - product 
source: 
    plugin: csv 
    path: 'public://import/products/products.full.csv' 
    header_row_count: 1 
    keys: 
    - product_sku 
    constants: 
    bool_0: 0 
    bool_1: 1 
    uid_root: 1 
    restricted_html: restricted_html 
destination: 
    plugin: 'entity:node' 
    default_bundle: product 
process: 
    title: product_name 
    field_sku: product_sku 
    sticky: constants/bool_0 
    promote: constants/bool_1 
    uid: constants/uid_root 
    'field_image/target_id': 
     plugin: migration 
     migration: product_image 
     source: product_full_image 
migration_dependencies: 
    optional: 
    - product_image 
dependencies: 
    enforced: 
    module: 
     - custom_migration 

以及創建圖像的實體:

id: product_image 
label: Images associated with a product. 
migration_group: product_migration 
migration_tags: 
    - product 
    - file 
    - image 
source: 
    plugin: csv 
    path: 'public://import/products/products.full.csv' 
    header_row_count: 1 
    keys: 
    - product_full_image 
    fields: 
    product_full_image: Name of the image file associated with the program. 
    constants: 
    file_source_uri: public://import/products/old-images 
    file_dest_uri: 'public://program/image' 
destination: 
    plugin: 'entity:file' 
process: 
    file_source: 
    - 
     plugin: concat 
     delimiter:/
     source: 
     - constants/file_source_uri 
     - product_full_image 
    - 
     plugin: urlencode 
    file_dest: 
    - 
     plugin: concat 
     delimiter:/
     source: 
     - constants/file_dest_uri 
     - product_full_image 
    - 
     plugin: urlencode 
    filename: product_full_image 
    uri: 
    plugin: file_copy 
    source: 
     - '@file_source' 
     - '@file_dest' 
dependencies: 
    enforced: 
    module: 
     - custom_migration 

以及CSV文件的格式是這樣的:

product_sku,product_name,product_full_image 
C242,couch,Blue Couch,"image1.jpg,image2.jpg" 
C243,chair,Red Chair,image3.jpg 

我我嘗試過使用expload和iterator插件,但老實說我完全迷失在這裏。任何想法將不勝感激。

+0

您是否已經找到解決方案? –

回答

0

我能想出來 - 希望這可以幫助其他人在同一條船上。我最後的遷移是這樣的:

主要模塊:

id: product_data 
label: Products 
migration_group: product_migration 
migration_tags: 
    - node 
    - product 
source: 
    plugin: csv 
    path: 'public://import/products/products.full.csv' 
    header_row_count: 1 
    keys: 
    - product_sku 
    constants: 
    bool_0: 0 
    bool_1: 1 
    uid_root: 1 
    restricted_html: restricted_html 
destination: 
    plugin: 'entity:node' 
    overwrite_properties: 
    - field_image 
    default_bundle: product 
process: 
    field_image: 
    - 
     plugin: explode 
     delimiter: ; 
     source: image 
    - 
     plugin: migration 
     migration: product_image 
     no_stub: true 
migration_dependencies: 
    optional: 
    - product_image 
dependencies: 
    enforced: 
    module: 
     - custom_migration 

上面提到的 'products.full.csv' 文件lookes這樣的:

product_sku,product_name,image 
C242,Blue Couch,image1.jpg;image2.jpg;image3.jpg 
C243,Red Chair,image4.jpg 

要導入和創建的所有實體的圖像:

id: product_image 
label: Import all product images. 
migration_group: product_migration 
migration_tags: 
    - product 
    - file 
    - image 
source: 
    plugin: csv 
    path: 'public://import/products/images.csv' 
    header_row_count: 1 
    keys: 
    - image 
    fields: 
    new_image: Name of the image file associated with the program. 
    constants: 
    file_source_uri: public://import/products/images 
    file_dest_uri: 'public://program/image' 
destination: 
    plugin: 'entity:file' 
process: 
    file_source: 
    - 
     plugin: concat 
     delimiter:/
     source: 
     - constants/file_source_uri 
     - new_image 
    - 
     plugin: urlencode 
    file_dest: 
    - 
     plugin: concat 
     delimiter:/
     source: 
     - constants/file_dest_uri 
     - new_image 
    - 
     plugin: urlencode 
    filename: new_image 
    uri: 
    plugin: file_copy 
    source: 
     - '@file_source' 
     - '@file_dest' 
dependencies: 
    enforced: 
    module: 
     - custom_migration 

上面引用的'images.csv'文件只有一列,並且是強制t爲每行創建一個實體的直接列表:

image 
image1.jpg 
image2.jpg 
image3.jpg 
image4.jpg