When migrating content from other CMS to Drupal with Migrate & Migrate Extras modules, I expected that the filenames were transliterated for FileFields (specially because of many of them were FLVs to be played with Flowplayer that rejects URIs with spaces).
I made a quick patch (against 6.x-3.7) to tell FileField to use the Transliteration module if:
- module installed and the transliterate file uploads option is enabled
- if the call to
field_file_save_file()(infield_file.inc) isn't originated by a HTTP request, checking the$_FILESsuperglobal
A test method was added to filefield.test to verify the correcteness of the code.
| Comment | File | Size | Author |
|---|---|---|---|
| filefield.transliterate_when_file_created_programatically.patch | 3.53 KB | Anonymous (not verified) |
Comments
Comment #1
quicksketchHmm, my preference when saving files programmatically like this is to call the transliterate functions directly before saving the file. As a programmer I expect my files to be renamed unless I ask them to be renamed.
Comment #2
Anonymous (not verified) commentedWhen I made this, I was thinking in consistency. Actually, isn't the better way because if I just used the file API, it would not transliterate the filenames also and would it only if the core were hacked.
I thought FileField would be the better place as other modules could use it to submit files programatically in migration tasks.
Because the way Transliteration works (using
hook_init()to transliterate the filenames), it seems too much to require this consistency from FileField. However, how can I transliterate the$file->filenameif thestdClassobject is created insidefield_file_save_file()? In a migration task, I would need to prepare the files, maybe copying and renaming but for larger and complex migrations, this could be a very time consuming task.A simpler approach would be an extra parameter for the filename. I don't know if extra parameters make your taste but seems more affordable to me than making a change full of side-effects like I did in my patch.
Comment #3
quicksketchI think the simplest approach is simply manually calling transliteration_clean_filename() if you want it to clean the file name before you save the file at all. There's no point in adding a parameter to to FileField when it doesn't do anything but call a function in Transliteration module.