WordPress.org

Ready to get started?Download WordPress

Forums

Gravity Forms Mass Import
[resolved] Where does the data get written to the database? (7 posts)

  1. pixelnate
    Member
    Posted 1 year ago #

    I need to modify this plugin so that I can send out notifications through Gravity Forms, but I cannot figure out the best place to do that. Since neither of your files are commented (eh hem) I was hoping you could share where that happens. Does it happen when the mass_importer_h.php is called by the mass_import_handler() function or does it happen when you run ParseCSV?

    Any info would be greatly appreciated.

    Thanks,

    Nate

    http://wordpress.org/extend/plugins/gravity-forms-mass-import/

  2. dunar21
    Member
    Plugin Author

    Posted 1 year ago #

    I don't know what you are trying to do with the notifications. It really has nothing to do with my plugin. mass_importer_h is strictly a file that checks the json database entry for the selected form and spits out the relevant Fields by id and name so the user can properly set the headers for their csv file. parsecsv.lib is where the action takes place. In gravity-forms-mass-import.php these lines instantiate and call the parsecsv class{`<br />
    $csv = new parseCSV();<br />
    $csv->last_form_id = max($lastnum);<br />
    $csv->form_using = $formnum;<br />
    $csv->actHeaders = $ararr;<br />
    $retarn = $csv->parse_file($_FILES['csv_file']['tmp_name']);<br />
    `

    First, we set the id number of the next database entry, then we define the form we are using by id, then we pass the list of headers that are actually used in the form as stored in the database (this is used for comparison to make sure that people are putting in the correct headers for their csv file).

    parse_file, takes the uploaded file, parses it into a string and in
    parsecsvlib.php, after the file is parsed to a string, parse_string is called with the data and we simply move a pointer along character by character, for each row, to look look for our encapsulaters (double quotes), our delimiter (comma) and our end of line. At the end of line, we now have an array of entries (or headers if it's the first line). This happens between 323 and 356. At 359, we process each line. If it's the first line, we validate the headers. If not, we continue as long as the headers were correctly validated. For each line, each entry is checked against type and stored appropriately in the database. This happens between 431 and 523. And that's it. The array for each row gets emptied and then repopulated after the row has been entered into the database (I was hoping this way would be the most efficient). Upon completion of rows, the success message is fired.

    Hope this helps.

  3. pixelnate
    Member
    Posted 1 year ago #

    The array for each row gets emptied and then repopulated after the row has been entered into the database

    This is what I need to know about. Where does this happen, in the parsecsv.lib.php file? What i am looking to do is pull out a couple of values out of each record (both of them email addresses) and then set up a function that will use the resend_notification() function in Gravity Forms to send the notification emails out to the people affected in each record. What I need to know is where in the process I need to add my extra plumbing? i could send out each notification manually after the CSV has been parsed, but the client wants it automated.

    BTW, thanks for responding so quickly.

  4. dunar21
    Member
    Plugin Author

    Posted 1 year ago #

    I told you where that happens already, between lines 431 and 523. Hey, don't want to sound mean but I'm a straight to the point kind of guy. If you couldn't look at the code, especially after the description and figure out where data was being entered into the db, then it's unlikely you are going to get this task of yours done without a lot of problems.

    Additionally, your task doesn't seem very relevant at all to the plugin. Why would you be importing a csv file then sending out notifications for every entry? Even if you have some sort of reasonable purpose for this, why wouldn't you just pull the fields from the file itself first?

    Another way to do what you are asking without editing any of the gravity forms code or trying to do this with mine, is to simply make all of your fields able to be dynamically populated by going to the advanced setting and clicking the check box. Assigning them variables, and finally sending an array to the form containing the variable values, automatically populating the fields and use a little jquery to automatically submit the form. You would have to either set a cron job or make a little script to continuously call the page until your job is done. Doing it this way will trigger the notifications set up for the form.

    I still don't see why you would want to send a notification out for either of these methods though. You are importing data from a source you already have access to. If it were user input, I would understand, but it's from data you have, so why wouldn't you just use the data you have and send out whatever notifications you may need with it?

    Or maybe you are trying to set up some sort of mailing list (or possibly spam) plugin wherein you are only importing emails and attempting to send mass emails. In that case use the dynamic population option for the forms. Send an array of data to the a custom php script (or string and parse it to array), populate the field, jquery a click event, reload the page, go to next item in array, and so on.

  5. pixelnate
    Member
    Posted 1 year ago #

    I told you where that happens already, between lines 431 and 523.

    To tell you the truth, I read your response about five times and never saw that there. Sorry, it's been a very long week, and it's only Wednesday.

    I agree that setting up the fields as dynamic and feeding an array to gravity forms would work great, except that the dataset we are using begins life as a spreadsheet. Your plugin already parses the data in the csv file, and puts it in all the same tables as gravity forms does, the only thing it doesn't do is trigger the notification emails, so it is the perfect basis for the additions I need to make.

    What I have decided to do is add all the $_field_num=>$_valu pairs generated by the switch on line 437 to an array, then I can take those values, replace them in the notification email set up in wysiwyg editor for gravity forms form and then use mail() to send the emails to people that should be receiving them.

    Since you are accusing me of creating spam (ahem) I'll let you in on what we are doing. This religious organization that we work with is trying to connect high school students in local church youth groups with the church youth group of the college that they are planning to attend.

    On the front end a high school student can enter their information in a form and when that info is submitted a notification email is sent back to the student welcoming them and giving them information about the youth group. Another email is sent to the youth group leader at the college informing them of a student interested in joining their group and provide contact info for the student so that they call the student and welcome them personally to the group.

    At high school youth group gatherings the youth group leaders/ministers sometimes collect the same information about the students, with their knowledge, then send a spreadsheet to the organization running the website. We use your awesome plugin (the only one of its type in the WordPress univers) to get that batch of student information into the database, but by default, there are no notifications sent to the student or youth group minister at the college. Sure, the owner of the website could select all those new records in the admin and choose to "re-send" notifications to the relevant parties, but they want it to be automatic. That's where I come in, and it's the reason we are having this conversation about adding notifications to the parsecsv.lib.php file. :)

    Thanks for your help.

    P.S. It just dawned on me that I might just be able to put the IDs of each of the new records into an array and then trigger Gravity Forms' built-in resend_notifications() function on each of those entries that way. Or better yet, just take the last $rowcount number of records in the lead_id column and "resend" the notifications to them.

    I am glad we had this talk.

  6. dunar21
    Member
    Plugin Author

    Posted 1 year ago #

    I'm going to be putting out a minor update to the plugin, so backup whatever changes you've made so your work doesn't get over written.

  7. pixelnate
    Member
    Posted 1 year ago #

    Thanks for the warning.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic