insert ignore into xfavforums.dark_postrating select null, vbulletin.post_thanks.postid, vbulletin.post_thanks.userid, vbulletin.post.userid, 5, date from vbulletin.post_thanks left join vbulletin.post on (vbulletin.post.postid = vbulletin.post_thanks.postid);
truncate table dark_postrating_count;
insert into dark_postrating_count
(user_id, rating, count_received) (
SELECT rated_user_id, rating, count(*) as count_received
FROM dark_postrating
inner join xf_post on dark_postrating.post_id = xf_post.post_id
where rated_user_id is not null and rated_user_id > 0 and xf_post.message_state = 'visible'
group by rated_user_id, rating
) on duplicate key update dark_postrating_count.count_received = values(count_received);
insert into dark_postrating_count
(user_id, rating, count_given) (
SELECT dark_postrating.user_id, rating, count(*) as count_given
FROM dark_postrating
inner join xf_post on dark_postrating.post_id = xf_post.post_id
where xf_post.message_state = 'visible'
group by dark_postrating.user_id, rating
) on duplicate key update dark_postrating_count.count_given = values(count_given);