// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('NOCOOKIES', 1);
define('NOHEADER', 1);
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$start = time();
print ("Welcome to vB3 search re-indexer\n");
print ("What is the full path to your main forum directory? ");
$forumspath = fetch_stdin();
// keep looping until they enter a path which exists
while (!is_dir($forumspath))
{
print ("\n$forumspath is an invalid directory, please re-enter ");
$forumspath = fetch_stdin();
}
print ("Would you like to drop the search table? (y/n) ");
$dropdb = fetch_stdin();
if ($dropdb == 'yes' or $dropdb == 'y')
{
$db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "postindex");
$db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "word");
print ("The tables postindex and word are now empty\n");
}
// tidy up variables dont need this any more
unset($dropdb);
print ("What post number would you like to start at? (0) ");
$startat = intval(fetch_stdin());
print ("What post number would you like to end at? (none) ");
$endat = intval(fetch_stdin());
print ("Posts to process per cycle? (100000) ");
$perpage = intval(fetch_stdin());
if (!$perpage)
{
$perpage = 100000;
}
$stopat = $startat + $perpage;
if ($endat)
{
if ($stopat > $endat)
{
$stopat = $endat;
}
if ($startat >= $endat)
{
continue;
}
}
$posts = $db->query_read("
SELECT postid, post.title, post.pagetext, post.threadid, thread.title AS threadtitle
FROM " . TABLE_PREFIX . "post AS post
INNER JOIN " . TABLE_PREFIX . "thread AS thread ON(thread.threadid = post.threadid)
INNER JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
WHERE (forum.options & 16384)
AND post.postid >= $startat AND post.postid <= $stopat ORDER BY post.postid
");
while ($post = $db->fetch_array($posts))
{
$notdone = TRUE;
if (empty($firstpost["$post[threadid]"]))
{
$getfirstpost = $db->query_first("SELECT MIN(postid) AS postid FROM " . TABLE_PREFIX . "post WHERE threadid = $post[threadid]");
$firstpost["$post[threadid]"] = $getfirstpost['postid'];
}