I have a need to be able to rename a file after it has been downloaded from a URL, but before it is saved to the entity. The system I'm importing from (Ektron) for some reason converts the actual file name (pdfs in this case) to a hex value, ie, something like from IT266_final.pdf to 8E738CC1-169C-4BFE-A5F6-F4CEE69B93FD.pdf. Therefore, it is available on the source system as http://www.sourcedomain.com/assets/0/16/80/98/8E738CC1-169C-4BFE-A5F6-F4.... I would like to be able to rename it to IT266_final.pdf before saving it in the node, but I'm not sure where to do it. prepareRow() allows me to change it right after the data has been pulled from the source database, but I think that's before the file has actually been accessed at the URL, so that's too early. If I access it in prepare(), the $entity object has already been created, so it looks like I would need to chance all the references to the file name in there as well as in $row, so that's too late.
Am I misunderstanding, or is there a better place to convert the file name?
Thanks.
Comments
Comment #1
wonder95 commentedAfter re-reading http://drupal.org/node/1132582 again, I'm thinking that I need to have a field level prepare() method to do this, since according to the docs
So how do I define a field_level method to do this? I can see that FileFieldHandler has a prepare() method that does the work of saving the module. Where would I put my code to rename the file before actually saving it?
I hope I'm not killing kittens here, but I have one more question. I've been assuming that for my destination I should use the MigrateDestinationNode class, since I'm importing this to a node entity. Should I be using the MigrateDestinationFile class instead?
Thanks.
Comment #2
mikeryanConsolidating with #1308102: Support specifying the destination file name/path. This issue of renaming during import falls under #1240928: META: Refactoring of file destination/field handlers, which is targeted for Migrate 2.4.