Modérateur: Modérateurs


$sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
FROM ' . USERS_TABLE . ' u
LEFT JOIN ' . POSTS_TABLE . ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1)
GROUP BY u.user_id';
$result = $db->sql_query($sql);
$user_data = array();
while ($row = $db->sql_fetchrow($result))
{
$user_data[$row['user_id']] = (int) $row['num_posts'];
}
$db->sql_freeresult($result);
$sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
FROM ' . USERS_TABLE . ' u
LEFT JOIN properprefix_posts p ON (u.user_id = p.poster_id AND p.post_postcount = 1)
GROUP BY u.user_id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if (!empty($user_data[$row['user_id']]))
{
$row['num_posts'] += $user_data[$row['user_id']];
}
$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}");
}
$db->sql_freeresult($result); // Resync post counts
$start = $max_post_id = 0;
// Find the maximum post ID, we can only stop the cycle when we've reached it
$sql = 'SELECT MAX(forum_last_post_id) as max_post_id
FROM ' . FORUMS_TABLE;
$result = $db->sql_query($sql);
$max_post_id = (int) $db->sql_fetchfield('max_post_id');
$db->sql_freeresult($result);
// No maximum post id? :o
if (!$max_post_id)
{
$sql = 'SELECT MAX(post_id)
FROM ' . POSTS_TABLE;
$result = $db->sql_query($sql);
$max_post_id = (int) $db->sql_fetchfield('max_post_id');
$db->sql_freeresult($result);
}
// Still no maximum post id? Then we are finished
if (!$max_post_id)
{
add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
break;
}
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
while ($start < $max_post_id)
{
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
FROM ' . POSTS_TABLE . '
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
AND post_postcount = 1 AND post_approved = 1
GROUP BY poster_id';
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
do
{
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
$db->sql_query($sql);
}
while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
$start += $step;
} // Resync post counts
$user_count_data = array();
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
$_xdb_def = array('forum1' => array('prefix' => 'phpbb_'), 'forum2' => array('prefix' => 'slavebb_'),);
foreach ($_xdb_def as $_local_def) {
$start = $max_post_id = 0;
// Find the maximum post ID, we can only stop the cycle when we've reached it
$sql = 'SELECT MAX(forum_last_post_id) as max_post_id
FROM ' . $_local_def['prefix'] . 'forums';
$result = $db->sql_query($sql);
$max_post_id = (int) $db->sql_fetchfield('max_post_id');
$db->sql_freeresult($result);
// No maximum post id? :o
if (!$max_post_id)
{
$sql = 'SELECT MAX(post_id)
FROM ' . $_local_def['prefix'] . 'posts';
$result = $db->sql_query($sql);
$max_post_id = (int) $db->sql_fetchfield('max_post_id');
$db->sql_freeresult($result);
}
// Still no maximum post id? Then we are finished
if (!$max_post_id)
{
add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
continue;
}
while ($start < $max_post_id)
{
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
FROM ' . $_local_def['prefix'] . 'posts
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
AND post_postcount = 1 AND post_approved = 1
GROUP BY poster_id';
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
do
{
$user_count_data[$row['poster_id']] = !empty($user_count_data[$row['poster_id']]) ? (int) ($user_count_data[$row['poster_id']] + $row['num_posts']) : (int) $row['num_posts'];
}
while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
$start += $step;
}
}
foreach ($user_count_data as $user_id => $post_count) {
$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = $post_count WHERE user_id = $user_id");
}$_xdb_def = array('forum1' => array('prefix' => 'phpbb_'), 'forum2' => array('prefix' => 'slavebb_'),); 

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 5 invités