MyBB Community Forums

Full Version: A new function for getting autoincrement value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
It's possible to "hook" into the DB itself, but you're not providing enough information to really say what you're exactly doing.
Yes i know i could write a my class which extends the actual DB class and then filling its property with these of the original DB and then assign it to $db but what if another plugin makes some queries i would hook these too.

I thought to have explained my intention, getting the the post id in datahandler_post_insert_post and datahandler_post_insert_thread_post hook before that it is inserted into DB.
(2010-04-06, 10:23 AM)flash.tato Wrote: [ -> ]I thought to have explained my intention, getting the the post id in datahandler_post_insert_post and datahandler_post_insert_thread_post hook before that it is inserted into DB.
No, you need to explain your problem at a higher level. Perhaps there is another method of implementing your issue without having to rely on this requirement.
We can't tell, because you're not giving the appropriate level of detail here.
(2010-04-06, 10:23 AM)flash.tato Wrote: [ -> ]getting the the post id in datahandler_post_insert_post and datahandler_post_insert_thread_post hook before that it is inserted into DB.

It's not possible to know the id before the insert. Even MyBB or the DB does not know. It has to ask the DB which id it used after it inserted it. Whatever you are doing with a post, if you need the post id, you want to do it after the insert. There is no other way.

In such a case, when there is apparently no good hook to use, I add debug messages. I added one directly after the post is inserted (echo "post inserted<br>") and one in the plugin class that prints which hooks are getting called.

For a new reply, the hooks getting called look like this:

run_hooks global_start
run_hooks_by_ref my_date
run_hooks_by_ref my_date
run_hooks_by_ref my_date
run_hooks_by_ref my_date
run_hooks_by_ref my_date
run_hooks global_end
run_hooks_by_ref mycode_add_codebuttons
run_hooks newreply_do_newreply_start
run_hooks_by_ref datahandler_post_validate_post
run_hooks_by_ref datahandler_post_insert_post
run_hooks_by_ref datahandler_pm_validate
after insert
run_hooks text_parse_message
run_hooks newreply_do_newreply_end
run_hooks_by_ref my_date
run_hooks_by_ref my_date
run_hooks_by_ref my_date
run_hooks parse_message_start
run_hooks parse_message
run_hooks parse_message_end
run_hooks_by_ref postbit

So the text_parse_message hook is called after the insert and can be used to obtain the post id. Since the text_parse_message hook may be used for other stuff as well, you should only use it only if a post was actually made, i.e. add the text_parse_message_hook in the datahandler_post_insert_post hook. Unconventional, a hack, yes, but it works and avoids a change to core code.

Of course maybe the newreply_do_newreply_end hook would be a better choice. Toungue
(2010-04-06, 11:49 AM)Yumi Wrote: [ -> ]
(2010-04-06, 10:23 AM)flash.tato Wrote: [ -> ]I thought to have explained my intention, getting the the post id in datahandler_post_insert_post and datahandler_post_insert_thread_post hook before that it is inserted into DB.
No, you need to explain your problem at a higher level. Perhaps there is another method of implementing your issue without having to rely on this requirement.
We can't tell, because you're not giving the appropriate level of detail here.

yes i rethought the system, i rewrote it.

The plugin is Tagging Plugin! which you can find in my sig.

Basicall the problem is that some posts may have additional data which i thought to put in another table in database (i added a new table because i could implement searching here).
The table has 3 columns: pid, uid, username. (The data of table is easily guessable).
Now i thought to rewrite it by adding a new column in posts table which stores a serialized array of array('uid' => ..., 'username' => ...).

This new approach will sacrifice the future searching feature that i wanted to implement but i gain in performance as less queries are done and it will reduce server load.

So i would say that with this new approach i thought i don't need to get next autoincrement id as i append data in the queries that MyBB runs for inserting/updating posts. Wink

I hope to have explained better to you.

@frostschutz: yes i thought this, but in that way i would handle newreply.php editpost.php and newthread.php and also i want to make my feature accessible by external plugins which insert posts using DataHandler.
I'd put it in the newreply_do_newreply_end etc hooks personally. External plugins probably won't use your feature anyway, and if they do, there's nothing stopping them from directly calling your function.

Otherwise, if you must use the datahandler, I don't see the problem with hooking into the DB, it's quite easy to filter out what you want, as long as another plugin isn't doing something stupid.
Or stick to code edits. I think it's rather silly to believe that hooks solve everything.
I want that my plugins can be used also by beginners, but if it is needed i do code edits that is no problem for me. Smile
At the end i realized that newthread_do_newthread_end, newreply_do_newreply_end hooks were necessary as i need to send PM and i need the PID of the Post so i separated the PM sending and the post insertion, i couldn't think of a better way.

Thanks again for your answers, it has been a nice chat with you Smile
Pages: 1 2