Frontend CSV Import issues and anomalies (fixed)

Bauer

Well-Known Member
There are numerous issues with CSV Imports on the front end using the current importcsv.php code. Upon reviewing the code it is obvious that it was primarily designed for use with the CSV Import Cron plugin. And while that might be working fine, there are many parts of this code that do not work well when used for a front end CSV Import.

For example...
The most glaring issue is the lack of an 'Overwrite' option. There may be a setting for that in the Cron Plugin, but there is no setting for it when used from a frontend menu item. The same is true for the 'DropData' option. So, on the front end, both options use the default value of 0 (No).

The workaround for lack of a 'Drop Data' option, I suppose, would be to empty the table before importing. But, as is, there remains the inability to set the 'Overwrite' option to Yes - which prevents the upload (Importing) of updated data from a changed list without causing errors or without creating duplicate records as each row is imported.

Another big problem with importcsv.php is that it was not honoring any 'Show in list' settings and so it was trying to update every column in the table - even those not included in the list; and, to make matters worse, it was inserting the 'default value' for any columns that were not included in the import - which would overwrite valid data in non-included elements with their default values!

There are also a few instances where variables are referenced (like $task) which, when called from the front end, have a different value than the code expects (if used for the cron).

And finally, while I realize their purpose with cron jobs, the use of 'exception errors' on the front end just seems unacceptable. If anything fails during the import process, all the user sees is a poorly formatted Exception error page sent from the server - when a simple system warning message and return to the list page would suffice and is far less confusing or intimidating to the user.

When I first encountered the problems mentioned, when I tried using the Fabrik CSV Import feature a few years ago, I just decided to write my own code to handle that - but I always thought in the back of my mind that this was something that could and should be fixed in Fabrik, as it would make things so much easier for me in this project.

So I have been working for quite a while on deciphering the code and making it work as I always expected it to work, and taking care of the issues mentioned above - and am now using the proposed code changes that I have also posted as a PR at github.

To get this all working as you (I) would expect it to work, I added 3 new options to the fabrik menu tab... Overwrite, Drop Data, and Valid extensions.

While the need for Overwrite and Drop Data are explained above, the 'Valid extensions' option was added to allow the upload of files that are not the standard Fabrik CSV Import file types (txt,csv,tsv). And in that case would require the inclusion of a custom PHP file to 'pre-process' the uploaded file and convert it to Fabrik-recognized CSV format before importing (or that custom PHP file could also include the code that does that). This concept is intended to be used with the new post-processing CSV Export custom php file that was introduced a few weeks ago.

To explain (and as I have explained before), I use 7 different menu options all sharing the same list, but set to use different filters and different 'Show in list' settings. Using a custom list template, those lists contain survey data laid out to collect simple numeric data in a 'spreadsheet-like' manner; and I always assumed the Fabrik CSV Import/Export features would allow users to export/download their surveys to 'work offline'.

But in order to make the surveys much more user-friendly, the work-offline files are first converted to Excel spreadsheets (using the new CSV Export post-processing feature) - so that the user can edit their surveys at their leisure in Excel and then upload them (also in Excel format) back to the server. So there was a needed for both post-processing of the 'CSV Export' file (to convert to xlsx) and, upon import, a pre-processing of that Excel xlsx file (using the PHPExcel library) in order to get the user's updated survey data back into the Fabrik table.

