Something isn't quite right with the term migration between 5 and 7. I have the following vocab in Drupal 5:

Term 1
-- Term 2
-- -- Term 3
-- -- Term 4
-- Term 5
-- -- Term 6
-- -- Term 7

When I migrate it across I get the following:

Term 1
Term 3
Term 4
-- Term 2
-- Term 5
-- -- Term 6
-- -- Term 7

For some reason terms under Term 2 are not respecting there parent. Outputting the $row from prepareRow() shows that the correct parent is assigned but in the new D7 term hierarchy they are assigned to 0. It's really odd that terms under Term 5 are migrated correctly. The one thing that does stand out is that the tid of the sub terms are higher lower than the container (Term 2). Also this is the first set of terms that are nested 3 deep.

Comments

mikeryan’s picture

Component: D5-specific » Code

Nothing to do specifically with D5 - to set the parent of a term properly, the parent must have already been migrated. So, if a term pops up in the migration before its parent, it won't get a parent. We order the term migration by parent so terms with no parent come first, which will work just fine with a 2-deep hierarchy, but beyond that all bets are off.

We should add a createStub() method, so parent stubs get created and ultimately the hierarchy is preserved.

mikeryan’s picture

Title: D5 to 7 Term Migration » Multi-level term hierarchy problem - parents must be migrated before children

Better title.

philipz’s picture

That title was really misleading I looked at it few times and haven't entered it :)

I just checked and this problem can be fixed by migrating two times and using --update the second time. That second time gets the hierarchy in order.
I did that with Feeds some time ago and that did the trick too.

Anyway the createStub is the right approach and I'll try to make patch today.

philipz’s picture

I failed to make createStub implementation for terms. Maybe later when I'll understand the whole migration classes registration better.
For now the double import with --update option is the solution for me:)

jacktonkin’s picture

The following subclass works for me migrating a 3-level vocabulary from Drupal 6. Might be suitable to simply add this createStub() implementation to DrupalTermMigration?

class MultiLevelTermMigration extends DrupalTerm6Migration {
  public function createStub($migration, $source_id) {
    if ($source_id[0] != 0) {
      $term = new stdClass();
      $term->name = t('Stub for term ') . $source_id[0];
      $v = taxonomy_vocabulary_machine_name_load($this->destinationVocabulary);
      $term->vid = $v->vid;
      taxonomy_term_save($term);
      if (isset($term->tid)) {
        return array($term->tid);
      }
    }
    return FALSE;
  }
}
Summit’s picture

Hi, did this also work for Drupal 5 - Drupal 7 migration?
greetings, Martijn

mikeryan’s picture

Status: Active » Fixed

OK, I've added a createStub() to the base class, this should work fine now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.