MyBB Community Forums

Full Version: Solved Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have a script that I made to make a thread have the "Solved" prefix and move the thread.

Does anyone know how to run the "Rebuild Forum Counters" function that's in the Admin CP?

I need this piece to finish it.
You don't need to do that, using the move_thread function takes care of the counters.
I haven't heard of this function, can you give me the parameters and what it does? (Updates SQL, or what?)
Well how are you moving it currently...?? This is how you should move a thread:

require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
$moderation->move_thread($tid, $move_fid, $move_type, $redirect_time);

It moves it, updates the counters, leaves a redirect if you want... does what you expect it to do.
$set_threads = "UPDATE ".TABLE_PREFIX."threads SET prefix = '6', closed = '1', fid = '139' WHERE tid = '$tid'";
$set = $db->query($set_threads);

That's how I currently am doing it.
So, to put it in that, how would I do it?

I have a variable $tid, and the fid is in there, what about move_type and redirect_time, probably 2 seconds like it currently is.
But, what about changing the prefix and closed status?
No the redirect isn't for the redirect message, it's how long there's a redirect in the thread the forum the thread was originally in, linking to the new location. Use this:

$update = array(
	"prefix" => 6,
	"closed" => 1
);
$db->update_query("threads", $update, "tid = '" . intval($tid) . "'");
require_once MYBB_ROOT."inc/class_moderation.php";
$moderation = new Moderation;
$moderation->move_thread($tid, $fid, $move_type, $redirect_time);

$move_type is either move or redirect, depending on whether or not you want to leave a redirect, and $redirect_time is how many days a redirect is there for, 0 is a permanent redirect.
		$update = array("prefix" => 6, "closed" => 1);
		$db->update_query("threads", $update, "tid = '" . intval($tid) . "'");
		require_once MYBB_ROOT."inc/class_moderation.php";
		$moderation = new Moderation;
		$moderation->move_thread($tid, $fid, $move_type, '0');
What else do I need to replace?
I end up locking the thread and changing the prefix, but, the thread is not moved.
Where is $fid and $move_type set?? I copied and pasted that code form my plugin where it works fine.
I wasn't sure what exactly to enter for $move_type, but, the others are:
$tid = $_GET['tid'];
$threads = $db->query("SELECT * FROM ".TABLE_PREFIX."threads WHERE tid = '$tid'");
$threads_result = $db->fetch_array($threads);
$prefix = $threads_result['prefix'];
$username = $mybb->user['username'];
$subject = $threads_result['subject'];
$uid = $threads_result['uid'];
$fid = $threads_result['fid'];
I said above what to put for $move_type, either move or redirect.

You don't want to be using $_GET, use $mybb->input instead.

$tid = $mybb->input['tid'];

Also you'll need to use intval() around that otherwise you've got a serious SQL injection vulnerability.

I'd suggest you look through the MyBB code a bit to see how queries are done, there's better cleaner ways of doing this. You're also going to have to loop through the results here otherwise you're only going to get the first one, not all the others.

$tid = intval($mybb->input['tid']);
$threads = $db->simple_select("threads", "prefix, subject, uid, fid", "tid = '{$tid}'");
while($thread = $db->fetch_array($query))
{
	// you can just use $thread['subject'] etc here directly
}

Unless you only need the first result, in which case, you don't need to loop, but you should put a limit on the query to only get one result.

That code to move the thread definitely works though. Right now it looks like you're just moving it to where it originally was...
Pages: 1 2