2

I have a migration use case where I can't figure out a way to get along with:

I have a Drupal 7 site which shall be migrated to D8. I don't want to migrate the content 1:1 but rearange some things to better fit the D8 way.

In the old site there are products which have an "ingredients" field which is a reference to taxonomy terms. Additionally there are "griege" nodes which technically represent an ingredient but are not associated with the taxonomy vocabulary "ingredients". They have indeed the same title so could be mapped by string comparison.

Now I want to do the following:

  • Import all "Griege" nodess from the old site and save them as "Ingredient" nodes
  • Import all "Product" nodes to the new site
  • Check if they have ingredients (taxonomy terms) assigned
  • If so, search for "Ingredient" nodes in the new site (term name == Ingredient title) and attach them to the newly created "Product"

In short I want the assigned taxonomy terms to be converted into "normal" content entities.

What I did so far is to extend the Drupal 7 node source plugin by adding the following left joins within the query() method:

$query->leftJoin('taxonomy_index', 'ti', 'ti.nid = n.nid');
$query->leftJoin('taxonomy_term_data', 'ttd', 'ttd.tid = ti.tid');

My problem is that I don't know what to do with that information within the process plugin. I could return the correpsonding Ingredient ID but as it's an 1:N relation between Prdouct and Ingredient that would mean it would overwrite the array holding the product ingredients everytime I process a row.

I hope my problem is somehow clear... :/

Some general questions I have:

  1. Is there a way to access the datasource (the D7 source database) within a process plugin? E.g. do a select on the old product (get all terms, do the lookup in the new DB and return an array of Node Ids)

  2. Could my solution somehow involve the usage of a destiantion plugin (I haven't fully understood the usage of those I fear)?

  3. Is there something completely different I missed out to do the job?

Many thanks in advance!

Dennis

  • Unless I've misread, I think you should do all of this on the D7 site first using rules to loop through each ingredient and maybe fetch by entity property to find and set the griege nodes. – Niall Murphy Jan 9 '17 at 17:06
  • I'm not sure what you mean unfortunately. Do you mean I should remodel the content on the D7 site before running the migration? – Dennis M. Jan 10 '17 at 13:51
1

I don't have time to fully flesh it out at the moment, but the approach I would take would be to:

  1. In your product migration, which presumably is using the d7_node source plugin, override that source plugin and implement prepareRow() (not forgetting to call parent::prepareRow()!) to query the related ingredient terms and $row->setSourceProperty('ingredient_names', /* array of term names *?);
  2. Use the migrate_plus entity_lookup process plugin to map those ingredient_names to existing (previously imported) ingredient node titles. You'll be looking at the example with full configuration for your use case...

Hope this helps!

  • This sounds like a good approach. Wasn't aware of the entity lookup plugin. Thanks alot! – Dennis M. Jan 10 '17 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.