Hi,
I would like to switch from the core Upload module to FileField, but I already have file attachments which were uploaded via the core module. Can someone please give me some hints on how can I do this migration automatically, using a PHP script and the information already stored in the database?
I've created a FileField field for the content type I have, and I've looked at the "upload" table and the "content_field_CONTENT_TYPE_attachments" table created by CCK, and the information looks similar, so I tried to add a new row to the content_field_CONTENT_TYPE_attachment table, based on the info in one of the "upload" table rows, but the attachment does not appear on the page, so I guess I need to do some other modifications as well.
Can anyone give me some pointers?
Thank you.
Comment | File | Size | Author |
---|---|---|---|
#7 | ohai.drush_.inc_.gz | 1.21 KB | kaare |
Comments
Comment #1
katiusha CreditAttribution: katiusha commentedComment #2
quicksketchThere are several examples of how to migrate from other modules (Image, Audio, Node Images) in the FileField Handbook: http://drupal.org/node/432852. I'd suggest trying to adapt one of those examples to work with Upload module. When finished, it would be helpful to others in the future to add your own solution as a new page to that handbook section.
Comment #3
stacysimpson CreditAttribution: stacysimpson commentedDid you ever put together a script?
Comment #4
quicksketchClosing after lack of activity.
Comment #5
juan.bangkok CreditAttribution: juan.bangkok commentedI'm in the same situation as the OP. I've been looking for a script to do this in the forums without success. If there isn't one I'll try to code it and post it here before for review (it'll be my first PHP script *ever*). Otherwise it'd be great to know where to find it to avoid reinventing the wheel.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedHey there,
I stumbled across this script here: http://castlin.net/blog/1/2009/12/migrating-d5-upload-module-d6-cck-file...
Basically, it does what you want. However, you have to check that all the names of fields/tables etc. are correct. I had to correct some typos too. Here's the version I used to migrate all my files from Upload to FileField:
Use with caution - no warranties etc. :-)
Comment #7
kaareI've recently done this myself, and took this script and refined it a bit. It now only converts files to content types that has a valid filefield for attachment. It's a drush script and can be run as many times as desired.
Put it in
~/.drush
as~/.drush/ohai.drush.inc
and rundrush ohai-convert
from your host.Comment #8
roderikDownloaded the script in #7. Ran it. Like it.
Note to casual readers entering at comment #7:
- you need to make sure that the FileField is already added to your content type (obviously)
- you need to edit the file, to change the field name of your FileField, at the top of the code. (Unless it's "field_attachment").
- if you have multiple content types with different field names set up, that's fine. Change the field name at the top of the script to "field_attachmentname-in-type-1" and run it; part of the attachments will get converted. Then cange the field name to "field_attachmentname-in-type-2" and run it again.
Comment #9
SpriteGF CreditAttribution: SpriteGF commentedFor those searching, there's additional discussion on migrating Upload to FileField here in the Drupal Handbook: http://drupal.org/node/893074
Comment #10
rv0 CreditAttribution: rv0 commentedgreat script in #7
one note though, on line 24
change that to
Otherwise it wont work with table prefixes..
Other than that, it works perfectly, converted 100s of nodes in no-time.
EDIT:
more comments:
- it doesnt clean out the upload table afterwards.
- it doesnt move the files to the filefields upload path.
Comment #11
Encarte CreditAttribution: Encarte commentedSubscribing
Comment #12
kmillecam CreditAttribution: kmillecam commentedRegarding the Drush script provided in comment #7, I'm getting this error:
Comment #13
rv0 CreditAttribution: rv0 commented@kmillecam
the script is for drupal 6..
you are using drupal 7?
Comment #14
Kniekel CreditAttribution: Kniekel commentedOK, I'm a bit late - currently switching my last D6 site to D8 - but I must say: Thank you. #7: This. Is. Fantastic. Worked like a charm.