We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Looking for a CSV update plugin

Development and Programming

srosenow's avatar
srosenow
15 posts
16 years ago
srosenow's avatar srosenow

I have a database on my site that shares several fields with a local database one of our volunteers keeps on his laptop. The local database has a slightly different purpose, but we would like to be able to update the site database with any changes made to the local database. One thing I’m considering is exporting from the laptop via CSV and then trying to use that to update the EE database. Every plugin I’ve looked at so far doesn’t seem made to handle simple updating, however. Does such a plugin exist?

       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

Not easily – closest is CSVGrab, but it’s only for new entries and doesn’t handle updates.

Honestly, what you need sounds more amenable to some sort of process that works with the databases directly, rather than using the EE interface at all. That is, you’d export from the database on the laptop, then do some SQL magic and get it directly into the MySQL database that EE uses, without ever going through the EE interface or control panel. What is the volunteer using to update the laptop database? You can do this with a CSV export, but it might be easier with some other format, depending on what you’ve got access to.

You’re welcome to PM me or send me more details here, and I’ll do what I can to help. Data exports/imports are something I have long and frequently painful experience with getting to work. 😊

       
srosenow's avatar
srosenow
15 posts
16 years ago
srosenow's avatar srosenow

He is using Bento (http://filemaker.com/bento). If I were going to use just simple SQL, what would the process look like? I have a basic understanding of databases and php, but honestly my experience leans more heavily on the design side. I’m doing this project for a non-profit, so I’m the sole developer and trying to learn as I go. One of the great things about EE is that it handles a lot of the harder stuff for me, but I know there is a lot more that can be done by going deeper. I’m willing to learn what I need to make stuff work, but I’m not really sure where to start looking at this point. Thanks for any help you can give.

       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

Well, you’ve still got an export-to-SOMETHING step in there. Probably CSV, though as I say, other things are possible. (Maybe even a straight SQL dump, if everything you need is in one or two tables.)

From there, it depends a lot on what the structure of everything is. I’m going to walk you through the way i’ve done similar things, but i’m making a lot of assumptions. So use this as a basic guide, but you’ll need to adjust it to fit your circumstances. And i know it seems like a lot of steps, and i’m afraid i’m somewhat wordy, which probably makes it seem even more overwhelming. But this really IS awfully easy once you get used to doing it, i promise!

  1. Before beginning, you need to identify some key value that’s not going to change, and that appears in BOTH databases. If necessary, create a field in one or the other to do this. In this case, i’d suggest creating a field on the EXPORTING database (the Bento one) to hold the entry_id from EE, and populating it appropriately, if you don’t already have a field that you can be sure of matching up.

  2. Export your appropriate data, including the key field, to CSV (or possibly as an SQL dump. At the moment i’m using CSV for example purposes.) You’ll end up with something like this:

Row_ID,EE_Entry_ID,Color,Flavor,Details
242,11,"blue","cherry","some detailed information"
122,14,"red","pumpkin","something else to say"
  1. Using your favorite MySQL admin tool (PHPMyAdmin is standard a lot of places, but there are also desktop tools you can use), import that. The FIRST time through, import it into a NEW table (call it something like “bento_update_values” or whatever). Tell it the first row is column headings.

On subsequent passes, you’ll import your data into the SAME table (which will always be empty, since we’re going to wipe all the current data every time we actually wrap up an import.)

(This is assuming a CSV file. With an SQL dump, you won’t have to worry, since it will always do a DROP TABLE/CREATE TABLE pair at the beginning.)

  1. Identify the EE fields that need to be updated based on your data. For purposes of this example, we’re going to say that Color matches up with field_id_1, Flavor is field_id_2, and Details is field_id_3.

  2. The SQL involved here is the simple part. Still using your admin tool, do something like the following.

UPDATE 
exp_weblog_data, bento_update_values
SET 
exp_weblog_data.field_id_1 = bento_update_values.Color,
exp_weblog_data.field_id_2 = bento_update_values.Flavor,
exp_weblog_data.field_id_3 = bento_update_values.Details
WHERE
exp_weblog_data.entry_id = bento_update_values.EE_Entry_ID
;
DELETE FROM bento_update_values
;

Note that i’ve fully qualified (with the table name) all the fields. That’s really unlikely to be necessary here, but it’s good practice to follow.

What this says is: “Do an update involving these two tables. Set the values in the main table equal to the values from our exported data, but ONLY where our key value matches. Then, when you’re done doing that, clear everything out of the export table, so it’s shiny and clean for next time.”

That’s basically it – and really, you’re talking maybe 10 minutes start to finish once you’ve got the process going. Some automation is possible, but this post is already huge, so i’m going to end it now. Feel free to get in touch/ask questions here if you don’t understand, or if you need more details!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.