View Full Version : Where in the code are new threads created?
Randomguyy
12-03-2014, 09:29 AM
Hello VBulletin forum,
I am trying to have VBulletin make an additional database entry when creating a new thread. But I just can't seem to find the section where this happens.
Could anyone give me some directions?
Dead Eddie
12-04-2014, 02:27 AM
All the posts go through the API -- vB_Api_Content_{Text, Photo, Link, Poll}
From there, it's handed off to the library (vB_Library_Content_}, and then it gets handed down to the db classes (vB_dB_MySQL_*).
IIRC, all a "new thread" is is a post whose parent is the containing channel.
Randomguyy
12-04-2014, 09:37 AM
Alright, that helped a lot. Thanks for the quick reply! :D
Randomguyy
12-15-2014, 09:27 AM
I think I'll need some more help.
I want to make the database entry with this line of code (maybe this is already where I'm doing a mistake?):
$vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX . "my_table (field1, field2, field3) VALUES (1, 2, 3)");
Now I want this line to be executed upon creating a new thread. So I went and inserted it in the vb_api_content_text add() function, and after it not working I also tried vb_library_content_text add() and a whole lot of other possible functions elsewhere.
However, not once did it actually do a database entry and I would always get this error message from VB in my browser:
Error while saving content: SyntaxError: Unexpected token F
Maybe noteworthy is that while it gave that error message and didn't redirect me to the newly created topic, it did create it nonetheless.
Can you (or someone else) tell what I'm doing wrong? :\
Dead Eddie
12-18-2014, 02:50 AM
Could it be an error with your SQL? Without seeing actual code and/or data, it's tough to debug.
Additionally, the db->query_write stuff is depreciated. Not sure if it'll actually be removed from the source code or not...but might be a good idea to look at the DB Assertor classes. If, for no better reason than it's the vb5 way.
Randomguyy
02-09-2015, 12:26 PM
So I finally had the opportunity to actually continue working on this and first of all, thanks for your reply.
As you suggested, I took a look at the DB Assertor classes and used the insert() function instead of query_write() and changed my code accordingly:
vB_dB_Assertor::insert("my_table", array("field1" => 1, "field2" => 1, "field3" => 1));
I believe this should be correct, but feel free to correct my syntax in case I did something wrong.
Anyway, on to my problem.
I put this in the add() function of vb_api_content (also tried other functions of other classes), but still to no avail. I don't get any error messages anymore, but at the same time nothing happens. So either I'm in the wrong spot or my code is wrong.
Any ideas? :\
Dead Eddie
02-11-2015, 02:18 AM
I think you need to have an entry in the DB Assertor class for your table. You should be able to create your own DB Assertor class and do the entire thing without file edits, though.
Randomguyy
02-11-2015, 02:22 PM
Works like a charm now. Thanks a lot for your help! :D
Randomguyy
03-31-2015, 10:26 AM
So making db entries when creating a new topic works for me. Now, though, I have a new problem.
What I want to do is make it possible to basically reply to a topic with another topic. To do this, I created a button in a PHP module in the first topic, which also adds the topic's ID in the URL. I want to save the IDs of the first and second topic in the db so that I can connect both via a link in f.e. a PHP module.
Now I want this to happen right as you click the 'Post' button for creating a new topic. However, for the life of me, I can't find where exactly in the code I would have to add my own code to execute the db insert.
help pls? :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.