How to easily migrate pages from Drupal 6 CCK content types to Drupal 7 fields using the Feeds module
One of the easiest ways to upgrade between version 6 and version 7 of Drupal is to re-build your site in Drupal 7, and then use the Views Data Export and Feeds XPath Parser modules to move your pages and articles into your new site.
This post shows you the details of setting up both a D6 View you can export and a D7 Feeds importer you can use to migrate that View content.
If you notice anything missing or confusing in these instructions, please post a comment, so that I can improve this tutorial. Thanks!
- Before you begin
- Set up your old D6 site
- Set up your test site in D7
- Known import Problems
- For more information
- Read other good posts on general updating strategies:
- Do a COMPLETE backup of your site (files, database, everything).
- Create a SEPARATE Test site to use for this process, so you don't kill your Live, Production site.
- On your old D6 site, install Views, Views Data Export, CTools & any modules they depend on.
- I'm using "Views Data Export", instead of the RSS display that is native to Views, because RSS made it difficult to output the path and Date fields correctly.
- Finally, create a separate View for each content type you want to move.
If you want to skip the instructions, you can just import this View code using CTools.
- Add a view type of "Node"
- Set filters for only Published Pages.
- Add fields for each bit of data you want to migrate, such as these common fields:
- Post date
- Add a "Data Export" display to the View.
- Under "Style settings", choose "XML file". For "Data export: Style
options", UNCHECK "Provide as file" and DO CHECK "Transform spaces". For
Transforming spaces, choose "Dashes", because XML does not process element
names if they have spaces in them.
- Under "Data export settings", set a "Path" to this new feed. For example: feeds/pages/all.
- Under "Fields", choose "Node: Path" and, under "Rewriting", check "Rewrite
the output of this field". Enter
[path]into the the text box, so that you will only get the internal path and not an entire URL.
- Again under "Fields", choose "Node: Post date" and, under "Rewriting", check
"Rewrite the output of this field". Enter
[created]into the the text box, so you can change the date formatting. For "Date format", choose "Custom" and enter
Y-m-d H:i:s Ointo the text box, this will output your date in a format that will be easier to import into the new Drupal 7 site.
- Don't link "Title" or "User" fields to their nodes, or they will output link tags in the feed.
- Under "Style settings", choose "XML file". For "Data export: Style options", UNCHECK "Provide as file" and DO CHECK "Transform spaces". For Transforming spaces, choose "Dashes", because XML does not process element names if they have spaces in them.
- SAVE your View, or all your changes will be LOST!
you click on the link to your new Feed
http://mylivesite.gatech.edu/feeds/pages/all), you may see something like
this XML code:
<?xml version="1.0" encoding="utf-8" ?>
<Post-date>2011-04-28 13:04:39 -0400</Post-date>
<Body><p>Our employees are brilliant! And attractive, too.</p></Body>
<Post-date>2011-04-28 13:06:27 -0400</Post-date>
<Title>Our Location and Hours</Title> <Body><p>More fascinating HTML goes here, including an <a href="http://mysite.gatech.edu/fakedirectory/pagename">absolute link</a> whose URL may need replaced if I am changing my site's Domain Name.</p></Body>
- Set up your new D7 site with whatever themes, modules & configurations you would like.
- Create custom content types with the same fields as you used in your Drupal 6 site. The Bundle Copy module will speed up your CCK re-creation, it allows you to import a generic content type with a pre-set collection of fields and settings you often use.
- Warning: pay attention to Text Input Formats or you might strip out important HTML tags from your Body field when importing. So, allow all users (for now) permission to use the "Full HTML" text format. Likewise, set the default text format for your new Page content type to use "Full HTML".
- Install Feeds, Feeds XPath Parser, CTools & any modules they depend on.
- Warning: the Pathauto module, if enabled, will overwrite/re-create path aliases for all the pages you import, so you might want to disable Pathauto before importing.
If you want to skip the instructions, you can just import this Feeds Importer code using CTools.
- Add a feed importer at
- For "Basic settings", choose:
- Attach to content type: "Use standalone form".
- Periodic import: "Off"
- CHECK: Import on submission
- For "Fetcher", use "HTTP Fetcher" and choose:
- CHECK: Auto detect feeds
- For "Parser", choose "XPath XML parser".
- For "Processor", choose "Node processor" and then use these Settings:
- Update existing nodes: Replace existing nodes
- Text format: Full HTML
- Content type: Page
- Author: YourUserName (Note: To import page authors, you have to import your users BEFORE importing pages).
- Expire nodes: Never
- For "Node processor Mapping", add "XPath Expression" for each of these
- "Node ID" and make it Unique
- "User ID"
- "Published date"
- "Path alias"
- Under "XPath XML parser", type in your XSL queries like this:
- At the bottom of the page, do NOT check any boxes under "Select the queries you would like to return raw XML or HTML", as this will wrap your field data in an extra <Body> tag.
- Be sure to Save your settings.
- Go to the
/importpage on your site (for example:
http://mysite.gatech.edu/import) & choose the importer you just created (D6 XML pages).
- In the Import > URL text box, enter the web address of the feed view you created
earlier, for example:
http://mylivesite.gatech.edu/feeds/pages/alland click on "Import".
- Hopefully, you'll see a successful Status message that says something like "10
imported items total".
- Do some sample checking of the pages you imported. Make sure your new pages are identical to those on the old site.
- Consider using Views Bulk Operations (VBO) as a great way to add tags or do mass corrections to this imported content in your new Drupal 7 site.