Thoughtful Dragon

Converting Drupal 6 CCK content types into Drupal 7 entity bundles

So one problem that I had for my work was there was a bunch of CCK content types in an old D6 site that needed to be brought in to the new (complete rebuild) D7 site. CCK had this content type import/export capability, but D7 does not. The import/export can be added using the Bundle Copy module, but the format is incompatible with that of CCK. Because of the number and size of the content types, I could not simply recreate them in D7 as that would take far too much time. So I wrote a program to convert content types from a D6 Features module exported from the old D6 site into the Bundle Copy format. With this setup, I can bring over tens of content types in an hour where one content type took me 8 hours (Extreme example, it was a big one). Here’s how you can do the same:

Use the Features module in D6 to export all of the content types you want to bring over and save the result somewhere convenient. Extract the module and grab the conversion code from here.
Place converter.php and export.sh in the extracted module directory.

You can call converter.php directly like this:

php converter.php -m exported_module_name

This will convert and output all of the content types you exported to stdout.
I have found that my Drupal install will bulk if I try to import too many things at a time, so there is a -t option for converter.php that will allow you to export just one content type:

php converter.php -m exported_module_name -t content_type_name

Need a list of all the content types? use the -l option:

php converter.php -m exported_module_name -l

Outputting one content type at a time is tedious when you have a large number to move, so I wrote export.sh to mostly alleviate that. Invoke it like this:

./export.sh exported_module_name

It will export all of the content types into individual files in a directory named exported.
The best is for those who have X11 and xclip:

./export.sh exported_module_name -c

This will pipe each converted content type to xclip, which copies it to the clipboard for easy pasting. It waits for a keypress after each content type.

Just paste the output (however you get it) into /admin/structure/types/importon your D7 site and click import.

And that’s it. You may need to adjust the script to handle extra types of fields if it doesn’t handle them correctly.