MyBB Community Forums

Full Version: Using the PM datahandler's "datahandler_pm_insert" hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Due to this issue in myALerts, I'm looking at using the PM handler's "datahandler_pm_insert" hook instead of "private_do_send_end" as I currently am.

The problem is that the datahandler hook is ran before the PM is actually inserted, meaning the PM ID is not set. There are three possible ways around this I can see:

  1. Grab the highest ID from the private messages table and add 1 - kind of dirty and not really reliable if lots of PMs are getting sent often possibly.
  2. Use PluginLibrary to edit the PM handler to add a new hook after the PM is inserted.
  3. Use multiple hooks in all locations that PMs are sent rather than 1 single one - definitely not clean.

Just looking to see if anybody might have any other ideas or past experience using the datahandler that I can call on to make life easier before diving into this.

Thanks in advance!
The second way looks the best imho. I'm currently using it for Moderation Alerts Pack because hooks are placed in awful positions into certain files such as moderation.php and editpost.php.

The others sound too unreliable and resource wasteful.
I did this ages ago. I'll see if I can dig up some code.
(2013-02-10, 11:41 AM)Tomm M Wrote: [ -> ]I did this ages ago. I'll see if I can dig up some code.

That would be nice Tomm, thanks.
This is hacky solution but should work. Use the hook and insert into database yourself. Take control of the $db object and modify insert_query to disallow running the query a second time.
I could do that, but it's not exactly a nice solution for others who may be hooking in within other plugins.
Set your hook priority to a big number and that's solved.
Could do that I guess, didn't think of that.
(2013-02-10, 07:05 PM)Pirata Nervo Wrote: [ -> ]insert into database yourself. Take control of the $db object

If you're going that far you could just grab the ID from the original query, without blocking any queries.
Yeah that would work too Toungue
Pages: 1 2 3