Mod Name / Version: Repairing damaged threads
Description: This script check correspondence of fields `B_Main`, `B_Parent`, `B_Board`, `B_Status` of answer posts to values of root post of the thread. I am using this script via cron every hour.
Working Under: UBB.Threads
Mod Status: Finished
Any pre-requisites: Author(s): autoua elia
Date: 10/15/04
Credits: Files Altered: none
New Files: #! /usr/bin/php
<?
// Require the threadss library
require ("../includes/main.inc.php");
//Selecting starting number of records for correcting
$counterquery = "SELECT count(m1.B_Number) FROM {$config['tbprefix']}Posts m1, {$config['tbprefix']}Posts m2
WHERE m2.B_Number = m1.B_Parent
AND m1.B_Parent > 0
AND (m1.B_Board != m2.B_Board or m1.B_Main != m2.B_Main or m1.B_Status != m2.B_Status)
";
$query = $counterquery;
$sth = $dbh -> do_query($query);
list($errcounter) = $dbh -> fetch_array($sth);
// step-by-step correcting errors in three
while ($errcounter > 0)
{
$query = "SELECT m1.B_Number, m2.B_Main, m2.B_Board, m2.B_Status FROM {$config['tbprefix']}Posts m1, {$config['tbprefix']}Posts m2
WHERE m2.B_Number = m1.B_Parent
AND m1.B_Parent > 0
AND (m1.B_Board != m2.B_Board or m1.B_Main != m2.B_Main or m1.B_Status != m2.B_Status)
";
$sth =
$dbh -> do_query($query);
while (list($B_Number1, $B_Main1, $B_Board1, $B_Status1) = $dbh -> fetch_array($sth) )
{
$B_Number_q = addslashes($B_Number1);
$B_Main_q = addslashes($B_Main1);
$B_Board_q = addslashes($B_Board1);
$B_Status_q = addslashes($B_Status1);
$query = "UPDATE {$config['tbprefix']}Posts SET B_Topic = 0, B_Main = '$B_Main_q', B_Board = '$B_Board_q', B_Status = '$B_Status_q'
WHERE B_Number = '$B_Number_q'
";
$dbh -> do_query($query);
}
$query = $counterquery;
$sth =
$dbh -> do_query($query);
list($errcounter) = $dbh -> fetch_array($sth);
}
$dbh -> finish_sth($sth);
?>
Database Altered: no
Info/Instructions: In forums with the big activity we usually have such problem:
- moderator has moved a topic in another forum, but somebody from users has already opened reply window and his post will be placed in forum on old location (value of field `B_Board` for this post will be different from analogous field of root post)
- moderator had closed the tread, but someone user already have opened answer window. And his post will be not "closed", because value of field B_Status will not be "C". So other users have pocibility to continue discussion

in closed thread.
- Topic had been split, subtopic was moved to separate topic, however some of "her" posts has old value of fields `B_Main` or `B_Parent`.
Disclaimer: Please backup every file that you intend to modify.
If the modification modifies the database, it's a good idea to backup your database before doing so.
Note: If you modify your UBB.Threads code, you may be giving up your right for "official" support from Infopop.If you need official support, you'll need to restore unmodified files.