JLA wrote:Well we have finally adapted all of our mods to your code and are now testing your update script. We have received the following error to report
Could not obtain topic information
....
Have a feeling this has to do with the HUGE number of topics and post (over 16 million posts now)
Please advise
Yes, that is correct. Here is an altered version of topic_update.php. Just paste the code into a new file.
This is set to do 500 topics per round. To make this higher, like perhaps 5,000 topics per round, there are two 500s which need to be changed, one in the query, and then one near the end of the file.
If you want automatic refreshing, then alter the die() statement to add a meta http refresh tag, that way you can leave this alone and won't have to click each round.
Completely un-tested too, this one is...
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
echo('<html><head><title>Topic Updater - v1.1</title></head><body>Hello. This script is going to update your topics table so that the existing topics show the correct data.<br /><br /><a href="topic_update.php?mode=start&start=0">Please click here to start.</a>');
if ( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
{
echo('<br /><br />Starting up....<br />');
if(!$start = intval($HTTP_GET_VARS['start']))
{
$start = 0;
}
$total_topics = get_db_stat('topics');
echo('Total topics: ' . number_format($total_topics) . '<br /><br />');
if ($start < $total_topics)
{
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
WHERE t.topic_poster = u.user_id
AND p.post_id = t.topic_first_post_id
AND p2.post_id = t.topic_last_post_id
AND u2.user_id = p2.poster_id
ORDER BY t.topic_id ASC LIMIT " . $start . ', 500';
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
}
echo('<br />' . $sql . '<br /><br />Topics selected');
$total_topics = 0;
while( $row = $db->sql_fetchrow($result) )
{
$topic_rowset[] = $row;
$total_topics++;
}
$db->sql_freeresult($result);
if( $total_topics )
{
echo('<br /><br />Beginning loop<br />');
for($i = 0; $i < $total_topics; $i++)
{
$topic_id = $topic_rowset[$i]['topic_id'];
$topic_title = $topic_rowset[$i]['topic_title'];
$topic_first_poster_name= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? $topic_rowset[$i]['username'] : ( ( $topic_rowset[$i]['post_username'] != '' ) ? $topic_rowset[$i]['post_username'] : $lang['Guest'] );
$topic_last_poster_id = $topic_rowset[$i]['id2'];
$last_poster_name = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : $topic_rowset[$i]['user2'];
$last_post_time = $topic_rowset[$i]['post_time'];
echo('<br />TOPIC ID: ' . $topic_id . ' - ' . $topic_title);
$sql = "UPDATE " . TOPICS_TABLE . "
SET topic_first_poster_name = '$topic_first_poster_name', topic_last_poster_id = '$topic_last_poster_id', topic_last_poster_name = '$last_poster_name', topic_last_post_time = '$last_post_time'
WHERE topic_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not UPDATE topic information', '', __LINE__, __FILE__, $sql);
}
}
}
flush();
// Done with this loop, so go again
die('This loop is done. <a href="./topic_update.php?mode=start&start=' . $start + 500 . '" >Click here</a> to start the next round.<br />');
}
else
{
echo('<br /><br />Loop done!');
echo('<br /><br />Re-synching topic & Forum data....');
sync('all forums', $id = false);
echo('<br />Forum sync done');
sync('all topics', $id = false);
echo('<br />Topic sync done');
echo('<br /><br />EVERYTHING IS DONE!!! <a href="index.php" target="_blank">Check your forum</a> to make sure Dog Cow didn\'t screw up, then you can thank him!! :-)');
}}
echo('</body></html>');
//
// Close our DB connection.
//
$db->sql_close();
exit;
?>