I have followed the term remapping cookbook article (https://www.drupal.org/node/2250057) in order to remap a term set on import. Some of the terms from the source are not contained in the csv as they are no longer needed in the destination.

The mapping table for this migration correctly lists the source rows that are not being imported with a 'NULL' destination ID. That's all as expected.

However, when running a migration that is dependant on the remapped taxonomy migration and has a term reference field with multiple values, if any of the values are the ones that have not been imported, ALL of the values get ignored - even if some of them are terms that have been imported.

EG.

I have a user with five email preferences that are mapped to a taxonomy that has also been imported and remapped. All five of the terms have been imported. All five tids get added to the user term reference field.

I have another user with five email preference, four have been imported and one hasn't. I would expect the four valid tids to be added to the term reference field. However, none get added - not even the valid ones. It does not matter where in the array of source IDs the invalid term ID is, none of the valid terms get attached to the user.

This is using Migrate 2.7 to migrate data from a MySQL database source into Drupal 7.34.

Thanks

Comments

mikeryan’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

I've tried to replicate this behavior in migrate_example, creating BeerNode::prepareRow() and explicitly setting an array of terms with and without a NULL value (e.g. array('pilsner', NULL, 'red ale')) - it seems to work fine. Can you provide a little more detail - the code setting up the terms in prepareRow(), what exactly the term array looks like after being applied, ...?

KeithC’s picture

Hi mikeryan. Thanks for the reply.

I'll try to describe what I'm doing.

The source is a MySQL DB from a bespoke CMS. I have a migration class to import 'themes' into a taxonomy in Drupal. However, this needs re-mapping on import.

So, for example, lets say that the source data is:

1, Theme 1
2, Theme 2
3, Theme 3
...
10, Theme 10

But lets say we re-map the data but we don't want to bring across Theme 3 and Theme 7 so we omit them from the crosswalk csv file that handles the remapping. In the mapping table for this migration, it still inserts a row for all ten source rows - including 3 and 7. Except 3 and 7 have a null destination ID but the rest have the ID of the Drupal taxonomy term that they have been mapped to.

I then import the users and one of the mappings is which themes (term reference field) they have opted to receive emails about:

this->addFieldMapping('field_theme', 'themes')
  ->sourceMigration('Themes');
$this->addFieldMapping('field_theme:source_type')
  ->defaultValue('tid');

Because of the way the source DB is setup, I can't get all the related term data as part of the source query. Instead, I'm getting all the additional data for all users in one query at the start of the migration and adding it to an array keyed by user ID. This data then gets added to each row in 'prepareRow'. So '$row->theme = array(1, 3, 6...)' - basically an array of the themes for that user.

From what I've seen, using the example above where 3 and 7 are not imported over but are mapped:

  • If '$row->theme = array(1, 2, 4, 5)', all the term references are setup correctly
  • However, if any of the source IDs are those that have not been import - '$row->theme = array(1, 2, 3, 4)' - then none of the term references are created - not even 1, 2 or 4.

So it's not that the data during the user import contains NULL values, it's that it contains valid IDs in the source DB, but these are mapped to NULL values in the dependant migration mapping table.

I hope this makes a bit more sense.

Thanks

KeithC’s picture

Status: Postponed (maintainer needs more info) » Active

  • mikeryan committed eb6ae6c on 7.x-2.x
    Issue #2497015 by mikeryan: Term reference handler would ignore all...
mikeryan’s picture

Status: Active » Fixed
Issue tags: +Migrate 2.8

Got it! The term reference handler was trying to simplify receiving something like array('') to array() by only checking the first value in the array - just added a count==1 check.

Committed, thanks!

Status: Fixed » Closed (fixed)

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