Posted: May 22, 2019 at 12:11 am
|
Each time someone registers for an event (wp_esp_registration), I want to insert various user profile data (which I’ve compiled from a view [myView]) into a custom table (mytable). I created a trigger The idea is to insert UserID and EVT_IDs into mytable from myView where they don’t exist. It is not working though. In my test, it seems I need to register twice as the same user to the same event. In this situation, the data from the first registration is inserted (trigger) into mytable. And, the data from the second (duplicate) registration does not get inserted, presumbaly because that UserID, EventID combination now exists in MyTable. How can I get the trigger to work after the FIRST insert to wp-esp_registration? |
|
Running the INSERT statement outside the trigger works everytime after each registration |
Hi, A topic like this one does fall outside the scope of support. That said, what’s the primary key on that table? |
|
|
Hi Josh, The table with the trigger is wp_esp_registration. The primary key is REG_ID. The view that contains data written into mycustomtable is a view with no primary key. mycustomtable (where data from view is inserted) has a primary key ‘id’ |
Hi there,
My apologies, but I’m a little confused by this. That’s what happens currently, or that’s the expected outcome? That sounds like your expected outcome.
Can you post how you’ve defined the columns in your view? Something to note is the INSERT on esp_registration is done as soon as the user selects the tickets and submits the form, this is before they’ve entered ANY details into EE. So, on a new registration for a new user your definitely not going to have a value in
At what point are you running the INSERT then? After the registration is complete and you’ve hit the thank you page? (If so that’s way after the esp_registration insert)
|
|
|
Here is the view I use to write into mycustomtable once a trigger fires from wp_esp_registration. It aggregates the user’s personal information and event information:
Here is the current edition of the trigger I’ve concocted. Rather than selecting from the view above, I’ve tried to re-create a simpler version with a derived table in the trigger itself:
The desired behaviour is for new registration values to be written into mycustomtable after each registration. Before, it was writing after every second registration by the same user to the same event. BUT, with this current trigger posted above, it is INSERTing all the existing records from evt_registrations_detail into mycustomtable(undesired) and not INSERTing the recently added registration into mycustomtable (desired). |
|
View: CREATE Current Edition of trigger. Inserting existing records and not newly submitted registration record (undesired) CREATE DEFINER=wordpress@localhost TRIGGER weigh_in_insert AFTER INSERT ON wp_esp_registration FOR EACH ROW BEGIN |
|
inserting ANS_value doesn’t seem to be the issue, it inserts the ANS_value. The problem is that it is inserting all the existing records from evt_registrations_detail (view) except for the newly added registration |
Yeah, so I think the problem is that registrations are inserted into the database earlier than your expecting. They are inserted really early and updated as the user steps through the registration steps, also your registrations can only be approved once they been finalized at the end of the process, which is way after the INSERT call. In order for a registration to have a status of Approve (wp_esp_registration.STS_ID = ‘RAP’) it’s been inserted early on, the attendee has run through all of the reg steps and finalized and the user paid (or they’ve finalized with a default registration status of Approved) but either way, you’ll only pull that registration on the NEXT insert which is why you have to register twice. I’m not sure how you can work around that in the above, you will always be at least one registration behind. |
|
|
Thanks Tony, |
|
you’re right.. i see that registrants have a status of “RIC” before the full registration process is completed. |
You could hook into the thank you page, use the transaction object passed to the hooks on that page to pull pretty much everything you need from Event Espresso and then add the record there. You’ll obviously need some additional checks to confirm the user hasn’t refreshed or revisits etc, but it’s doable. Take a look at the Then use our models to pull everything you need (or do it directly if you want to): https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System |
|
|
just to put some finality into this, I was able to achieve my desired output by 1.changing the ON INSERT TRIGGER into an ON UPDATE TRIGGER When the User registers for an event but have not yet to finalize, EE inserts a row into wp_esp_registration with STS_ID=’RIC’. On finalization, EE updates RIC to RAP. During the update, the trigger fires and inserts the REG_code into the writee table then updates the same row with values from MyView (which now contains the new record because registration is finalized and ANS_Value has been submitted[see posts above]) Thanks for the insights. |
The support post ‘MySQL trigger after INSERT on wp_esp_registration – requires two inserts to trig’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.