|
| 1 | +/* Insert all users data */ |
| 2 | +INSERT INTO wp_bbp_users |
| 3 | +SELECT |
| 4 | + p.post_author AS user_id, |
| 5 | + IF (r.first_reply_date IS NULL || t.first_topic_date <= r.last_reply_date, t.first_topic_date, r.first_reply_date) AS first_posted, |
| 6 | + IF (r.last_reply_date IS NULL || t.last_topic_date >= r.last_reply_date, t.last_topic_date, r.last_reply_date) AS last_posted, |
| 7 | + IF (u.last_active IS NULL, '0000-00-00 00:00:00', FROM_UNIXTIME(u.last_active, '%Y-%d-%m %H:%i:%s')) AS last_active, |
| 8 | + IF (t.topic_count IS NULL, 0, t.topic_count) AS topic_count, |
| 9 | + IF (r.reply_count IS NULL, 0, r.reply_count) AS reply_count |
| 10 | +FROM (SELECT DISTINCT post_author |
| 11 | + FROM wp_posts |
| 12 | + WHERE post_type IN ('topic', 'reply') AND post_status IN ('publish', 'closed')) p |
| 13 | +LEFT JOIN (SELECT post_author AS user_id, COUNT(ID) AS topic_count, MAX(post_date) AS last_topic_date, MIN(post_date) AS first_topic_date |
| 14 | + FROM wp_posts |
| 15 | + WHERE post_type = 'topic' AND post_status IN ('publish', 'closed') |
| 16 | + GROUP BY post_author) t ON t.user_id = p.post_author |
| 17 | +LEFT JOIN (SELECT post_author AS user_id, COUNT(ID) AS reply_count, MAX(post_date) AS last_reply_date, MIN(post_date) AS first_reply_date |
| 18 | + FROM wp_posts |
| 19 | + WHERE post_type = 'reply' AND post_status IN ('publish') |
| 20 | + GROUP BY post_author) r ON r.user_id = p.post_author |
| 21 | +LEFT JOIN (SELECT user_id, MAX(meta_value) AS last_active |
| 22 | + FROM wp_usermeta WHERE meta_key = 'wp_bbp_last_activity' |
| 23 | + GROUP BY user_id) u ON u.user_id = p.post_author |
0 commit comments