Problem/Motivation

When migrating Single on/off checkbox fields from D6 to D7, the "On value" label from D6 is replaced with "1" in D7. This makes the purpose of the checkbox unclear on the node edit form. Also, due to this bug: #1898922: Unable to Modify Labels in Boolean Fields, you cannot change the label.

Proposed resolutions

1. A simple improvement would be to check 'Use field label instead of the "On value" as label' by default. This would provide a more meaningful checkbox label on the node edit form. I've written a patch for this and will post it here.

2. Another option would be to take the allowed values from D6 and reformat them for D7. This would allow us to preserve the original D6 values and labels, rather than overriding them with 1 and 0. However, this would require using the using the 'Allowed values PHP code' field. I'm happy to write another patch, but I'm hesitant to set the values using an "Advanced usage only" field, unless php was used for the D6 field. I'd like to hear other people's opinion on this before moving forward.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikehues’s picture

Status: Active » Needs review
FileSize
942 bytes

Here's a patch that defaults the 'Use field label instead of the "On value" as label' to checked when migrating list fields using the Single on/off checkbox widget. I created this patch from the root of the cck module. Let me know if I should recreate the patch from the root of the content_migrate submodule.

mikehues’s picture

Do not use the patch from #1.

I did some additional investigation and testing and found that the problem is worse that I thought. The checkbox values are changed along with the labels. While some of my content in D6 had the checkbox checked, all of the D7 content is unchecked. This appears to happen with both regular allowed values and php allowed values. I intend to put together a list of steps to reproduce the problem when I have time. I'm hoping to get to it tomorrow.

mikehues’s picture

Category: feature » bug
Status: Needs review » Active

This issue can be reproduced by trying to migrate a D6 text field that uses the single on/off checkbox widget and uses keys other than "0" and "1". For example, these allowed values fail to migrate cleanly:

no|do not contact me
yes|you may contact me

The problem arises because content_migrate converts text fields to list_booleans and D7 forces the use of integer keys. I attempted to massage the field settings and data records into a suitable form for D7 using content_migrate's field_alter and data_record_alter hooks. But I did not have much luck.

Migration does work as intended when using integer keys. So, as a workaround, I simply updated the fields and content on my D6 site to use integer keys prior to migrating.

pandroid’s picture

Mikehues:
We have the same issue. By 'changing fields and content to use integer keys' do you mean the database field type?
i.e. Changing the D6 database field to be an int, and the values to be 1 & 0 rather than yes & no?

mikehues’s picture

pandroid, you do not have to change the db field type. Simply change the key values in the "Allowed values list" of the field in question. For example, change this

no|do not contact me
yes|you may contact me

to this

0|do not contact me
1|you may contact me

You will then need to update any nodes that use this field to use the new values. You can do this with the Drupal admin, but updating the database directly will be much quicker. With the field options and node content updated, everything should migrate properly.

DamienMcKenna’s picture

Priority: Normal » Major

This results in broken fields, so I'm bumping it the priority to 'major'.

The problem is in content_migrate_extract_allowed_values where it predefines $allowed_values for list_boolean, and then proceeds to add the existing (string) values to the array. It is at this point that the current field is broken.

What should happen is that it should queue up additional tasks to fix the existing content, like what happens with other field types.

DamienMcKenna’s picture

Status: Active » Needs review
FileSize
3.62 KB

Lets see if this works.

It does several things:

  1. Fixes content_migrate_extract_allowed_values() to properly update list_boolean values.
  2. In content_migrate_text_field_alter() it keeps a copy of the original values in $field_value['settings']['legacy_values'] so it can be used later.
  3. In content_migrate_text_data_record_alter() it swaps out the old values for the new ones, based on the legacy_values array stored earlier.

I haven't tested it yet.

DamienMcKenna’s picture

Might it be worth adding an update script to fix the settings for existing sites?

DamienMcKenna’s picture

I should also mention that because of the fact the new list_boolean field only accepts integers, the converted data is all reset to 0, i.e. this results in dataloss.

DamienMcKenna’s picture

FileSize
3.63 KB

Updated, hoping this grabs the correct values. Also, doh.

DamienMcKenna’s picture

FileSize
3.71 KB

This fixes my incorrect use of array_pop instead of array_shift. Also, doh.

DamienMcKenna’s picture

FileSize
948 bytes

This patch is completely rewritten to depend upon #1996770: content_migrate's field-module handling is hardcoded, which really needs to be committed.

