Hi guys,
I'm trying to migrate my content and image files from another CMS to drupal. I'll be importing my contents into nodes using node_import, but the images is the only thing left. Currently I have a cck imagefield (named content_field_screenshot) in the node which will have multiple images in it.

After much searching, I think I'll import the images using sql scripts, here are the steps:
- move images files to /files/images/
- add multiple entries into 'content_field_screenshot' table
- add entries into 'files' table
- update 'sequences' table (I have to update row: files_fid, right?)

My questions are, are these steps good enough? Do I miss any tables/steps which I may have overlook? Or is there any better/easier way to do this?

Comments

epicflux’s picture

Have you checked out the imagefield import module?

natrio’s picture

Yes, but imagefield_import can't import into existing node I think..

epicflux’s picture

Having to setup all the appropriate tables & values manually seems problematic.

I've done a lot of importing from other databases, including moving images over, and I try to let Drupal handle the setting up of tables & values.

(I wrote a little about this on my own site about moving from Flexinode to CCK. While not much of the instructions there will help you I think the part about moving files might help.)

I'm assuming that somewhere you've got a table setup or something that connects the individual images to their destination nodes.

Put your pics in a separate folder from your Drupal files folder, because Drupal deletes the source file, and this way you know if any images were skipped.

Setup your script to load the node, grab the image path, and then setup your image values like this:


// If there's a picture move it over

//$picture would be a full path to the file

if (file_exists($picture)) {
  $node['field_thumbnail'][0]['fid'] = 'upload';
  $node['field_thumbnail'][0]['filename'] = $picture_filename;
  $node['field_thumbnail'][0]['filepath'] = $picture;
  $node['field_thumbnail'][0]['alt'] = $title;
  $node['field_thumbnail'][0]['title'] = $title;
}

Run all the values through the standard node save process:

  $node = (object)$node;
  node_object_prepare($node);
  $node = node_submit($node);
  node_save($node);

Then test, test, test before running the script for all your images.

natrio’s picture

Hmm..definitely looks easier. I'll try it this weekend, and hope all is well..

Thanks for the suggestion, epic ^_^