Download & Extend

Document Argument for auto-creation of terms from references

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

Category:feature request» support request
Status:active» postponed (maintainer needs more info)

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

Category:support request» feature request
Status:postponed (maintainer needs more info)» active

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

Title:character separated field (for example /)» Argument for auto-creation of terms from references
Version:7.x-2.0-rc2» 7.x-2.x-dev
Component:Miscellaneous» Code

#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

Status:active» needs review

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.
AttachmentSize
1078368-migrate-term-create.patch 1.1 KB

#9

Status:needs review» fixed

Committed, thanks!

#10

Title:Argument for auto-creation of terms from references» Document Argument for auto-creation of terms from references
Component:Code» Documentation
Category:feature request» task
Status:fixed» needs work

Where do we document this?

#11

Status:needs work» fixed

OK, documented at http://drupal.org/node/1224042.

#12

Status:fixed» closed (fixed)

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!