Migrating WordPress Images to Drupal with Migrate 2.4

I’m having a time migrating images from WordPress to Drupal with the Migrate 2.4 module. Here are my mappings:

$this->addFieldMapping('field_image','images');
$this->addFieldMapping('destination_file', 'images');
$this->addFieldMapping('field_image:source_dir')
 ->defaultValue('/Users/grafa/htdocs/wordpress/wp-content/uploads');
$this->addFieldMapping('field_image:file_class')
  ->defaultValue('MigrateFileUri');

The images come from a function that queries the wp_postmeta table then returns the result to the prepareRow() function.

Read More
function getImages($row) {
$post_id = $row->id;
$results = db_query("
  SELECT pm.post_id, pm.meta_key, pm.meta_value FROM streetroots_wp.wp_postmeta AS pm LEFT JOIN streetroots_wp.wp_posts AS p ON pm.post_id=p.id WHERE p.post_parent = $post_id AND pm.meta_key='_wp_attached_file';");

$images = array();
foreach($results as $result) {
  $images[] = $result->meta_value;
}
return !empty($images) ? $images : NULL;
}

This basically returns the image name and relative path from the wp_postmeta table something like ‘2012/05/figure1.jpg’. I then use prepareRow() like this:

 function prepareRow($row) {
$row->images = $this->getImages($row);
}

I’m guessing there’s something funky with how I’m using the new-ish migrate module that handles the file fields. The sql is outputs the file names correctly but it doesn’t seem like the images are getting copied over. This is a Drupal 7 using Migrate 2.4. Any help is appreciated.

Related posts

Leave a Reply

2 comments

  1. You might want to have a look at the beer.inc lines 377 – 383 within migrate_example folder and at the associated content type *migrate_example_beer* which has an image field defined not a file field which was my mistake and lead to my images not being populated.

    Hope this helps!