简体   繁体   English

如何使用Drupal Migrate添加分类术语

[英]How do I add taxonomy terms using Drupal Migrate

I'm using the migrate module to copy data from several sources to a new drupal installation. 我正在使用migration模块将数据从多个来源复制到新的drupal安装中。 So far, I'm able to replicate a lot of what I need from the examples provided with the module. 到目前为止,我已经可以从模块随附的示例中复制很多我需要的内容。 I'm currently stuck on adding terms or taxonomy to newly created nodes. 我目前一直在为新创建的节点添加术语或分类法。 The example shows: 该示例显示:

// These are related terms, which by default will be looked up by name
$this->addFieldMapping('migrate_example_beer_styles', 'terms')
     ->separator(',');

I've tracked down the migrate_example_beer_styles destination mapping and it seems to be the machine name for that taxonomy. 我已经找到了migrate_example_beer_styles目标映射,它似乎是该分类法的machine name

I've tried imitating this behavior with every variation of what my machine_name should be, but the terms never seem to get associated: 我尝试模仿我的machine_name应该是什么的每种形式的这种行为,但是这些术语似乎从未关联起来:

By id: 按编号:

// where source breed_id is '1,100' - it finds mapped values accordingly
$this->addFieldMapping('breeds', 'breed_id')
     ->sourceMigration('BreedMigration')
     ->separator(',')

And, by name: 并且,按名称:

// where source breeds is 'Dogs,German Shepherd'
$this->addFieldMapping('breeds', 'breeds')
     ->separator(',');

Am I wrong assuming the destination mapping is the machine name for a taxonomy? 假设目标映射是分类法的machine name ,我错了吗?

This version of the migrate module was released recently, I haven't found any other helpful examples on the web. 此版本的migration模块是最近发布的,我在网上找不到其他有用的示例。

This question still seems to be getting some views, so I thought I'd add what else I've discovered. 这个问题似乎仍然有一些看法,所以我想我还要补充发现的内容。 While the accepted answer works, you are able to map Vocabs on ID: 在接受的答案有效的同时,您可以将Vocabs映射到ID:

$this->addFieldMapping('Exact Case Sensitive Vocab Name', 'source_field_name')
     ->sourceMigration('ExactSourceClassName')
     ->arguments(array('source_type' => 'tid'))
     ->separator(',');

->separator(',') used for passing a delimited string of source ids. ->separator(',')用于传递定界的源ID字符串。 Obviously, leave that off if you're mapping an array of values. 显然,如果要映射值数组,则不要选择该选项。

I'm currently working with migrate module myself, and I agree that the documentation is somewhat wanting at this point. 我目前正在自己​​处理迁移模块,并且我同意此时需要一些文档。 :) :)

The 'machine name' of a vocabulary is listed in the Vocabulary table, in the field 'module'. 词汇表的“模块名称”列在“词汇表”中。 Try using that value. 尝试使用该值。 Do note that you need to feed the text into the mapping, not the ids. 请注意,您需要将文本(而不是ID)输入到映射中。

This is my first post on stackoverflow, so I apologize in advance if this isn't the accepted way to submit more information concerning this issue... 这是我关于stackoverflow的第一篇文章,因此,如果这不是提交有关此问题的更多信息的可接受方式,我要向您道歉...

I've been stumbling around with the Migrate module for the past few days and was looking for a way to do this in Drupal 7. I had a comma-delimited list of taxonomy ids within an XML field that I wanted to use, but every example I found was retrieving from an external class, or from a database source. 在过去的几天里,我一直在尝试着使用Migrate模块,并在Drupal 7中寻找一种方法。在XML字段中,我想使用一个用逗号分隔的分类法ID列表,但是每个我发现的示例是从外部类或数据库源检索的。

Anyway, through trial and error, I found that you can use a field within the migrate class, rather than reference an external term migration class. 无论如何,通过反复试验,我发现您可以在migration类中使用字段,而不是引用外部术语migration类。

$this->addFieldMapping('field_article_type', 'category_id')
     ->arguments(array('source_type' => 'tid'))
     ->xpath('/article/category_id')
     ->separator(',');

Check out the taxonomy csv import module at http://drupal.org/project/taxonomy_csv . http://drupal.org/project/taxonomy_csv上检查分类csv导入模块。 It was easy to use and did what it was supposed to and more. 它易于使用,可以完成预期的工作,甚至更多。 I ended up only using the migrate module for importin gNodes and used this module for the taxonomy. 我最终仅将Migration模块用于gNode的导入,并将该模块用于分类。 It was a pleasure to use. 使用是一种乐趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM