MyBB Community Forums

Full Version: Deleting posts or threads through a manual plugin query causes bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am working over making a plugin, in which the plugin deletes specific user's posts and threads.

Everything goes smooth, but it causes a bug. On the index forum listing page and the sub-forum listing (if any sub-forums are there) it does not update the threads and post's accurate count and also keeps on showing last post by usernamehere whereas there is no posts only.

For example, if FORUM A has 3 threads and after my query is ran, 1 thread is deleted so there are 2 left, but on index page, that count won't be updated, it would still show as if there are 3 threads.

See this screenshot:

http://img688.imageshack.us/img688/8238/...7809c5.png

It shows there are 3 threads, whereas when entering the forum, there is not a single thread or post there:

http://i.imgur.com/0aa32.png

I checked the db table mybb_forums which only shows the remaining last post by that test4 guy. So the thing is, how to rebuild that mybb_forums table so that the statistics are updated.

Just like we use rebuild_settings() after activating or deactivating plugin, is there any $db->query for it?

And btw, I tried using optimize query, but no effect.

Also ran recount and rebuild manually to check whether its a problem which could be solved by it, but nope, no effect.

Any solution?

Thank you.
Why not use a SELECT COUNT query first to identify how many posts or threads you will be deleting? You can then use $db->fetch_field so you have a variable that holds that value. After assigning the value to the variable, then you can run an UPDATE query on the forums table.
Good idea. I would try that.
Might sound crazy, but how are you deleting the users' threads and posts? If it's done via the moderation class, you shouldn't be having these problems.
(2012-03-21, 08:54 AM)Tomm M Wrote: [ -> ]Might sound crazy, but how are you deleting the users' threads and posts? If it's done via the moderation class, you shouldn't be having these problems.
I am using query DELETE FROM . And no actually its not being done via moderation but misc.php task (page). Any solutions Tom?

I'd advise using the moderator class as Tomm M mentioned:

require_once MYBB_ROOT.'/inc/class_moderation.php';
$moderation = new Moderation();
$moderation->delete_post($pid);
Okay, but I have some doubts regarding using the moderation class.

$moderation->delete_post($pid);

But what if I want to prune all posts of the user? What query would there be?

Thank you.
If you're returning the result of the SELECT COUNT query in a while() loop then try to run the $moderation->delete_post($pid); inside the while() loop.

Incase you're not using it then you may also use foreach () loop.
I would need to use loops in this? Actually I hate going with loops, I keep them as last option if in case anything is not gonna work. Confused
Inorder to delete all posts you do not have the other way round.
Pages: 1 2