I have a legacy site with user photos and documents that I would like to import in and attach to entities using File/Image field types. I have everything else working fine, but not sure how to approach this, and Googling didn't provide much or maybe I searched wrong.

Is there a solid recipe for fetching files with URLs and uploading/attaching to entity during a migration?

Comments

mikeryan’s picture

Component: Code » Documentation
Status: Active » Postponed (maintainer needs more info)

Have you tried just mapping the URL to your image field? E.g.,

  $this->addFieldMapping('field_attachment', 'url_from_source_db');

If it doesn't work directly, take a look at beer.inc and wine.inc (mappings of field_migrate_example_image) in migrate_example to see some of the arguments you can pass.

kevinquillen’s picture

Oh, so you can just pass the URL to the Field and Drupal takes care of the rest? That's pretty sweet. I'll try that out.

Sifro’s picture

have you been able to migrate your file fields? I'm having the same problem too, and i'm finding it pretty hard.

kevinquillen’s picture

I did not get to try this yet. I expect to do so on Monday.

Sifro’s picture

Ok let me know if you discover something useful... meanwhile, i'm trying my luck with the node_export module... it has some problems with node attachments, but they are being solved. Now a single node export works fine, but there are still memory problems with bulk exports (but a good workaround may be to write a bash script to bulk export nodes one by one).

Sifro’s picture

Ok, i can definitely say that for simpler node-with-attachments imports, node_export module works perfectly! (use latest dev)

kevinquillen’s picture

I've found that Node Export was unpredictable and hard to make work for nodes with cck or Fields in 6 or 7. Thus is why I am using Migrate, which has worked great.

Anywho, attempting files now. Will let you know of progress from #1.

kevinquillen’s picture

Just attempted to import documents and link them to their local file system. Here is the error I got for all 1051 document nodes:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null: INSERT INTO {file_usage} (fid, module, type, id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => 52305 [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => 1 ) (/sandbox/includes/file.inc:664)


$this->addFieldMapping('field_document_upload', 'filename');

field_document_upload is a File field, and filename is the old local filename on the server.

kevinquillen’s picture

It appears spaces need conversion to %20 to get rid of the first error.

Now I just can't make the filename be the original file name. Here is snippet:


public function complete($document, $row) {
    db_update('file_managed')->fields(array('filename' => $row->originalfilename))->condition('fid', $document->field_document_upload[LANGUAGE_NONE][0]['fid'])->execute();
  }

The first two times I tried this, it created two document node entities, and a rollback did not remove them.

mikeryan’s picture

The file handling has been completely rewritten for Migrate 2.4 - see http://drupal.org/node/1540106. If you upgrade to the latest -dev, you should find it easier to work out how to migrate your files.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)