- Issue created by @kensuke-imamura
Nice! 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.
Corrected the patch format (missing the first line) in the previous 2 patches.
- Status changed to Needs review
over 1 year ago 8:40pm 27 February 2024 - last update
over 1 year ago Patch Failed to Apply - last update
over 1 year ago 536 pass - last update
over 1 year ago Patch Failed to Apply - šŗšøUnited States jrockowitz Brooklyn, NY
Does the CVS that is being imported have empty lines?
Can you upload and example CSV that is having this issue?
- Status changed to Postponed: needs info
7 months ago 12:07pm 24 November 2024 - š§šŖBelgium kubrick
Patch #3 solved an issue I was having with big CSV's.
- šŗšøUnited States jwineichen
Patch #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.
- Status changed to Needs review
26 days ago 1:33pm 5 June 2025 - š«š·France pacproduct
I think ths 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
fgets
where they should not.I was facing the following errors in my case because of multiline webform elements:
... > [warning] Line n°101: 28 values expected and only 3 found. > [warning] Line n°102: 28 values expected and only 5 found. ...
Using
fgetcsv
as 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! :)
- First commit to issue fork.
- Merge request !645Update file WebformSubmissionExportImportImporter.php ā (Open) created by immaculatexavier
- šÆšµJapan kensuke-imamura
Patch #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 return false.$fp = fopen('php://memory', 'rw+'); fwrite($fp, <<<CSV a,b,c 1,2,3 CSV); rewind($fp); while (($line = fgetcsv($fp))) { if (!empty($line) && $line !== ['']) { // This is always output. echo "not empty\n"; } else { echo "empty\n"; } }
The first patch I submitted does not have this issue. The empty line detection method in that code is aligned with the existing condition in
modules/webform_submission_export_import/src/WebformSubmissionExportImportImporter.php
.