Closed (works as designed)
Project:
Migrate
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
6 May 2012 at 15:15 UTC
Updated:
22 May 2012 at 19:06 UTC
Importing from a file defined as a URI, but from an existing D6 site, so we already have a fid that we want to keep.
In MigrateDestinationFile->import() there is a line,
$file = $source->processFile($file->value, $file->uid);
$file here already has a fid, but this call eventually also calls file_save which returns a $file with a new fid, breaking our migration.
Comments
Comment #1
muhleder commentedSo it looks like core file_save() sort of prevents this possibility, since it uses drupal_write_record to do either an update or insert based upon whether or not $file->fid is set.
If we set $file->fid, file_save() will try to update a row and we get nothing inserted.
Comment #2
mikeryanAre you saying that you're trying to use the same fid in Drupal 7 as you did in Drupal 6, and are explicitly passing that? That's not going to work, as you point out - core does not support adding a new file entity with an explicit ID. Nodes and users have the "is_new" support for doing this, but they're the only core entities that support it.
The real question is, why do you want to keep the fid? If you're expecting that you need the same fid to maintain relationships to, say, file fields, it isn't necessary - the sourceMigration() support in Migrate will rewrite old fids to new fids so relationships are not broken.
Comment #3
muhleder commentedFor completeness I guess, eg there might be a token in a text area linking to a specific file id, or a custom module might provide zipped downloads based upon a path including a file id eg /downloadzipped/$fid
So core file_save is quite a short function and what I've done for my case is provide an alternate version in the class to save with the file id.
Ugly but working. I've also altered $source->processFile($file->value, $file->uid) to pass in the file object as well of course. Don't have a patch for this to hand, figured it would be too brittle to get in.
Comment #4
mikeryanThe nice thing about the new file handling is that you can define your own file class - one that calls your custom file_save() in place of core's, treats $value as a file object, etc.
Comment #5
mikeryan