I've implemented a MigrateFieldHandler that allows to import Double Fields using Migrate.

It provides two subfields to map the first and second parts individually, using something like:

<?php
$this->addFieldMapping('field_double')->defaultValue('TRUE');
$this->addFieldMapping('field_double:first', 'source_value_1');
$this->addFieldMapping('field_double:second', 'source_value_2');
?>

Comments

chi’s picture

Which version of the Migrate are you using?

mpv’s picture

I am using migrate 2.5. I actually had a patch ready, but found a bug when I was about to upload it. Apparently migrate auto loads the .inc files declared in double_field.info, and since those files use simpletest classes you get a fatal error if simpletest is not enabled. #1844462: Class 'DrupalWebTestCase' not found is a similar issue in Location.

I will be working on it today and upload the patch later.

mpv’s picture

Status: Active » Needs review
StatusFileSize
new3.55 KB
new3.94 KB

Here's the patch. I removed the tests/*.inc files from the .info and included them in double_field_test_case.inc. The tests still run ok.

The migration handler is working for one valued fields, still needs to be tested for multi valued fields.

I have also rolled the patch against 7.x-2.3.

chi’s picture

Status: Needs review » Active

It looks as we do not need to mantain a field handler since 2.6 version of the Migrate.
#1996602: Default field handler

Can you confirm that?

davemybes’s picture

Issue summary: View changes

I'm using Migrate 2.6 and it automatically shows the two fields from double_field. So we shouldn't need a special field handler. The only question now is how would I create additional items of the field when migrating. In my case I have 10 pairs of fields (20 separate fields), that I would like to move into double_field, thereby having a maximum of 10 values for one double_field ... er ... field. I'm using migrate_d2d_ui as well, so I can only associate one pair of fields with the double_field in the UI. Guess I'll need to do something in a prepareRow method. If I figure it out before someone has an answer, I'll report back here.

mpv’s picture

Status: Active » Closed (won't fix)

Thanks @incrn8. Since this issue was about adding migrate support to double field and you confirm it's not needed with migrate 2.6 I'm closing it.

Regarding your question, I have never used migrate_d2d_ui so I don't know how you would do that from the ui, but if the source field is an array (you can build that in prepareRow as you suggest) it's imported as a multi-valued field.

mlncn’s picture

Status: Closed (won't fix) » Active

Migrate 2.5 is still the current stable release, and i'm contributing a module that relies on that stable release of Migrate and Double Field.

Would you accept a re-rolled patch? (Needed a little manual intervention to apply now but mpv's patch worked perfectly.)

mlncn’s picture

Status: Active » Needs review
StatusFileSize
new3.78 KB

Well here's a patch in case you are open to it!

Status: Needs review » Needs work

The last submitted patch, 8: double_field-add_migrate_support-2083695-8.patch, failed testing.

timodwhit’s picture

It looks like there is still possibly an issue with migrate and double field at 2.6. I'm getting a lot of notices about "Undefined index: second" and the field is not being recognized as empty.

Using the patch found in #3, I was able to get the migration working and the field is properly recognized as empty.

timodwhit’s picture

Status: Needs work » Needs review
timodwhit’s picture

timodwhit’s picture

Status: Needs review » Reviewed & tested by the community

Sorry, not purposely spamming, just hid the wrong file and now marking as RTBC. My bad

chi’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Current stable version of Migrate module is 2.8. Do we still need this patch? If so can you confirm it would not break migrations made running with Migrate 2.8 module?

chi’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)