Hi,
I am trying to import data and my regular CCK fields (and regular taxonomy fields) import ok, but my content_taxonomy cck taxonomy fields do not get imported. I have them set to allow new values to be added to taxonomy. I'm assuming this is either a bug or a case that is not covered in the code?
Has anyone been successful doing this?
Thanks :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pimousse98’s picture

After a look at the code there would be a need (probably ) to add a case to content.inc that covers content taxonomy. Right now I believe the fields just get ignored.
Since in the database only the tid gets stored in a column named field_ would there be a way to use existing functions in taxonomy.inc such as _migrate_taxonomy_get_term (to get the tid for existing terms) and some of the code in taxonomy_migrate_prepare_node (for handling terms that are not in the taxonomy term list yet?). The thing I haven't found out how to do is to get the appropriate vocabulary since it's handled in a different way from taxonomy.
If anyone could give me a hand with the code, I would be very grateful.

pimousse98’s picture

I made a partial fix... This will always add terms to taxonomy if they don't exist (regardless of settings), and does not add rows to the term_node table (however, it seems that if the option "also save to taxonomy table" is not checked then terms don't get imported).

in modules/contrib/content.inc
function content_migrate_prepare_node
in switch statement add the following:

 case 'content_taxonomy':
           	// if save_term_node = 1 we want to also save taxonomy information to the database. It seems  	
	      	// ? don't know what the var is, but there is also an option to NOT add new terms to db.
	      	// seems that if that is not set things do not get imported (if do not save terms to taxonomy)
	       
// first get vocabulary information to send in to function
	             	$vocab= taxonomy_vocabulary_load($field['vid']);  
             		
// the function will return the tid and add the term to vocabulary if it is not found.
             		// function resides in taxonomy.inc for the migrate module. 
             		$value=_migrate_taxonomy_get_term($vocab, $value,'add');
             	break;

Hope this might help someone.

mikeryan’s picture

Category: bug » feature

Note there was already an issue for content_taxonomy support: #600012: How to migrate multiple Taxonomy terms into CCK. I'm closing that as a duplicate, since this contains more info.

The preferable way to add support for another module is in its own file (i.e., modules/contrib/content_taxonomy.inc).

BenK’s picture

+1 for support for content_taxonomy module!

rsvelko’s picture

@2: Thanks a lot that worked awesome.

Please patch the module soon.

mikeryan’s picture

Component: Code » Contrib module support
mikeryan’s picture

Project: Migrate » Migrate Extras
Version: 6.x-1.0-beta3 » master
Component: Contrib module support » Code
BenK’s picture

Hey everyone,

Now that this has been assigned to Migrate Extras, should we make a new migrate extras sub-module for content taxonomy?

--Ben

gunzip’s picture

subscribe

frankcarey’s picture

well, not submodule, but integration, yes. We need a content_taxonomy.inc and a patch adding it to the integrations listed in migrate_extras_migrate_api().

bsnodgrass’s picture

Component: Code » Migrate Extras Features

great! looking for this too.

gg4’s picture

+1 for support for content_taxonomy module

3dloco’s picture

Title: Content_taxonomy cck fields not imported » Content Taxonomy CCK Fields Not Imported
Issue tags: +CCK, +taxonomy, +content taxonomy, +migrate

+1 too ;D

3dloco’s picture

Thanks Pimousse98 for sharing the code on #2 to migrate CCK taxonomy. I modified ../migrate_extras/content.migrate.inc and it worked for me too.

Summit’s picture

Hi KH,
Could you share your code for content.migrate.inc please?
Thanks a lot in advance!

greetings, Martijn

3dloco’s picture

FileSize
7.32 KB

Hi Martijn,

Hope this is not too late for you...I was out on vacation and I am catching up :)

See attached file specifically where I've put in the code from #2 between the comments //616910 starts //616910 ends.

Regards,

KH

milos.kroulik’s picture

+1

kruser’s picture

subscribe

darora’s picture

Project: Migrate » Migrate Extras
Version: 6.x-2.x-dev » master
Component: Code » Migrate Extras Features

Has any one tried it with Migrate V2 module? The workaround above is for the older version of MigrateExtra module that handled that CCK fields.

Summit’s picture

Hi,
On project page there is stated: Notably, that means while CCK and filefield support were in migrate_extras for V1, they are in Migrate itself for Migrate V2.

What is the status on this issue in this perspective please?
greetings, Martijn

mikeryan’s picture

Project: Migrate Extras » Migrate
Version: master » 6.x-2.x-dev
Component: Migrate Extras Features » Code

Since Drupal 7 natively handles term references, it makes sense that supporting Drupal 6 term references as provided by content_taxonomy should go into the Migrate module itself. Moving this issue over there.

darora’s picture

Project: Migrate Extras » Migrate
Version: master » 6.x-2.x-dev
Component: Migrate Extras Features » Code

Has anyone got it working with Migrate 2.0 version? Please share tips or code.

darora’s picture

Finally...got it working with Migrate 2.0 version. It ended up a simple fix but took long time to figure out.

Need to register the "content_taxonomy" as field type inside the /plugins/destination/fields.inc file as below...and that's it.

