3

I'm working on migrating a fairly large blog type site from WordPress into Druapl 7. The WordPress Migrate module has imported the basic blog content very well (title, body, tags, etc), however there were custom fields set up in WP that do not import.

Looking at the xml file, there's really just one extra piece of info I need. A line for a video file (which is a code for a youtube video).

Here's how the code for this looks in the XML file:

    <wp:postmeta>
        <wp:meta_key>Video_File</wp:meta_key>
        <wp:meta_value><![CDATA[8ENbMuVQCYE]]></wp:meta_value>
    </wp:postmeta>

I have decent PHP experience, but the only customizing I've done in Drupal are relating to themes. Can I write a little addition to the WordPress Migrate module to insert this extra piece of info? Since the module migrates everything else nicely can I create a new little module that would go through the same xml file, find the matching node (by post date/time, title, some distinguishing piece of info from the xml file) and then add in the video info (assuming I would first create another row in the DB table)?

I'm at a bit of a loss, and since I need to bring in close to 1000 posts (most of which have the video code), I really need to fine a solution that doesn't involve me editing every single node by hand to add in the dang code.

I should also mention I currently don't have a CCK field in Drupal for the video code... that just dawned on me, so I'm off to create one and then re-migrate a portion of the blog (I downloaded it in multiple xml files for testing).

Update: Created that CCK field, re-imported the blog, and sadly it didn't work :) Not that I thought it would to begin with (nothing is ever that easy).


Update: I've been attempting to modify the WordPress Import module with little success thus far. This meta field is just some text, so I'm hoping to figure out where to add in the info I need to have it process correctly. I'm sure I need to tell it which cck field to insert the new data, just have to find it!


Another Update: Working on adding a WP plugin to export all the content as a CSV, then going to use the Feeds module to attempt to import everything.

My backup is going to be to use the wordpress_migration module to import the basic stuff (title, body, tags, etc), then write a custom php page to add the video links... I'm basically thinking to find the title in the node table, grab the nid, then create the entry in the video_field in the db table. At least that's how it's currently laid out in my head, whether or not that works in real life remains to be seen.

Course hopefully Feeds works just fine and I won't have to try the backup!

3

Neat. It looks like wordpress is storing a small fragment of the youtube url in the DB. I'm not sure how the the cck video field stores content -- probably in its own field, and it probably has to be set for "Youtube" before you attempt a migration.

Once you figure out where the youtube ID will be stored in a drupal field. See the documentation on how to extend worpress migrate:

  1. Extend the appropriate class, such as the WordPressBlogEntry class with your custom behavior - add field mappings in __construct(), manipulate the body ($row->content) in prepareRow(), etc.
  2. Extend the WordPressBlog class, and override migrationClasses to point to your custom classes:
<?php class MyCustomBlog extends WordPressBlog {
public function migrationClasses() {
    $classes = parent::migrationClasses();
    $classes['WordPressBlogEntry'] = 'MyCustomBlogEntry';
    $classes['WordPressPage'] = 'MyCustomPage';
    return $classes;
} }

In your custom migration class you would then define the migration of a field using a Mapping as something like:

 // dest (a field in the node) <- source
 $this->addFieldMapping('youtube_url', 'source_yt_value');

In your custom migration class you will of course have access to the typical helper methods used in migrations to "prep" the data (retrieve the youtube url from that CDATA crud), and translate it into a valid video blurb for drupal.

  • The youtube info is quite literally just plain text. Whoever set up the blog created a custom simple text field (looks like the WP plugin is called "Custom Field Template") that will accept text (the youtube id), and then later on parse it into a player. I'm fine with doing something similar, I just need to get the text to import with the rest of the content. I'll try what you wrote, however I'm not a Drupal developer by any means, so I'm not optimistic :) Thanks for the suggestion! – cfox Nov 19 '12 at 16:34
  • No such luck thus far - I'm going to install another wp plugin to export the site as a CSV and try using the Feeds module. Adding code to the Wordpress_Migrate module will be a last resort (since I have no idea what to add or where to add it). – cfox Nov 20 '12 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.