In the description of MigrateDestinationTerm here:

http://drupal.org/node/1349702

the destination vocabulary is hard-wired into the example. I'm trying to move all terms from all vocabularies from an old db into D7. I have code in place to determine the new machine_name for the destination vocabulary. This information must be in MigrateDestinationTerm::$bundle which is a protected field and can only be set during object instantiation (so changing it in prepareRow() isn't an option).

I've looked at wine.inc in migrate_examples and I see there that the terms are imported vocabulary by vocabulary. That is, there are three subclasses of WineTermMigration each with their own unique constructor.

Is there a way to do this in a more automated fashion, for an arbitrary set of Vocabularies?

Comments

mikeryan’s picture

Status: Active » Fixed

I've added the following to the documentation page:

The vocabulary passed to the MigrateDestinationTerm constructor can be overridden on a per-term basis by mapping vocabulary_machine_name:

  $this->addFieldMapping('vocabulary_machine_name', 'category_name');
nerdcore’s picture

Status: Fixed » Active

I am assuming from this example code that an appropriate place to perform this mapping is in prepareRow() because we are talking about per-term data.

So I wrote this:

  public function __construct() {
    ...
    // Attempting to instantiate this class with no args fails to save
    // "New object was not saved, no error provided"
    // We need to give it something here, so why not 'tags'...
    $this->destination = new MigrateDestinationTerm('tags');
    ...
  }

  function map_vocab($human_name) {
    // Returns machine_name given a human-readable vocabulary name
  }

  function prepareRow($r) {
    // $r->vname is the human-readable vocabulary name
    $this->addFieldMapping('vocabulary_machine_name', $this->map_vocab($r->vname));
  }

But this results in warnings:

MyTermMigration addFieldMapping: vocabulary_machine_name was previously mapped, overridden

And my terms migration import is sticking them all into the vocabulary 'tags'.

Is there some sort of overrideFieldMapping() call? Or some other way to replace the vocabulary_machine_name in the MigrateDestinationTerm object?

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

No, addFieldMapping goes in your constructor. Try this:

public function __construct() {
...
$this->addFieldMapping('vocabulary_machine_name', 'vname');
...
}

public function prepareRow($row) {
  $row->vname = $this->map_vocab($r->vname);
}
nerdcore’s picture

Status: Postponed (maintainer needs more info) » Fixed

This works. Thank you.

Status: Fixed » Closed (fixed)

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