Problem/Motivation
I cannot import a large number of records that are executed in multiple batches.
If the number of records to be imported exceeds 100, drush wfi command splits the task into several batches. When handling 2nd or subsequent batches, the process should skip over the records that have already been imported. However, WebformSubmissionExportImportImporter skips by line rather than by CSV record.
while ($index < $offset && !feof($handle)) {
// => We should use fgetcsv() here.
fgets($handle);
$index++;
}
The problem and cause is similar to this: #3386895: Upload count is incorrect in getTotal method of WebformSubmissionExportImportImporter
Steps to reproduce
- Install Webform and Webform Submission Export/Import
- Create a webform
- Insert ~200 records to the form
- Export the submission data by
drush wfx --exporter=webform_submission_export_import - Import the exported files
Proposed resolution
Skip processed records by CSV record as #3386895: Upload count is incorrect in getTotal method of WebformSubmissionExportImportImporter.
Remaining tasks
Write tests
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | webform-submission-importer-csv-line-offset-3414928-3.patch | 710 bytes | scambler |
| #2 | webform-submission-importer-csv-line-offset-3414928-2.patch | 522 bytes | scambler |
| webform-submission.patch | 534 bytes | kensuke-imamura |
Issue fork webform-3414928
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
scambler commentedNice! I came across the same issue. I used a similar patch and it solved my problem. The only difference is when checking for an empty line, I copied the logic from L422. I'm not sure if there are situations where this will actually make a difference, but I'll upload it anyway.
Comment #3
scambler commentedCorrected the patch format (missing the first line) in the previous 2 patches.
Comment #4
cilefen commentedComment #5
jrockowitz commentedDoes the CVS that is being imported have empty lines?
Can you upload and example CSV that is having this issue?
Comment #6
jrockowitz commentedComment #7
kubrick commentedPatch #3 solved an issue I was having with big CSV's.
Comment #8
jwineichen commentedPatch #3 also worked for me. I was importing a CSV with 1900 lines. Without the patch, the completion message said it created a little under 300 records and then updated 1600 or something, even though I added sid and uuid columns so they should have all been recognized as unique. With the patch, the the upload completed successfully and I've got 1900 submissions now.
Comment #9
cilefen commentedComment #10
pacproduct commentedI think the issue is not specific to big CSVs but to big CSVs that contain entries with line breaks, as they get interpreted as new lines with
fgetswhere they should not.I was facing the following errors in my case because of multiline webform elements:
Using
fgetcsvas suggested seems to be the way to go, and I can confirm that the patch in #3 does solve the issue as it counts lines in a similar way to\Drupal\webform_submission_export_import\WebformSubmissionExportImportImporter::getTotal, although the latter usesif (!empty($line) && !is_null(array_pop($line))) {instead ofif (!empty($line) && $line !== ['']) {, I'm not sure which approach is the best.Thanks! :)
Comment #11
pacproduct commentedComment #12
liam morlandComment #15
immaculatexavier commentedComment #16
kensuke-imamura commentedPatch #3 and the merge request do not seem to correctly recognize empty lines.
According to https://www.php.net/manual/en/function.fgetcsv.php, fgetcsv() returns an array containing only NULL (
[NULL]) for empty lines.In this code, it's strictly comparing with
[''], so it will always fail to check empty lines.The first patch I submitted does not have this issue. The empty line detection method in my patch was copied from the existing condition in
modules/webform_submission_export_import/src/WebformSubmissionExportImportImporter.php.Comment #18
jrockowitz commentedComment #22
liam morland