Mod Name / Version: Repairing damaged threads <br /><br />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. <br /><br />Working Under: UBB.Threads <br /><br />Mod Status: Finished <br /><br />Any pre-requisites: <br /><br />Author(s): autoua elia <br /><br />Date: 10/15/04 <br /><br />Credits: <br /><br />Files Altered: none <br /><br />New Files: #! /usr/bin/php<br /><?<br /><br />// Require the threadss library<br /> require ("../includes/main.inc.php");<br /> <br />//Selecting starting number of records for correcting<br /> $counterquery = "SELECT count(m1.B_Number) FROM {$config['tbprefix']}Posts m1, {$config['tbprefix']}Posts m2<br />WHERE m2.B_Number = m1.B_Parent<br />AND m1.B_Parent > 0<br />AND (m1.B_Board != m2.B_Board or m1.B_Main != m2.B_Main or m1.B_Status != m2.B_Status)<br />";<br /><br />$query = $counterquery;<br />$sth = $dbh -> do_query($query);<br /><br />list($errcounter) = $dbh -> fetch_array($sth);<br /><br />// step-by-step correcting errors in three<br />while ($errcounter > 0)<br />{<br /><br /> $query = "SELECT m1.B_Number, m2.B_Main, m2.B_Board, m2.B_Status FROM {$config['tbprefix']}Posts m1, {$config['tbprefix']}Posts m2<br />WHERE m2.B_Number = m1.B_Parent<br />AND m1.B_Parent > 0<br />AND (m1.B_Board != m2.B_Board or m1.B_Main != m2.B_Main or m1.B_Status != m2.B_Status)<br />";<br /><br /> $sth = <br /> $dbh -> do_query($query);<br /> <br /> while (list($B_Number1, $B_Main1, $B_Board1, $B_Status1) = $dbh -> fetch_array($sth) )<br /> {<br /><br /> $B_Number_q = addslashes($B_Number1);<br /> $B_Main_q = addslashes($B_Main1);<br /> $B_Board_q = addslashes($B_Board1);<br /> $B_Status_q = addslashes($B_Status1);<br /> <br /> $query = "UPDATE {$config['tbprefix']}Posts SET B_Topic = 0, B_Main = '$B_Main_q', B_Board = '$B_Board_q', B_Status = '$B_Status_q'<br /> WHERE B_Number = '$B_Number_q'<br /> ";<br /> <br /> $dbh -> do_query($query);<br /> }<br /><br /> <br /> $query = $counterquery;<br /> $sth = <br /> $dbh -> do_query($query);<br /> list($errcounter) = $dbh -> fetch_array($sth);<br /><br /><br />}<br /> <br /> $dbh -> finish_sth($sth);<br /><br />?> <br /><br />Database Altered: no <br /><br />Info/Instructions: In forums with the big activity we usually have such problem:<br />- 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)<br />- 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 <img src="http://www.ubbdev.com/forum/images/graemlins/wink.gif" alt="" /> in closed thread.<br />- 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`. <br /><br />Disclaimer: Please backup every file that you intend to modify. <br />If the modification modifies the database, it's a good idea to backup your database before doing so. <br /><br />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.