我有几十个XML文件等待使用迁移模块和API导入到Drupal中。
目前,我所有的移民都是在一个名为“问题”的单一组中登记的,如下所示:

由222个导入组成的单个组代表我的XML文件的5/6。如果我导入挂起的几十个XML文件,我将有超过10,000个导入。
我想要的是每个XML文件都有自己的单独组。这样,我就可以在必要时还原单个XML文件,而不是所有XML文件。
有人能帮我解决这个问题吗?
发布于 2017-08-24 02:38:10
更新:对于D8来说,这个答案可能很好,但D7则不行。
使用迁移_加号模块,我能够为大约十几个不同的提要指定共享配置,这些提要需要在导入时根据我导入的组织媒体提供单独的分类。我用我的source和process配置创建了一个组,然后为每个提要创建了单独的导入器,只使用特定于该提要的配置。如果我想同时导入它们,我可以运行drush mi --group=<group_name>,如果我想回滚一个提要,我可以运行drush migrate-rollback <migration_name>。对我来说,唯一乏味的部分是创造了一打几乎相同的迁徙。
例如,下面是Twitter导入程序的组定义:
id: twitter_importer
source_type: twitter
shared_configuration:
source:
plugin: url
data_fetcher_plugin: http
data_parser_plugin: json
authentication:
plugin: oauth2
base_uri: 'https://api.twitter.com'
token_url: /oauth2/token
grant_type: client_credentials
fields:
-
name: id
selector: id_str
-
name: text
selector: text
-
name: timestamp
selector: created_at
ids:
id:
type: string
process:
title:
plugin: substr
source: caption
start: 0
length: 254
type:
plugin: default_value
default_value: twitter_feed_item
# etc. etc.然后有一些像这样的迁徙:
id: tw_dept_a
dependencies:
- migrate
- migrate_plus
migration_group: twitter_importer
source:
# this changes from migration to migration
urls: 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=tmountjr&count=10'
process:
field_source:
# this also changes; works because the group's shared config specifies the plugin
default_value: tmountjr
destination:
plugin: 'entity:node'在前面设置所有这些都很烦人,但是在第三次设置之后,您可以很快地复制/粘贴模板并替换一个或两个变量。
所以我想回答你的问题:
如何创建单个迁移组--每个XLM文件一个,而不必为每个文件编写一个新的迁移类?
我不确定您能否绕过that...but,您可以使用共享配置从每个单独的文件中抽象出许多重复的配置。您可以通过拥有一个带有占位符变量的模板文件,复制文件,并在新文件上使用sed替换文件名,从而进一步完善该过程:
cp migration_template.yml migrate_plus.migration.migrate_xml1.yml
sed -i "s/filenameplaceholder/file1\.xml/g" migrate_plus.migration.migrate_xml1.ymlhttps://drupal.stackexchange.com/questions/244170
复制相似问题