Deleting posts or threads through a manual plugin query causes bug
#11
(2012-03-21, 01:50 PM)crazy4cs Wrote: 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

Yeah, looping a query is a bad idea - especially if the user ends up having many posts. Why not have a look at how matt's Goodbye Spammer works?
Reply
#12
require_once MYBB_ROOT.'/inc/class_moderation.php';
$moderation = new Moderation();

$query = $db->simple_select('posts', 'pid', "uid = '{$uid}'");

if($db->num_rows($query))
{
	while($post = $db->fetch_array($query))
	{
		$moderation->delete_post($post['pid']); 
	}
}

Bare in mind that when MyBB deletes a user, it doesn't actually delete posts but just removes the uid attached to them.

If you don't want to use loops, then you're going to have run more queries to get the lastpost information for the forum then update it accordingly. Take a look at how recount/rebuild counters and lastpost information works and apply it if you want to follow this method. Ideally, use the moderation class.
Reply
#13
(2012-03-21, 03:01 PM)euantor Wrote:
(2012-03-21, 01:50 PM)crazy4cs Wrote: 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

Yeah, looping a query is a bad idea - especially if the user ends up having many posts. Why not have a look at how matt's Goodbye Spammer works?

Matt used foreach()
Reply
#14
(2012-03-21, 03:42 PM)Yaldaram Wrote:
(2012-03-21, 03:01 PM)euantor Wrote:
(2012-03-21, 01:50 PM)crazy4cs Wrote: 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

Yeah, looping a query is a bad idea - especially if the user ends up having many posts. Why not have a look at how matt's Goodbye Spammer works?

Matt used foreach()

Ah right. I never actually looked so thanks Wink
Reply


Forum Jump:


Users browsing this thread: