Error With PHP 7.2 And CSV Import Plugin v1.11

7 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 14, 2018   (RSS)

By Steve99 - June 4, 2018

Hey Guys,

I'm experiencing errors with CSV Import Plugin v1.11 on PHP 7.2. The CMS version is 3.13.

The error occurs immediately after uploading the CSV file and clicking "Analyze Data".

The error shown in the browser is:

Error: There was an error sending the request! (200 OK) parsererror - SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data

The error log entry shows:

E_WARNING: count(): Parameter must be an array or an object that implements Countable
/cmsb/plugins/csvImport/csvImport_functions.php (line 500)
_plugin=csvImport/csvImport_functions.php&_pluginAction=csvImport_analyseForm_ajax&num=7&offset=0&rowNum=1&menu

I do see the csv data in the _csv_import_data table, so it seems to be getting that far in the process before it errors.

Regards,
Steve

By leo - June 11, 2018

Hi Steve,

Sorry for the late response. I have tested under the same environment with some test csv files and couldn't get the error. It may be the file that's not formated very well.

Leo - PHP Programmer (in training)
interactivetools.com

By gregThomas - June 11, 2018

Hi Steve,

Dave asked me to look into this in more detail. I installed PHP version 7.3 and was able to replicate the problem, it looks like the PHP count function is much stricter in the latest version. If the last line of a CSV is blank (which it is if the CSV is exported from the CSV Export plugin) then that error is thrown.

You can resolve the issue by adding the following to line 499 of csv_functions.php:

    list($colValues, $offset) = _csvParser_getNextLine($csvFilepath, $setOffset);
    if(!$colValues){ $done = true; break; }
    $maxColumnCount = max($maxColumnCount, count($colValues));

NOTE: I've not thoroughly tested this change yet, so I'd recommend doing a few test uploads before you use it on any client sites.

Thanks,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - June 12, 2018 - edited: June 12, 2018

Hi Steve,

Good to hear that worked. I'll do some tests on the fix and should have a new version of the plugin released in the next couple of days. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - June 14, 2018 - edited: June 14, 2018

Hey Steve,

I've released a patched version of the plugin, you can download it here:

https://www.interactivetools.com/add-ons/csv-import/

In the end, the only change I made was to add that single line of code, so you can stick with your patched version if you prefer.

Thanks again for bringing that issue to our attention.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Steve99 - June 14, 2018

Hey Greg,

Sure thing, thanks for the update!

Best,
Steve