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

CommentFileSizeAuthor
#8 1078368-migrate-term-create.patch1.1 KBklausi

Comments

mikeryan’s picture

Category: feature » support
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.

cesarseoane’s picture

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

mikeryan’s picture

Category: support » feature
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).

mikeryan’s picture

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
cesarseoane-at-gmail.com’s picture

Mikeryan Thanks for your help with the process.

chromix’s picture

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.

mikeryan’s picture

No one's been motivated enough to submit a patch so far, it seems.

klausi’s picture

Status: Active » Needs review
StatusFileSize
new1.1 KB

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.

mikeryan’s picture

Status: Needs review » Fixed

Committed, thanks!

klausi’s picture

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

Where do we document this?

mikeryan’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

chrisivens’s picture

Any chance of this for d6?

nlisgo’s picture

Thanks for this lovely commit. Was the last piece in my migration puzzle!