Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import from zip file with CSV files - mapping to table ids #145

Closed
Principia4834 opened this issue Jan 17, 2021 · 5 comments
Closed

Import from zip file with CSV files - mapping to table ids #145

Principia4834 opened this issue Jan 17, 2021 · 5 comments

Comments

@Principia4834
Copy link

Tobias
Thank you for all your work on the plugin which works really well. I have a site with multiple tables that are created from CSV files that my users frequently re-import. I would like to do a bulk import that replaces existing tables. I see that controller-admin.php has a "TODO" comment against this functionality and that by default new tables are created even if the "replace" option is selected on the Import page. I have written a possible implementation which uses the CSV file name to find the table id. I use the table name to hold the CSV file name so I can do the match - case sensitive and exact.

I've attached the changed controller-admin.php - this is the first time I've written php so it may not be the best solution. Changes are at lines 1156 to 1164 and line 1183 in the function handle_post_action_import. I've removed your "TODO" comment.

It would be great if you could consider this change for a future release - for me and my users it's a real convenience enhancement and helps automate our site update processes.
Andy
controller-admin.zip

@TobiasBg
Copy link
Member

Hi @Principia4834,

thanks for your work on this! I'll take a look as soon as possible, and I'll be more than happy to integrate this into TablePress directly if everything works fine!

Best wishes,
Tobias

@TobiasBg
Copy link
Member

TobiasBg commented Mar 4, 2021

Hi @Principia4834,

I added such a feature (after some modifications to not break existing behavior) in commit 0074297.
Would be great if you could test this some more!

Best wishes,
Tobias

@TobiasBg
Copy link
Member

TobiasBg commented Mar 4, 2021

Hi @Principia4834,

to add on, I added one more modification, in commit 8983b6e: As the table name is not unique, replacing of the table will only be done, if there was exactly one match of table name and file name. Otherwise (no matching table or more than one match), the file will be imported as a new table. This way, no possibly "wrong" tables will be replaced accidentally.

Regards,
Tobias

@Principia4834
Copy link
Author

Tobias
Thanks for the update. I have tested the new controller-admin.php on my Wordpress 5.6.2 site as follows:

  1. Import zip file with three files (book1.csv, book2,csv, book3.csv), option "Add as new table" - pass, new tables created
  2. Import zip file with three files (as above with extra line added to each), option "Replace existing table" - pass, existing tables updated
  3. Copy the table named book3.csv and edit the name so there are two identically named tables with different IDs. Import zip file with three files (as above with extra line added to each), option "Replace existing table" - pass, book1.csv and book2.csv are updated and new book3.csv table is created so preserving existing tables

So it all looks good to me.
Best wishes
Andy

@TobiasBg
Copy link
Member

TobiasBg commented Mar 5, 2021

Hi @Principia4834,

great! Thanks for testing this! This confirms my tests, so that we can ship this, I think :-)

Best wishes,
Tobias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants