Posted by cesarseoane on March 2, 2011 at 9:24am
8 followers
| Project: | Migrate |
| Version: | 7.x-2.x-dev |
| Component: | Documentation |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I have to import some characteristics form a field separated by '/' as separated taxonomy Terms and i don't find the way to do it.
Example:
Original field -> "family/ sports/ cooking" -> it could be any number of characteristics.
Taxonomy terms -> "family", "sports" and "cooking" -> only if it doesn't exist jet.
I've tried with separator('/') but creates only one field with the three characteristics inside.
I need to create a taxonomy with each characterístic and a reference in a node object to the characteristics it has.
Thanks
Comments
#1
Are you saying that you want each section of the incoming field to produce a term in a separate vocabulary? I.e., "family" would be a term in the "Relationships" vocabulary, "sports" in the "Hobbies" vocabulary, etc.? If so, that's something you'll need to implement yourself in a prepare() or prepareRow() method.
#2
Hi mikeryan thanks for answer my question.
I'm going to try to be more specific.
I've a source table named products that has a field named context with information like "family/ sports/ cooking". This field is not related with other tables in the database, only with the "product" in which it appears.
I'd like to create a vocabulary "contexts" in which appears all the context of all the new products objects in drupal.
And create a multiple term reference field in product object in drupal with the context it has (one or more).
With separator, i can fill the context in products, but i don't know how to previously fill the vocabulary.
I was thinking to use a query to separate family, sports and cooking and get different registry for each one in the query, but i think it's not possible.
I need new ideas to solve the problem. Thanks
#3
OK, so the question you're asking is about creating the taxonomy terms themselves, not their assignments to each node. If it's not convenient to form a query to base an explicit term migration on, then what's needed is to 'lazily-create' the terms - as you hit term references during node migration, check if they already exist and if not create them. The Migrate module does not have this capability built-in, so you need to implement it yourself in a prepare method on your migration. It's pretty simple, I've done it a number of times - just do a db_select on taxonomy_term_date (not forgetting to include your vocabulary's vid as a condition), and either assign the returned tid if any, or do a taxonomy_term_save() to create the term and assign the tid from that.
It's not a bad idea to support an argument on MigrateTaxonomyTermReferenceFieldHandler telling it to automatically create the term if it's not found, let's make this issue a request for that feature (too late for Migrate 2.0, but a consideration for 2.1).
#4
#5
Mikeryan Thanks for your help with the process.
#6
Did anything ever come of this? I'm running into a similar problem and I wasn't sure if this ever made its way into Migrate 2.1 or dev.
#7
No one's been motivated enough to submit a patch so far, it seems.
#8
Here is a patch that supports a boolean 'create_term' argument. If set, unknown values will be created as new terms.
Usage:
$this->addFieldMapping('field_example_term_reference', 'source_column')->arguments(array('create_term' => TRUE))
Patch attached.
#9
Committed, thanks!
#10
Where do we document this?
#11
OK, documented at http://drupal.org/node/1224042.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.
#13
Any chance of this for d6?
#14
Thanks for this lovely commit. Was the last piece in my migration puzzle!