Active
Project:
Drupal-to-Drupal data migration
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
31 Mar 2013 at 10:38 UTC
Updated:
16 Jul 2020 at 05:36 UTC
Jump to comment: Most recent
Comments
Comment #1
joachim commentedI'm not really sure where this should be implemented.
getSourceValues() is where field values are loaded up for the fields on the current migration row (ie, the fields on the current node).
But handling term ref fields in this function as a special case feels ugly. Also, we'd have to repeat the code 3 times in each of the 3 Drupal major version source classes.
The other option that I can see is to create a whole new family of 'source field' handlers, roughly analogous to the destination handlers.
What does the maintainer think? :)
Comment #2
mikeryanThe maintainer doesn't see why having a distinct term migration is a problem;). I feel like having a distinct migration for each chunk of data complex enough to be a distinct "entity" is the cleanest approach, and that creating entities as a side-effect of another migration (as happens when mapping taxonomy terms by name within a node migration) increases rather than decreases complexity. Can you make a case otherwise?
Comment #3
joachim commentedI definitely agree it would be a load of extra complexity for a special case.
However, as a user of Migrate, this tripped me up. I made a D7-D7 migration, and found my nodes all tagged with numbers instead of words, because the terms had been created with their names taken from the source site's term IDs!
Having previously migrated from a raw CSV into D7, which is a case where you can have strings in a row auto-create terms, I was expecting something along the same lines.
So it seems to me we should be consistent -- or make sure the inconsistency is very well documented!
Comment #4
justindodge commentedIn case it's helpful for anyone, this isn't too hard to accomplish with a little callback for a term reference field mapping. This solution assumes you have access to the Drupal database you're migrating from.
First I've got the DB connection defined - this is where I'm migrating from, but we'll query from it later. My implementation of hook_migrate_api() specifies this as the 'source_connection'
Then, in my migrate class constructor I'm mapping a term reference field and adding my callback:
Lastly, the mapping callback in my migration class looks up the term name(s) with a DB query
The D7 version is identical except for the DB query:
$term_names = $db->query('SELECT name FROM {taxonomy_term_data} WHERE tid IN(:tid)', array(':tid' => $value))->fetchCol();I keep these methods hanging around in a common base class that's available for all my migrations - super handy.
Enjoy!
Comment #5
daletrexelI'd like to jump in to reply to mikeryan's comment in #2:
I'm currently working on a D7 migration where the builders were thinking ahead and built taxonomy references via entity reference fields, but I've asked them to revert to the older taxonomy reference field type for several reasons related to the discussion here. Here's a summary of my observations. I'm not sure if this is the right place to have this conversation, but it's the best I've found so far:
1. The fact that terms are entities is not really that important all the time. Regarding the comment, "having a distinct migration for each chunk of data complex enough to be a distinct 'entity' is the cleanest approach," people use taxonomies because they provide more flexibility than a simple select list field with a pre-determined list of options. You can let people manage taxonomies without giving them access to the entity configuration (which may be featurized). Entities may be complex on the back end, but conceptually, to the users and the site builders, they're really not that complex or significant -- just a glorified list with some handy extra management tools. I would argue that taxonomy terms are a class of entity that as a group benefit from being able to be migrated alongside other entities that reference them.
Making it harder to migrate terms puts you in the position of asking yourself, "Is the extra time spent now migrating terms worth the ease of management that using a taxonomy will provide down the road?" It's not a question you faced when you could easily migrate terms along with an entity.
2. Pre-migrating taxonomies from sources that are not fully normalized requires extra work: you have to pre-query the source data first to pull out the terms to migrate and then again to get the entities that reference those terms. This turns a single migration class into potentially many migration classes (one for each taxonomy) that have to be developed, debugged and maintained as the migration itself moves forward, creating greater complexity in the migration system, which adds greater opportunities for things to break.
You might expect that a simple GROUP BY on the source data might be sufficient to pull out unique terms for a separate migration, but this doesn't work if your data are not clean (something I face often) and you need to perform extra logic on the terms that are interrelated with the entities that are referencing them. Being able to clean up term data during the referring entity's prepareRow() step, including deciding whether or not to include the term at all, is very, very handy at times. If you migrate terms in a separate preliminary migration, you may not be able to clean up your data sufficiently, leading to messier term lists than if you were able to migrate and process terms alongside entities.
3. Update migrations that follow an initial migration get messier and more complex if you have to re-migrate each set of terms. The new data may not include any new terms to migrate, but unless you analyze your incoming data to look fro this, you have to assume that there is at least one new term in the new batch of data, requiring you to run the term migration ahead of the entity migration.
You also have to know the key field for each term with each subsequent update migration. That may not always be easy to get. For example, your initial migration may come from an old CMS with its own key field values, but moving forward, you may batch import new data that's no longer from that CMS. (In our case, new batches of students that enroll each semester, data from the registrar, rather than the old CMS.) With the old system, you could migrate terms themselves, not caring or bothering to look up their migration map ID was, and creating new ones on the fly if they didn't already exist. The concept of a source migration gets rather messy!
Comment #6
joey-santiago commentedIs there any news on this approach to do migrations? The reason why i think it would make more sense migrating this way is one would only migrate the used terms, leaving on d7 all the unused ones. Also, this way the migration is way slimmer and straightforward.