When exporting webform submissions using drush wfx with range-type='new', the webform_last_download table is never written to, with the result that it always exports all submissions. The reason for this is because the code that updates the webform_last_download table is in the webform_results_download() function, which is not called during a drush wfx.

A possible solution is to move the code that updates the webform_last_download table to the webform_results_batch_rows() function, as I will demonstrate in the attached patch.

Comments

pdcarto created an issue. See original summary.

pdcarto’s picture

StatusFileSize
new2.49 KB
serundeputy’s picture

Status: Active » Needs review

Setting to `Needs review` to trigger travis.

serundeputy’s picture

I applied this patch and tested the drush wfx --range-type='new' command. Works as expected with only new results being exported.

I did not test through the Drupal UI.

danchadwick’s picture

Status: Needs review » Needs work

I took a quick look and see one minor style issue and a bug:

  1. +++ b/includes/webform.report.inc
    @@ -1330,6 +1315,9 @@ function webform_results_batch_headers($node, $format = 'delimited', $options =
    +  global $user;
    

    This is an anti-pattern. You can easily screw yourself with a global $user. I've been converting these to $GLOBALS['user'] as I work on issues.

  2. +++ b/includes/webform.report.inc
    @@ -1380,6 +1368,21 @@ function webform_results_batch_rows($node, $format = 'delimited', $options = arr
    +  if ($context['finished'] && !in_array($options['range']['range_type'], array('range', 'range_serial', 'range_date')) && !empty($context['results']['last_sid'])) {
    

    Not quite. You are evaluating a floating point number as a boolean. The truthy value of 0.5 is TRUE, so this will do the db_merge part way through the batch. To test this, set the batch size small enough that multiple batches are exported.

This needs testing with both drush and the UI. It also needs testing with multiple batches.

danchadwick’s picture

Oh, also, thanks for the am-style patch. However, you need to put a Drupal and webform standard commit message in it, otherwise I can't use it.

danchadwick’s picture

Ehhhh, looking more closely, the code was removed from the page which displays the downloaded file and moved to just after the rows are exported. This increases the risk that the last-downloaded will be reset before the file is successfully delivered to the user. The UI download uses some javascript trickery to display the file.

This isn't going to be quite as easy as I hoped.

danchadwick’s picture

Title: wfx range-type='new' doesn't work » wfx range-type='new' doesn't reset last downloaded sid
Status: Needs work » Fixed
StatusFileSize
new3.83 KB

This was made harder because the $_SESSION super-global this is used to communicate the results of the export to the next page load does not work with the command line.

Committed to 7.x-4.x.

  • DanChadwick committed e3867fd on 7.x-4.x
    Issue #2566017 by DanChadwick: Fixed wfx range-type='new' doesn't set...
danchadwick’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Category: Bug report » Task
Status: Fixed » Patch (to be ported)

Up-port needed.

  • fenstrat committed de6993b on 8.x-4.x
    Issue #2566017 by DanChadwick, pdcarto: wfx range-type='new' doesn't...
fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Category: Task » Bug report
Status: Patch (to be ported) » Fixed

Committed and pushed to 8.x-4.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.