Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 8-使用多个值从CSV迁移图像字段_Csv_Migration_Drupal 8 - Fatal编程技术网

Drupal 8-使用多个值从CSV迁移图像字段

Drupal 8-使用多个值从CSV迁移图像字段,csv,migration,drupal-8,Csv,Migration,Drupal 8,我正在尝试使用core的Migrate模块、Migrate Source CSV、Migrate Tools和Migrate Plus,用CSV文件中的内容填充一个新的Drupal 8(8.3.2)站点。我能够使用单个图像成功导入每个节点,但我不确定如何将多个图像迁移到节点的多值图像字段中 我的模块当前看起来如下所示: id: product_data label: Products migration_group: product_migration migration_tags: - n

我正在尝试使用core的Migrate模块、Migrate Source CSV、Migrate Tools和Migrate Plus,用CSV文件中的内容填充一个新的Drupal 8(8.3.2)站点。我能够使用单个图像成功导入每个节点,但我不确定如何将多个图像迁移到节点的多值图像字段中

我的模块当前看起来如下所示:

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
product_sku,product_name,product_full_image
C242,couch,Blue Couch,"image1.jpg,image2.jpg"
C243,chair,Red Chair,image3.jpg
product_sku,product_name,image
C242,Blue Couch,image1.jpg;image2.jpg;image3.jpg
C243,Red Chair,image4.jpg
要创建图像实体,请执行以下操作:

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文件的格式如下:

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
product_sku,product_name,product_full_image
C242,couch,Blue Couch,"image1.jpg,image2.jpg"
C243,chair,Red Chair,image3.jpg
product_sku,product_name,image
C242,Blue Couch,image1.jpg;image2.jpg;image3.jpg
C243,Red Chair,image4.jpg

我曾尝试使用expload和迭代器插件,但老实说,我完全迷路了。任何想法都将不胜感激。

我能够解决这个问题——希望这能帮助同舟共济的其他人。我的最后一次迁移如下所示:

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
product_sku,product_name,product_full_image
C242,couch,Blue Couch,"image1.jpg,image2.jpg"
C243,chair,Red Chair,image3.jpg
product_sku,product_name,image
C242,Blue Couch,image1.jpg;image2.jpg;image3.jpg
C243,Red Chair,image4.jpg
主要模块:

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”文件如下所示:

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
product_sku,product_name,product_full_image
C242,couch,Blue Couch,"image1.jpg,image2.jpg"
C243,chair,Red Chair,image3.jpg
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”文件只有一列,只是要为其创建实体的所有图像的直接列表,每行一个:

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

你已经找到解决办法了吗?