DamienMcKenna’s picture

FileSize
1.09 KB

This'll work better. *cough*

DamienMcKenna’s picture

FileSize
3.18 KB

I'd accidentally included some code for this patch in #1996770, this includes all code needed to fix the checkboxes.

DamienMcKenna’s picture

FYI I've finally gotten these two patches to work on my local test bed without any problems, hopefully someone out there will be able to test them and give them the RTBC of approval so that 2.5 years after launch we can have a slightly more reliable upgrade for CCK.

DamienMcKenna’s picture

FileSize
4.25 KB

This patch doesn't store the legacy values in the field's settings any more as that turned out to be causing problems. Instead text_content_migrate_data_record_alter() loads the settings again when needed.

DamienMcKenna’s picture

FileSize
4.45 KB

Fixed #16, had to load the field specs again as content_migrate_extract_allowed_values() is ran again before the data is migrated.

fender177’s picture

I've been having this same problem - thank you for tackling this! I am having trouble applying the patch (#17) though. It fails in hunk #3... Any thoughts? Do I need to apply all of the patches in order?

DamienMcKenna’s picture

@fender177: You need to first apply the patch from #1996770: content_migrate's field-module handling is hardcoded.

fender177’s picture

Thanks, @DamienMcKenna, that worked for applying the patch. Much appreciated!

DamienMcKenna’s picture

Status: Needs review » Needs work

I guess I need to put it through its paces again. Time to find a D6 client and test out an upgrade for them :)

fender177’s picture

So here is an interesting one for you... I've been documenting the process of upgrading from d6 to d7, which involves starting from scratch/a snapshot. It appears that before I apply this patch, the CCK migrate module is able to migrate filefield/image fields. After the patch, they are listed as unavailable... Thoughts on that?

I think I'm going to migrate all of the available fields with the patched CCK module, revert back to the unpatched version and see if I can then migrate the filefield/image fields.

Thanks for your help thus far!

DamienMcKenna’s picture

For issues with the file patch please follow up on #1996770: content_migrate's field-module handling is hardcoded.

russellb’s picture

I have checkbox migration failing.

I Tried applying cck-n1996770-2.patch followed by cck-n1913072-17.patch as described above.

The field definition looked a bit better in D7 but all values were set to 0. Previous values were a mix of 'on' and 'off'

russellb’s picture

I've sorted this out with manual fix. I used the patches above to migrate the CCK field to D7 core field, edited the field in D7, then ported the lost data and added the bundle manually. If anyone needs more details please contact me.

colan’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Issue summary: View changes
Status: Needs work » Fixed

Thanks! Committed in 6d662c9. Let's fix any related problems in others tickets.

Status: Fixed » Closed (fixed)

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

ssantaana’s picture

Hi russellb,

I'm a new drupal dev and I'm running into the same issues above. I've applied patch 17 but the data did not migrate. All values are still set ot 0.

Can you provide more detial on what you did?

1) I used the patches above to migrate the CCK field to D7 core field, (Which ones all of them?)

2) edited the field in D7, (What did you edit, what did you change?)

3) then ported the lost data (What did you use to port the data?)

4) and added the bundle manually. (How did you do this? Where?)

Apologies in advance and Thanks!

russellb’s picture

Hi ssantaana,

It's a while ago now that I did this port, so my experience is a bit out of date but I will try to help.

Looking at this issue queue, I can see that colan has made a commit, so I would recommend that the first thing that you try is using the latest release of the module that includes the commit to fix this. 7.x-3.0-alpha3 has this new code included, so you should not apply the patches as I described.

myha’s picture

Hi colan,

Looks in the patch #17 (what is commited to module) there is typo at content_migrate.text.inc line 173. It is:

$field_specs->global_settings = unserialize($results->global_settings);

Need to be:

$field_specs->global_settings = unserialize($field_specs->global_settings);
colan’s picture

Status: Closed (fixed) » Needs work

@myha: Thanks. Can someone else confirm/test? Patches welcome!

c4rl’s picture

Status: Needs work » Needs review
FileSize
798 bytes

Remarks in #30 seem to work for me. One-liner attached.

DamienMcKenna’s picture

markabur’s picture

Status: Needs review » Fixed

Going back to Fixed per #27.

The patch in #32 is a duplicate of #2212961: $result should be $field_specs in text migration

Status: Fixed » Closed (fixed)

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