Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I'm using CCK's filefield module and have a multi-value file field on my custom content type. It's actually an imagefield, but I don't think that should make any difference. I can easily migrate one filefield entry but am unsure how to handle it when multiple files need to be migrated for the one field. I'm trying to do it in a hook_migrate_prepare_node() function, but don't know what to set the $node->field_file_sourcefile variable too. I'm guessing it needs to be some sort of an array or object.
Cheers,
Stella
Comment | File | Size | Author |
---|---|---|---|
#18 | migrate_extras-731992-18.patch | 1.85 KB | cedarm |
#18 | migrate_extras-731992-18.patch ignoring whitespace | 1.41 KB | cedarm |
#15 | 731992-6--1-1.patch | 1.71 KB | justintime |
#14 | 731992-6--1.patch | 3.23 KB | justintime |
#3 | migrate_extras-731992.patch | 2.74 KB | a_c_m |
Comments
Comment #1
stella CreditAttribution: stella commentedAttached patch adds multi-value filefield functionality. To use, you will need to implement a hook_migrate_prepare_node() that sets up your filefield (e.g. $node->field_file_sourcefile) as an array of filepaths. The patch also works if just one filepath string (not an array) is configured.
Comment #2
a_c_m CreditAttribution: a_c_m commentedAhh ok, so after reading this for a while i think i get it.
Its expecting you to pre-set the $node->$source_key value in your own hook_migrate_prepare_node() to be an array of file names.
However it no longer cleanly applies to dev
Comment #3
a_c_m CreditAttribution: a_c_m commentedUpdate to the patch, so it applies cleanly.
Required for http://drupal.org/project/migrate_drupal
Comment #4
3dloco CreditAttribution: 3dloco commentedHello,
Thanks for this patch! I am looking into using it for several multivalue filefields so this is great.
I have one of the filefields that is not so straightforward and I'd like to know how best to use it to migrate the data over. I have this multivalue filefield that is inside a multigroup (cck3.x-dev)...together with two other fields, one has content taxonomy and the other is just a text field.
Below is how I've set the multigroup on Drupal:
and here is how I have the incoming data/files
I'd like to know whether it is possible to do it with migrate extras+the multivalue fields patch above.
Thanks,
KH
Comment #5
ptoly CreditAttribution: ptoly commentedPatch @ #3 is failing on migrate_extras-6.x-1.0-beta1
Comment #6
a_c_m CreditAttribution: a_c_m commentedYeah, looks like dev has moved on since i rolled this patch. Its not that complicated, so should be easy enough to re-roll.
Comment #7
Alex Andrascu CreditAttribution: Alex Andrascu commented+1 subscribe. Having the same problem please please please post the new patch against current version and give us an real world example of hook_migrate_prepare_node() implementation for multivalue filefields.
Thank you so much :)
Comment #8
justintime CreditAttribution: justintime commentedThanks Stella for the patch - it works great for me. However, in my case, the files in the DB were stuffed into one column, as comma separated values. I modified the patch so that it "just works" when it encounters such an instance, and in doing so eliminated the need to write any PHP code at all to import multi-value filefields.
The one caveat here is that your filenames cannot contain commas. I pity the soul who has to deal with that arrangement :)
Is this a patch worth posting, or is the "no commas in filenames" requirement to stringent?
Comment #9
stella CreditAttribution: stella commentedComment #10
justintime CreditAttribution: justintime commentedgah, sorry for the title change... normally I'm not so bone-headed.
Comment #11
wapnik CreditAttribution: wapnik commentedWhat about using the field "edit-multiple-separator" from the "migrate-content-set-mappings" form instead of hard-coded commas?
Comment #12
justintime CreditAttribution: justintime commented@wapnik: even better!
If the patch would get accepted, I can take the time to code it up against current dev.
Comment #13
wapnik CreditAttribution: wapnik commented@justintime: yeah, go for it!
Comment #14
justintime CreditAttribution: justintime commentedI unfortunately didn't have time to test - @wapnik, can you review? This patch is against 6.1 HEAD.
Comment #15
justintime CreditAttribution: justintime commentedSilly Eclipse -- there's some extra cruft in that patch. Use this one instead.
Comment #16
wapnik CreditAttribution: wapnik commentedYes works good for me.
One note. If the filefield used is not a multiple filefield, the first file is migrated. The same case i think if there are less files permitted in the filefield than the record is holding, remaining files are rejected. That's the behavior i was expecting but i think it will be ok to put a message about those remaining files somewhere. A system (error) message will be enough.
Comment #17
moonray CreditAttribution: moonray commentedsubscribe
Comment #18
cedarm CreditAttribution: cedarm commentedPatch from #15 works for me as well.
I went ahead and rolled the patch from #825352: Unable to migrate nodes containing empty (not required) filefield paths into this since they affect the same lines of code. And for readability, the same patch ignoring whitespace. I can certainly post another patch over on #825352 after this one is committed if you'd rather keep them separate.
Comment #19
tobiassjosten CreditAttribution: tobiassjosten commentedThis ("ignoring whitespace") works great! Thank you so much for fixing this, justintime and cedarm!
The only change I'd like to see is indenting that if statement you're wrapping with a foreach, as per the coding standards.
Comment #20
cedarm CreditAttribution: cedarm commented@tobiassjosten: indenting as per coding standards is the whitespace change.. apply the other patch and feel better that your site runs pretty code :)
Comment #21
pthanos CreditAttribution: pthanos commentedCould I have some context on this patch? Can I use it to get multivalue file fields migrated using the UI of migrate 6.x-1.0 or does this apply only to the dev version?
Is this functionality usable only by coding hooks or can I use it from the UI as well?
Comment #22
cedarm CreditAttribution: cedarm commentedYou should be able to use the UI. The trick with migrate and filefields/imagefields is getting the source path right so the source file can be found. If I'm doing a simple migration and don't want to use hooks then I'll tweak the source data first.
For example, if you have "filename" in the source table, add another column "migrate_filename" and run an update statement:
If your situation allow preparing the source data like this, then you can avoid implementing any hooks at all.
But you want a multi-value filefield, right? Filling a migrate_filenames column using SQL is a bit more complex. If you're up to the task, go for it. If you use commas to separate the filenames, just make sure no filenames actually contain commas. I suggest using pipes instead. Does that help?
Comment #23
cedarm CreditAttribution: cedarm commentedOh, and it applies to 6.x-1.x-dev. But you can also apply it to 6.x-1.0-beta1 if you first change line 17 of filefield.migrate.inc from:
to
(Which is a patch from another issue.)
Comment #24
mikeryanMigrate and Migrate Extras V1 are no longer supported. Multi-value filefields are supported in Migrate V2.