Thread Trigger

Ferity

Member
Hello,

Short introduction:
Every time when a thread is posted in a specific node, I want a poll to be added automatically.

I have already added a Procedure that adds the Poll with the following parameters: (ThreadID, Question, Answer 1, Answer 2, Answer 3). This Procedure has been tested and is working smoothly.

Now to automatize this, I wanted to add an After Insert Trigger on xf_thread. But this runs into an error.

My trigger is the following (we're using MySql if relevant):
Code:
delimiter //
create trigger xftables_Trig_SugPolls
after insert
on  xf_thread
for each row
begin
if(new.node_id = 4) then
    call FSuggestionPolls(new.thread_id,'Do you think that these suggestions should be implemented?','Yes','No','I don\'t care');
end if;
end //
delimiter ;


In my procedure I edit the following tables: xf_thread, xf_poll, xf_poll_response

Creating Threads in node != 4 works fine. But when I create a thread in node 4, I'm experiencing an error. The call FSuggestionPolls Procedure was tested on already existing threads and worked perfectly fine.

Do I possibly have to set the trigger to another database because xf_table might be too early in the thread creation process?


Best regards
Ferity
 
Last edited:
Hi,

Hum why not doing this is in PHP ?

IMO xF class extension is a far easier way to perform this.

Clément
 
Hey MtoR,

thanks for your fast answer!

I've only got some database knowledge and do not know how to code such in Php and how to implement it properly.
Are there any guides you could recommend to learn it?

Best regards
Ferity
 
Hi,

If you don't have PHP knowledge that might be complicated.

You would have to extend the thread model postSave method to create your poll and execute a query.

Perhaps there is a tutorial that explains that, or you can check a mod that does something kinda like that to get inspiration.

Clément
 
Could you tell me where the postSave method can be found?
I should be able to include the call of my method myself.
 
In library/XenForo/Model/Thread.php.

You may have to add a condition to check that it's a new thread not an update.

Clément
 
Back
Top Bottom