Migrate taxonomy field data from drupal 6 to 7

rajeesh's picture

Hi all,
I am new to this group. Now I was migrating content from Drupal 6 to 7 with the help of migrate module. I had migrated image field having multiple values. But I have no hope in the case of taxonomy terms yet. i tried with reference to the code of some sandbox project but the values were not inserting. Please take a look on my prepareRow function.

function prepareRow($current_row) {       $terms_query = db_select('D6_DATABASE.'.content_field_office_insurance', 'cf')       ->condition('cf.nid', $current_row->nid, '=');      $terms_query->leftJoin('D6_DATABASE'.'.term_data', 'td', 'cf.field_office_insurance_value = td.tid');        $terms_query->addField('cf', 'field_office_insurance_value');        $terms_tax = array();       $terms_results = $terms_query->execute();     foreach ($terms_results as $result) {   if((!in_array($result->field_office_insurance_value, $terms_tax)) && ($result->field_office_insurance_value != NULL)) {   $terms_tax[] = $result->field_office_insurance_value;    }   }      $current_row->terms = implode(',', $terms_tax);     return TRUE;   }

Here I put the the in-array() condition to avoid the duplicate and NULL values. I mapped the field by this way.
$this->addFieldMapping('field_office_insurance', 'terms')     ->separator(',');

But the values were not inserted. I have a doubt that in the case of taxonomy field migration whether we need to migrate the taxonomy vocabulary and their terms before doing the field data migration. I was scratching my head for the last two days to fix this problem. Any help on this will be appreciated.

Thanks in advance.

Comments

Several things: I would not

mikeryan's picture

Several things:

  1. I would not use the dot-notation hack to access the remote database, get a proper connection object with Database::getConnection().
  2. You don't need to use separator() and implode(), you can just assign the array of tids.
  3. Don't use == or != to test for NULL, use is_null. Although, in this case, I would use empty()...
  4. I don't see why you're joining to term_data, you're just using field_office_insurance_value.

<?php
function prepareRow($current_row) {
 
// Note second arg to getConnection should be connection string, not actual DB name
 
$terms_query = Database::getConnection('default', 'D6_DATABASE')
    ->
select('content_field_office_insurance', 'cf')
    ->
condition('cf.nid', $current_row->nid);
 
$terms_query->addField('cf', 'field_office_insurance_value');
 
$terms_results = $terms_query->execute();
  foreach (
$terms_results as $result) {
    if ((!
in_array($result->field_office_insurance_value, $current_row->terms)) &&
        (!empty(
$result->field_office_insurance_value))) {
     
$current_row->terms[] = $result->field_office_insurance_value;
    }
  }
  return
TRUE;
}
?>

But, the one that's really breaking you is this:

  1. By default, the values are assumed to be the term names, not tids. For it to accept tids, you need to set the source_type option to 'tid'. With Migrate 2.4 or later:

<?php
$this
->addFieldMapping('field_office_insurance', 'terms');
$this->addFieldMapping('field_office_insurance:source_type')
       ->
defaultValue('tid');
?>

With earlier versions of Migrate:

<?php
$this
->addFieldMapping('field_office_insurance', 'terms')
     ->
arguments(array('source_type' => 'tid'));
?>

Mike Ryan

Any idea in migrating location details ?

rajeesh's picture

Hi mikeryan,
Thanks for your quick and helpful reply. Any way I figured out a solution for it with the help of this article http://drupal.org/node/1481998. In this first we need to migrate the taxonomy vocabulary and then we can migrate the taxonomy field with reference to the first migration. But now I stuck up with another issue. I need to migrate the location details from drupal 6 to drupal 7. I can't find any helpful article on web. Any help on this will be really appreciated.

Thanks in advance.

By "location details" I

mikeryan's picture

By "location details" I assume you mean data from the location module? Support for migrating contrib modules goes into the module itself or Migrate Extras - there is currently no support for the location module, but it has been requested: [#943178].

Mike Ryan

I migrated location details

rajeesh's picture

Hi Mike,
Thanks for your reply. The good news is that I migrated location details with migrate module(using migrate 2.3 version). Here is my prepareRow function.

function prepareRow($current_row) {

        $loc_query = db_select('drupal_d6'.'.location', 'l');
        $loc_query->leftJoin('drupal_d6'.'.location_instance', 'li', 'li.lid = l.lid');
        $loc_query->leftJoin('drupal_d6'.'.location_phone', 'lp', 'lp.lid = l.lid');
        $loc_query->leftJoin('drupal_d6'.'.location_fax', 'lf', 'lf.lid = l.lid');
        $loc_query->condition('li.nid', $current_row->nid, '=');
        $loc_query->addField('l', 'name');
        $loc_query->addField('l', 'street');
        $loc_query->addField('l', 'additional');
        $loc_query->addField('l', 'city');
        $loc_query->addField('l', 'province');
        $loc_query->addField('l', 'postal_code');
        $loc_query->addField('l', 'country');
        $loc_query->addField('l', 'latitude');
        $loc_query->addField('l', 'longitude');
        $loc_query->addField('l', 'is_primary');
        $loc_query->addField('lp', 'phone');
        $loc_query->addField('lf', 'fax');
        $loc_query->orderBy('li.lid', 'DESC');
        $loc_query->range(0, 1);
        $loc_array = array();
        $loc_results = $loc_query->execute();
         if(!empty($loc_results)) {
              foreach ($loc_results as $row) {
                    $current_loc_data = array(
                      'name' => $row->name,
                      'street' => $row->street,
                      'additional' => $row->additional,
                      'city' =>  $row->city,
                      'province' =>  $row->province,
                      'postal_code' =>  $row->postal_code,
                      'country' =>  $row->country,
                      'latitude' =>  $row->latitude,
                      'longitude' =>  $row->longitude,
                      'is_primary' =>  $row->is_primary,
                      'phone' =>  $row->phone,
                      'fax' =>  $row->fax,
                    );
                   
                   if(!in_array($current_loc_data, $loc_array)) {
                           $loc_array[] = $current_loc_data;
                       }   
           
              }
                $current_row->location_data = $loc_array;
        }
       
        return TRUE;
     }

Then I mapped the location details like this.

$this->addFieldMapping('locations','location_data');

It works...
Please let me know your comments.

My module may do this easily

bailey86's picture

Hi,

Install this module on to both your D6 site and D7 site:

http://drupal.org/sandbox/bailey86/1278830

Export the taxonomy terms to file on the D6 site - the file will be in sites/default/files/data_export_import by default.

Move the file to the D7 site - put it in sites/default/files/data_export_import. The file should now show up in the dataset files list.

Use the module to import the terms into your D7 site.

I've just ported the module to work on D7 - and as far as I remember I've not changed the output of the terms - so the data file may be in the same format for both D6 and D7.

D6 module downloaded/enabled, but where is it?

JeniferTucker's picture

I have successfully downloaded the data export import module into my Drupal 6 modules directory using drush and enabled it using drush.

The details on the project page says:

"The admin page is at admin/config/system/data_export_import - the link from the module listing page is wrong for some reason. Will be fixed in the next version."

But this is just blank and so far I haven't been able to find out where the config page is in my D6 installation.

I don't even see the module listed in /admin/build/modules.

The screenshots on the project page only show D7 config layout which is slightly different to where to find things in D6 admin config

http://drupal.org/project/data_export_import

Have also tried looking in the README.txt file

INSTALLATION

  • Put the module in your Drupal modules directory and enable it in
    admin/build/modules.
  • Go to admin/user/permissions and grant permission to any roles that
    need to be able to export or import datasets.

USAGE

  • Configure and use the module at admin/content/data_export_import.
  • The dataset files are exported to and imported from
    {files}/data_export_import. Various methods can be used to manage
    the files and to move the files between Drupal instances.
    Although not tested the module at:
    http://drupal.org/project/webfm looks suitable for file management.
  • The user which is running the module needs to have permissions to
    be able to delete nodes when importing pages. It is expected that
    data exporting and importing will be carried out by the admin user
    which has correct permissions.
  • Currently the pages import has been created to import standard
    simple pages. It can handle a simple added text type CCK field -
    but any other file type fields are not being handled yet.
  • If you have taxonomy terms associated with pages this has not been
    coded for yet. It may work OK but you might be better to import
    the taxonomy terms separately first and then import the pages.

Any help appreciated - thanks.

If you do get this working OK

bailey86's picture

If you do get this working OK could you let me know please - migrating taxonomy terms from D6 to D7 was not the original plan - but it would be great to know that this works.

Upgrading from Drush 5.4 to 5.8 solved this issue

bailey86's picture

Upgrading from Drush 5.4 to 5.8 solved this issue.

Data Export Import module

bailey86's picture

Hi,

I have noticed an occasional issue where Drush installs the module and enables it - but then the config page is not there.

A workaround I've found to work is to disable the module via the admin GUI and then re-enable it.

This issue may be related to the version of Drupal and the version of Drush used. Could you let me know the versions you are using please?

Thanks,

bailey86

Just hit a 'drush cc menu'

rogerpfaff's picture

Just hit a 'drush cc menu' after installing modules. For some reason drush is not clearing the menu router so you can't see the modules config pages on your site.


Remember: I compute you!

Thanks millions for that

bailey86's picture

This seems to be the issue - reported at:

http://drupal.org/node/1649368

I'm going to see if the later version of Drush is OK.

Upgrading from Drush 5.4 to 5.8 solved this issue

bailey86's picture

Upgrading from Drush 5.4 to 5.8 solved this issue.

Drush and Drupal versions

JeniferTucker's picture

Hi there,

I am running Drupal 6.26 with Drush 5.8 and in the process of upgrading to Drupal 7.

Will try your suggestion #rogerpfaff to just hit 'drush cc menu' to see if that helps.

Unfortunatley I can't see the module at all in the admin GUI #bailey86 to try your workaround to disable the module via the admin GUI and then re-enable it.

Will let you know how I get on...

Thanks for all the useful suggestions everyone :-)

Or install the module without drush?

bailey86's picture

Or install the module without drush? It should list in the modules page fine.

Using Drush...

JeniferTucker's picture

Yey, got to see the admin page after suggestion made by #rogerpfaff of clearing the menu cache with the drush command after downloading, so the sequence was:

Download export import module.

drush -l [sitename] dl data_export_import

Clear the menu router.

drush -l [sitename] dl cc menu

Enable export import module.

drush -l [sitename] pm-enable data_export_import

Make sure your /files directory has permissions set so Drupal can mkdir the directory to store the data file in (example:/files/data_export_import/taxonomy_terms)

Once on the D6 admin GUI page, I created a data file which I was then able to copy over into my D7 install and use the D7 admin GUI to import.

Thanks again everyone :-)

distanceroller's picture

I am trying to export on a D6 but I and I am getting this error:

The data export functionality is not currently compatible with internationalization (i18n).

Any ideas?

Thanks in advance

Content migration, import, and export

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: