6

I'm using the migrate module to copy data from several sources to a new drupal installation. 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.

I've tried imitating this behavior with every variation of what my machine_name should be, but the terms never seem to get associated:

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?

This version of the migrate module was released recently, I haven't found any other helpful examples on the web.

4

4 回答 4

13

这个问题似乎仍然有一些观点,所以我想我会添加我发现的其他内容。虽然接受的答案有效,但您可以在 ID 上映射词汇:

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

->separator(',')用于传递分隔的源 ID 字符串。显然,如果您正在映射一组值,请不要使用它。

于 2011-01-07T22:28:06.740 回答
1

这是我在stackoverflow上的第一篇文章,所以如果这不是提交有关此问题的更多信息的公认方式,我提前道歉......

在过去的几天里,我一直在使用 Migrate 模块,并正在寻找一种在 Drupal 7 中执行此操作的方法。我在一个我想使用的 XML 字段中有一个以逗号分隔的分类 id 列表,但是每个我发现的示例是从外部类或数据库源中检索。

无论如何,通过反复试验,我发现您可以在 migrate 类中使用字段,而不是引用外部术语迁移类。

$this->addFieldMapping('field_article_type', 'category_id')
     ->arguments(array('source_type' => 'tid'))
     ->xpath('/article/category_id')
     ->separator(',');
于 2011-03-30T16:36:44.173 回答
1

我目前正在自己​​使用 migrate 模块,并且我同意该文档在这一点上有些欠缺。:)

词汇表的“机器名称”列在词汇表中的“模块”字段中。尝试使用该值。请注意,您需要将文本输入映射,而不是 id。

于 2010-12-23T19:18:20.647 回答
0

在http://drupal.org/project/taxonomy_csv查看分类法 csv 导入模块。它易于使用,并且做了它应该做的事情等等。我最终只使用了 migrate 模块来导入 gNodes 并将这个模块用于分类。使用起来很愉快。

于 2012-02-12T04:39:06.753 回答