Difference between insert post and insert post from draft?
#1
Hi everyone,

I've got a function that is hooked to "datahandler_post_insert_post".

What already works:
- When a user posts in a certain forum (set in $ipids) the user table in the database is updated
- If the post is safed as a draft it isn't

My Problem now is that the user table should be updated if I edit a draft and turn it into a visible post. The part of datahandler/post.php that refers to that looks quite similar and it's the same hook so I don't understand why it doesn't work.

Here is my code:
$ipids = explode(",", trim($mybb->settings['lastippost']));
if (in_array($datahandler->data['fid'], $ipids) && $datahandler->data['visible'] == 1)
{
        $db->update_query("users", array('lastippost' => $datahandler->data['dateline']),"uid = '".$datahandler->data['uid']."'");
}

Any ideas?
Reply
#2
What version of MyBB are you using? I don't know what that site you linked is but that's version 1.6, which is several years old. https://github.com/mybb/mybb/blob/featur...s/post.php is the actual current version of the file for 1.8.10. To answer your question, I don't see anything wrong with those few lines, what is the exact error you're getting and what is the rest of your code? Would be helpful to see the $datahandler object, etc. Have you checked to see if the update query is even being called? Does the lastippost column exist in the users table?
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply
#3
Oh thanks for pointing that out, I didn't look at the version in the site I linked. I'm using the latest version of mybb.

I'm using this hook here at the top of my file:

$plugins->add_hook("datahandler_post_insert_post", "lastippost_insert");  
 
And this is the whole function (the parts IP Posts and NP Posts are almost similar, ignore one of them Wink ) :
function lastippost_insert($datahandler)
{
        global $db, $mybb;

        if ($mybb->settings['lastippost'] != '' || $mybb->settings['lastnppost'] != '')
        {
                //IP Posts loggen
                $ipids = explode(",", trim($mybb->settings['lastippost']));
                if (in_array($datahandler->data['fid'], $ipids) && $datahandler->data['visible'] == 1)
                {
                        $db->update_query("users", array('lastippost' => $datahandler->data['dateline']),"uid = '".$datahandler->data['uid']."'");
                }

                //NP Posts loggen
                $npids = explode(",", trim($mybb->settings['lastnppost']));
                if (in_array($datahandler->data['fid'], $npids)  && $datahandler->data['visible'] == 1)
                {
                        $db->update_query("users", array('lastnppost' => $datahandler->data['dateline']),"uid = '".$datahandler->data['uid']."'");
                }
        }
}

To answer your questions:
It does work when a new post is posted so that's how I know the code as such works. The lastippost column exists, is filled correctly and there is no error.

When I update a draft to turn it into a visible post, there is no error as well but the column simply isn't filled. 

From what I understand of the code the same hook is used in the same way and should therefore work similar. Or is that where I'm wrong?
Reply
#4
Can anyone explain me how the hook works differently in these two cases (editing draft to post vs. regular post)?
Or is it my code that is wrong?

I would really love to finish that plugin Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)