Community Documentation

Taxonomy term migration

Last updated October 22, 2012. Created by mikeryan on October 22, 2012.
Log in to edit this page.

In migrating taxonomy terms, the key is mapping the legacy vocabulary to the destination vocabulary. Note that up till now we've dealt with classes that you will generally instantiate once - this is our first example of classes you would instantiate multiple times, one for each vocabulary to migrate.

  • source_vocabulary: The unique identifier of the legacy vocabulary (a machine name in Drupal 7, or a vid for earlier Drupal versions).
  • destination_vocabulary: The unique machine name of the destination vocabulary.

<?php
// In this example, we're consolidating two legacy vocabularies into one
$photo_term_arguments = $common_arguments + array(
 
'machine_name' => 'ExamplePhotoTerm',
 
'description' => t('Import Drupal 6 photo terms into media terms'),
 
'source_vocabulary' => '3'// "Photo category" vocabulary
 
'destination_vocabulary' => 'media_category',
);
Migration::registerMigration('DrupalTerm6Migration',
 
$photo_term_arguments['machine_name'], $photo_term_arguments);

$video_term_arguments = $common_arguments + array(
 
'machine_name' => 'ExampleVideoTerm',
 
'description' => t('Import Drupal 6 video terms into media terms'),
 
'source_vocabulary' => '5'// "Video category" vocabulary
 
'destination_vocabulary' => 'media_category',
);
Migration::registerMigration('DrupalTerm6Migration',
 
$video_term_arguments['machine_name'], $video_term_arguments);
?>

Comments

Mapping them to nodes

This works great to import the terms themselves (using 6.x-2.0-rc1), but mapping them to nodes seems to be a bit tricky. Here's the pattern I have seen to make this work, assuming that the vocabulary ID on the source Drupal 6 system was 1 (which it was):

class MSIArrangementNodeMigration extends MSINodeMigration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);

    $this->addFieldMapping('field_voices', 1)
         ->sourceMigration('Voices')
         ->arguments(array('source_type' => 'tid'));

  }
  public function sourceFieldList() {
    $fields = parent::sourceFieldList();
    return $fields;
  }
}

Unfortunately it doesn't seem to work. Is this the correct pattern?

Thanks in advance,
Tom

Oops my mistake - it does

Oops my mistake - it does work! :) I had a bit of old data hanging around in my database that led me to believe otherwise.

D6 to D7?

Any hints or examples for a D6 to D7 migration? I'm having a hard time getting this to work.

Actually, this does work in

Actually, this does work in D7, except you don't need the sourceFieldList function at all.

Note that DrupalTerm6Migration in this example will not create the destination Vocabulary. Instead, you will get something like:

New object was not saved, no error provided     [error]
New object was not saved, no error provided     [error]
... etc

one for each source Term. Also, drush mmsg [yourmigration] shows something like:
sourceid1   message                                            
15          No vocabulary found with machine_name document_type
15          New object was not saved, no error provided        
16          No vocabulary found with machine_name document_type
16          New object was not saved, no error provided        
... etc

Manually creating empty Vocabulary placeholders at the destination allows the import to succeed as shown in the example.

--
..happiness is point and click..
http://www.bronius.com

Hi, @Pearlbear, I need also

Hi, @Pearlbear,
I need also to migrate a vocabulary with term referenced node fields to convert from a D6 to a D7 site.
Can you may be give me a plan of action how to deal with this please?

Thanks a lot in advance!
Greetings, Martijn

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Level
Intermediate, Advanced
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here