Until someone can come up with a cheap and effective online spreadsheet that works as fast and has all the features of Excel, this seems to be the best solution; and I feel it makes this sensitive data more secure than if I used some cloud service like Google Documents. And so I am thankful I have Fabrik for that. It's taken me almost 4 years now to iron out all the issues - but I'd like to think I've got what I need to make the main 'engine' of my project work. So I'm keeping my fingers crossed that these latest PRs (#1730, #1731, #1732) are merged, as I think this would be a welcome fix/addition to Fabrik.
 
Last edited:
The only thing I see in that so far I don't agree with is the "show in list" thing. While that may be the way you expect it to work, as we know, there as as many different expectations of how things should work as there are users, and I can absolutely guarantee some folk will expect any column in the CSV to be imported, regardless of whether it's being displayed in the list or not. I know this, as I have several clients who use it that way. Not everyone uses export / import in a commutative (?) way, where the export and the import have the same columns. Some people show a list summary, with only a few columns visible, but use it to import the entire table.

I agree about the defaults, though.

So I think that needs to be an option - import only the columns displayed in the list, or everything in the CSV.

-- hugh
 
So if I also add a "Only update 'Show in List' elements" Yes/No option you will merge the PR?
The biggest problem I see with this is as I explained. And yeah, I've got to be missing something here.

And I'm sure you do realize that the 'Show in list' menu setting is not necessarily what is actually shown to the user in the list (the PK Id for example).

If only elements that are shown in list are exported (to begin with) - then how would the user get the other columns for the upload/import? And if they don't include those columns they are getting overwritten with their 'default' values - which could be a real catastrophe. Thankfully, in the list I'm testing this on there is another 'unique' index key (that is not part a columns that were exported). And so when I ran the CSV import and when the code tried to replace that field with it's blank 'default' value then that 'unique' index rule was broken (on the second record). And so fortunately the the rest of the import died - and I only had one row that "lost' some of its data because of the default value overwrites.

At any rate, users should be made aware of the rules and how they play differently (possibly overwriting existing data), depending on the configuration. But that problem existed long before I showed my pretty face around here.:p

This doesn't affect anything run via an admin on the admin backend - which is where (I would think) most of the 'full' import/export transactions are being done. In that case, there is no menu and the 'Show in list' value would be empty - and if empty (whether in the backend or from a frontend menu) it works like it always did.
 
Last edited:
Yup, as I said, I agree on the default data thing.

And, as I said, I have a number of clients who use the front end for CSV import (so they don't have to give anyone backend access), for instance client data from CRM systems, who don't do any exporting. Working on lists with dozens of elements, where they only show a handful in the list, but want to import them all.

So yes, I'd merge it if that was option-ified.

-- hugh
 
OK - Done, thanks! I gave it a test on my system and it seems ok. (Now I have to go change the other 6 menu items:))
 
Just FYI, we've gone back to using 'master' as the main branch. We've left 'joomla3' there to make it easier for people to switch, as renaming a branch in git is a pain in the ass. Anyway, before submitting any more PR's, can you check out and switch to the master branch, and submit future PR's on that.

I'm in the process of merging your existing PR's on joomla3, then merging from there to master.

-- hugh
 
Actually, thinking about it ... ignore that last message. Keep doing PR's against joomla3. That'll give me a branch I can test them on, before merging into master.

-- hugh
 
Actually, thinking about it ... ignore that last message. Keep doing PR's against joomla3. That'll give me a branch I can test them on, before merging into master.

-- hugh
OK. Thanks for getting to this.
Right now I 'm afraid to do anything. My server automatically 'updated' to php v7.07 last night - while I was in the middle of making some changes, just out of the blue. I couldn't even get the menu to load on the admin backend until I went into the config file and set error messages off. Ughh.

So it looks like this latest php version is even more picky than the last. Even on the front end, the date element is throwing errors like this - like crazy...
E.g. Backtrace from warning 'Only variables should be passed by reference' at /home/public_html/plugins/fabrik_element/date/date.php 638
...because of the use of &$var in so many functions.

And off course, at first I was blaming it on you :p because one of the things I had changed was to switch from using a cascading dropdown in the form I was working on to using your new placeholders feature for the databasejoin where condition.

But as it turns out, the dbj feature is working like a charm. Thank you so much for that!
I'd much rather use the dbj because it has the frontend add option.

The only issue I see (and this was on a table with over 5K records) is that when the watch element changes and the where condition is updated, the spinner shows but then just freezes. So at first I thought the ajax script was was froze, but the 'dead spinner' eventually goes away and everything looks as expected. No biggie for me - but for users who don't know what's going on, I'm afraid it might cause them to think something is broken and they'll close the page before the element reloads.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top