Posted by aaronpinero on January 6, 2013 at 10:09pm
3 followers
| Project: | Webform |
| Version: | 7.x-3.18 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
I just upgraded a website from D6 to D7.18. In webforms that have a file field, the names and URIs of submitted files has changed. The correct files are still in the files directory but now submission records reference some other, incorrect file. It's as if the file ID numbers have been scrambled. Has anyone had this experience? Is there any way to easily correct the problem?
Comments
#1
This David, one of the developers who works with Aaron, the OP. Adding some info to this issue for others who might have to deal with this problem.
In 2010 Drupal core switched from using
filestable to newfile_managedtable. Also created was thefile_usagetable which appears to be a registry of which modules are using which uploaded files. Webform modules switched to this new backend scheme in early 2013 but did not provide update code in webform.install to migrate the files from old table to new or insert rows into thefile_usagetable.Webform module maps webforms to submitted files via
webform_submitted_datatable, with columndatacontaining the foreign key file id of the corresponding row infilestable. This query displays the rows in oldfilestable that belong to webforms.SELECT DISTINCT wsd.nid, wsd.sid, f.*FROM `webform_submitted_data` AS wsd
INNER JOIN `webform_component` AS wc
ON wsd.nid = wc.nid
AND wsd.cid = wc.cid
INNER JOIN `files` AS f
ON wsd.data = f.fid
WHERE wc.type = 'file';
To see related rows in the
file_managedtable, change the 2nd INNER JOIN to reference `file_managed` table. For a database that has just been upgraded from 6.x to 7.x, this query will not return any rows.After a Drupal 6.x to 7.x migration, file mappings break due to the following reasons:
filestable have not been migrated tofile_managedwebform_submitted_data.fidcolumn still contains foreign key values for oldfilestable, which the Webform module code now interprets to be foreign key values for thefile_managedtable. Thus webforms will map to completely unrelated rows in thefile_managedtable.file_usagetable to reflect Webform module's usage of the uploaded files.Luckily the
filestable is left untouched after migration so it is possible to repair the mappings. The steps for doing so:filestable tofile_managedtable. Be aware that thefile_managed.uricolumn is defined with a unique index. During migration the values that populate this column come fromfiles.filepath, which does not have a unique index defined. In certain cases the old Webform code allowed for duplicates in this column. In our case this happened when the same user uploaded the same file on the same form more than once. These cases have to be dealt with manually.file_usagetable for each migrated row.Attached is an edited version of the ad-hoc script I wrote to do this for our site. (.txt extension is due to restriction against attaching files named *.php). I removed some stuff to preserve confidentiality but it should still work as is. Note that function
alter_duplicate_filepathswas written to be specific to our website and will not apply as a general case. Before attempting migration it should be determined if there are any duplicatefilepathvalues infilestable. If so, ad hoc transformation can be performed in this function. If no duplicates are found, invocation ofalter_duplicate_filepathscan be commented out.Links of interest
Webform module code switches from
file_managedtouricolumn is defined :http://drupalcode.org/project/webform.git/blob/cf4a11d385bcdcd18ae4f3429...
...but does not provide migration update:
http://drupalcode.org/project/webform.git/blob/cf4a11d385bcdcd18ae4f3429...