MyBB Community Forums

Full Version: Repair thread table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I recently converted from phpBB3 to MyBB 1.2 via the merge tool.

Everything is working smoothly, and the transfer even fixed a few display issues I was having with my forums. However, there was a pre-existing problem I hope you can help me with. I have a few hundred topics that were lost due to improper backups made by the original webmaster of the site. The posts for these threads still exist (as well as the thread IDs) so I know it is technically possible to restore the missing threads, but I'm a bit lost as to how to go about it (my PHP skills are not all that great)

If someone could please write me a small script to repair this, I would greatly appreciate it.

To my knowledge, you need a joined select statement that uses a WHERE clause to look for tids from the post table that aren't in the thread table, which isn't a problem for me to write, but then there's the matter of taking this, getting the title of the topic from the post, etc, and inserting it into the thread table.
The select statement would select the post title. Then you'd just use it in your insert.

// Grab all the tids that aren't in the threads table
$query =  mysql_query("SELECT subject, tid, .......");

// Loop through all of them
while($row = mysql_fetch_array($query))
{
    if(!isset($done[$row['tid']]))
    {
       mysql_query("INSERT INTO mybb_threads (tid, subject, ...) VALUES('{$row['tid']}', '{$row['subject']}', ...)");
       $done[$row['tid']] = true;
    }
}

//etc...
Why aren't the posts part of a thread? And I had something similar happen but the posts were all part of threads not if a forum (fid). You need to find what's missing and like Dennis said...run a loop to fix them.