class MigrateValueFieldHandler extends MigrateFieldHandler {
  public function __construct() {
    $this->registerTypes(array('value', 'list', 'list_boolean', 'list_number',
      'list_text', 'number_integer', 'number_decimal', 'number_float','content_taxonomy'));
  }

Hope it helps...

mikeryan’s picture

Title: Content Taxonomy CCK Fields Not Imported » Support for Content Taxonomy CCK Fields
Project: Migrate » Migrate Extras
Component: Code » CCK

I misunderstood what Content Taxonomy does - it's not really analagous to D7 core functionality, so back over to Migrate Extras.

The suggestion in #23 only works when passing in tids, not names. Here's the equivalent implementation for migrate_extras, but it would be nice to support both tids and names as the D7 term reference handler does:

class MigrateContentTaxonomyFieldHandler extends MigrateValueFieldHandler {
  public function __construct() {
    $this->registerTypes(array('content_taxomony'));
  }
}
mikeryan’s picture

Status: Active » Needs work
Anonymous’s picture

I patched my Migrate module as suggested in comment #23.
I experience this behaviour: terms are correctly migrated between Drupal installations, but the term with value "1" is added to each field of my content type, even if the term with tid 1 does not belong to the vocabulary associated with that field.

How can I submit here relevant debug information about this?

Thanks

Leo

trunks’s picture

FileSize
2.03 KB

My two cents from migrating content_taxonomy fields from tids or term_names.

Instructions for developers:

The example field mapping code below shows how to import terms in content taxonomy field.

Note that these code snippet must go into your Migration subclass's constructor - see the migrate_example module for an example of how and where to use field mappings.

// Import source field "content_taxonomy" containing tids into
// destination field field_content_taxonomy:
$this->addFieldMapping('field_content_taxonomy', 'term');

// Import source field "content_taxonomy" containing names into
// destination field field_content_taxonomy:
$arguments = MigrateLinkFieldHandler::arguments('name');
$this->addFieldMapping('field_content_taxonomy', 'term')
   ->arguments($arguments);
trunks’s picture

Status: Needs work » Needs review

I'm sorry. Forgot changing the status.

ermannob’s picture

Hi trunks,
thank you for your patch. I found it very useful.

I'd like to point out a requirement that I found in your approach: terms must exist in vocabularies before importing content_taxonomy fields. I'm writing this just to help others who's willing to test your patch.

I'd also fix a line in the code you wrote in the issue, I will post it here as a whole. (MigrateLinkFieldHandler should be MigrateContentTaxonomyFieldHandler)

// Import source field "content_taxonomy" containing tids into
// destination field field_content_taxonomy:
$this->addFieldMapping('field_content_taxonomy', 'term');

// Import source field "content_taxonomy" containing names into
// destination field field_content_taxonomy:
$arguments = MigrateContentTaxonomyFieldHandler::arguments('name');
$this->addFieldMapping('field_content_taxonomy', 'term')
   ->arguments($arguments);

Greetings,
-ermannob

trunks’s picture

FileSize
2.04 KB

Hi ermanobb,

You're right. Here you are a new bugfixed revision for this patch.

By the way, it's a requisite migrating terms and vocabularies (implementing MigrateDestinationTerm or your own class) in your migration module before migrating nodes.

ermannob’s picture

FileSize
1.08 KB
2.57 KB

Hi trunks,
I made some improvements to your patch. I found some problem when having terms with same name in different vocabularies. I'm working on a large project where some terms names are identical but belong to different vocabularies.
I made some modifications that let developers restrict searching for terms in a particular vocabulary instead of searching through the entire term_data table.

For example:
$arguments = MigrateContentTaxonomyFieldHandler::arguments('name', 3);
'3' is the vid of the vocabulary to search into. It's an optional parameter.

[sorry, i couldn't produce a patch like yours, so I will post a patch for your patch and the entire file]

Greetings,
-ermannob

ermannob’s picture

I'm trying again with a (supposed) proper patch. :)

mikeryan’s picture

Status: Needs review » Needs work

Please review the Drupal coding standards for indentation, structure, etc.

I haven't used Content Taxonomy myself, so I will be dependent on someone (other than the patch author) who does to test this for functionality and set it to RTBC.

Thanks.

ermannob’s picture

Thank you for pointing me to the right direction, mikeryan.
Not sure if there's more to do on my patch... any hints are welcome.
I'm trying again. :)

mikeryan’s picture

Status: Needs work » Needs review
mikeryan’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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

myselfhimself’s picture

Hello,

here is a patch (done with cvs diff...) of migrate_extras/content_taxonomy.inc to allow for merging source terms with destination terms for multi-valued taxonomy fields.

Maybe this won't be useful for general use cases, but it will help others finding the same need that I had.

Here's an example how to use the patch, within a Migration class's __construct():

    // We want to add source terms tid=19 & 21 into destination, by tid (1st param), looking up vocabulary 21 (2nd param), *with source+destination terms merging (3rd param)*.
    $arguments = MigrateContentTaxonomyFieldHandler::arguments('tid', 21, TRUE);
    $this->addFieldMapping('field_est_properties')
    ->defaultValue(array(19,20))
    ->arguments($arguments);

: )

Summit’s picture

Hi,
Any news on this please? Is there now a correct working migration for content_taxonomy migration from D6 to D7 to correctly migrate terms and term-fields references?
Greetings, Martijn

rootwork’s picture

#36 says it was committed way back in March 2012, but it doesn't appear to be in the most recent version (from November 2012). What's up? Was it rolled back?

mikeker’s picture

Status: Needs review » Active

Perhaps a bit late for @Summit and @rootwook, but the commit in #36 is to the 6.x-2.x branch.

I'm pretty sure it doesn't belong there, but should be in the 7.x branch instead? (Unless entities and DB-TNG were backported while I wasn't looking? :)