The current webform.report.inc is really nicely abstracted from the point of view of generating the actual export, however it is really inflexible as an API - lots of functionality is bundled into a single function, which is in itself quite inflexible (headers are always written, no control over pager etc). This patch breaks header and row generation out from webform_results_download() into different functions, and makes some minor changes in argument passing. Obviously there is more that could be done here to formulate this into a more general purpose API, but even as it is this is hopefully a useful start that should enable things like batch exporting in the future.
Patch is attached that should apply on 6.x-3.x HEAD with the #1137348: Ability to download archive of CSV and all files patch rolled back, but this was not yet pushed up yet, so I am including one with the zip code included.
There is a Drush command that provides export (including support for large datasets) that uses this patch in #1276098: Add Drush command for bulk export.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | webform_export_drush-1275468-24.patch | 10.55 KB | sdrycroft |
| #23 | webform-1275468-improve-webform.report.inc-23.patch | 9.47 KB | torotil |
| #20 | webform_drush_integration-1275468.patch | 16.45 KB | quicksketch |
| export-drush-head-with-zip.patch | 13.02 KB | owen barton | |
| export-drush-head.patch | 7.97 KB | owen barton |
Comments
Comment #1
quicksketchI can't see anything of a Drush script (at least from the patch), but could you make that a separate issue anyway? Seems like it'd be dependent on this patch but it should still be a separate issue nonetheless.
The patch itself looks pretty great. I appreciate your going through and documenting all those functions too.
Comment #2
owen barton commentedThat makes sense to me - description updated!
Comment #3
quicksketchA few of these changes were handled in a separate patch #1292252: Update the exporting mechanism to make it extendable by other modules, which I imagine would be somewhat helpful for your purposes also. This patch unfortunately now needs a reroll for compatibility.
Comment #4
quicksketchComment #5
davidseth commentedPatch attached for 7.x-3.17.
This brings Drush integration to webform. @Owen Barton did the original d6 patch and I just modified it to work with d7.
Comment #6
davidseth commentedComment #7
darrell_ulm commentedHas this patch been incorporated anywhere? It looks like it is for a version pre 6x-3.17 Thanks.
Comment #8
quicksketchNo it hasn't been implemented. New features (and especially API changes) are only being added to 4.x at this point. At least this eliminates the need for a D6 backport, though it probably still needs a reroll for 7.x-4.x.
Comment #9
eporama commentedHere's a reroll against 7.x-4.x
Comment #10
quicksketchThanks @eporama! This patch looks pretty good but I've got a few reservations:
- Shouldn't the drush command be able to set options that match the interface? Or at the very least, be able to choose the exporter (delimited or Excel for example)?
- The calls to
webform_results_download_options($node, $options, $submission_information)are confusing (taking two empty variables by reference and populating them). For clarity it would be preferable to have separate functions with a single return value each, one that initializes $options and one that initializes $submission_information. Calls by reference are always a little difficult to follow, but initializing empty variables through them is more confusing yet.Looks great overall, I just fear maintaining this :P
Comment #11
gnosis commentedI'm in the same situation as others (large submission sets, results downloads time out) and I've read through this thread (and the one about running Webform downloads through batch - awesome idea). It seems like my best option for a fast solution is to apply the #5 patch and use Drush to get the CSVs.
Can anyone confirm that this patch is safe to apply against 3.18 in a multisite env. with several sites sharing the module and several active webforms on each? I'll test on my own, of course. Just interested in any feedback I can find in advance.
Thanks!
-J
Comment #12
gnosis commentedFor anyone looking into this, I applied the patch from #5 to Webform 3.18 and it appears to work as advertised. One chunk in the patch did fail, but it was a nice clean block (a whole function), so it was easy to add it manually. After that, I ran
drush wfx [nid] > dumpfile.csvand was able to dump over 7000 submissions without error to create a 3.5MB CSV file (it's tab-separated, btw, not comma). Using the GUI, this dump failed every time. Definitely a step in the right direction!Comment #13
sylvainm commentedPatch adapted for 7.x-3.18 version
Comment #14
jonathan.droz commentedWhen I want to export submissions from a webform using the command drush webform-export nid=7343, the following error occurs:
Invalid argument supplied for foreach() webform.components.inc:935
Thanks for your help
Comment #15
owen barton commentedThe argument is simply the node id - i.e. "drush webform-export 7343".
Comment #16
jonathan.droz commentedThank's @Owen Barton. It's working like a charm :-)
Comment #17
burningdog commentedAssigning to version 7.x-4.x as according to #8:
I don't mind that the drush option only exports csv and doesn't allow other options - those can always be added in later (and csv is easy to change into any other format by Excel).
I agree with quicksketch at #10: the calls by reference should be eliminated in favour of separate functions.
Comment #18
burningdog commentedVersion change.
Comment #19
quicksketchThanks @burningdog. I'd still love to see this patch move forward. Batching our CSV files would be a great improvement for forms with a lot of submissions. The Drush handling is a nice-to-have on top of that.
Comment #20
quicksketchHere's a reroll of this patch that makes my requested changes plus some additional refactoring:
Ahh, much better. :)
drush wfx --range-latest=10ordrush wfx --delimiter="\t" --range-start=10 range-end=100. However there's a followup I'd like to do here to change how start/end ranges work: #2041221: Submission range options should be by serial number, not by SID.Comment #21
quicksketchI've committed #20 to the project's 7.x-4.x. Thanks Owen Barton for your work on this long, long ago. Let's finish up #1327186: Use BatchAPI to Export very large data sets to CSV/Excel now, that's the more important one in my mind.
Comment #22.0
(not verified) commentedMoving Drush command to 1276098
Comment #23
torotil commentedThe patch from #20 applies nearly unmodified to webform-7.x-3.x. Here is a re-roll that fixes the only rejected hunk and makes it apply again.
Comment #24
sdrycroft commentedWe have been using a modified version of this patch on the 7.x-3.x release for some time, and realised others would benefit from our work. We would love to see the enclosed patch, which applies against the 7.x-3.x branch, included in a release.
Comment #25
sdrycroft commentedComment #27
sdrycroft commentedApologies to all, this should've been 7.x-3.x-dev.
Comment #30
torotil commentedHi there. Thanks for publishing your work in the issue queue. 7.x-3.x will receive only critical fixes. Your patch might still be useful for others though.
Comment #31
sdrycroft commentedCheers @torotil, I suspected that would be the case, but figured our patch could be beneficial to others so I should post it. It also aids out internal workflow when we can refer to a patch on d.o.