| 1 | <?php |
|---|
| 2 | add_action( 'bb_recount_list', 'fast_recount_list',999); |
|---|
| 3 | |
|---|
| 4 | function fast_recount_list() { |
|---|
| 5 | global $recount_list, $bbdb, $fast_recount, $fast_recount_query; |
|---|
| 6 | |
|---|
| 7 | $fast_recount['fast-topic-posts']="posts of every topic"; |
|---|
| 8 | $fast_recount['fast-topic-deleted-posts']="deleted posts on every topic"; |
|---|
| 9 | $fast_recount['fast-forums']="topics and posts in every forum"; |
|---|
| 10 | // Count topics to which each user has replied. |
|---|
| 11 | // Count tags for every topic. |
|---|
| 12 | // Count topics for every tag. |
|---|
| 13 | // DELETE tags with no topics. Only functions if the above checked. |
|---|
| 14 | // REMOVE deleted topics from users' favorites. |
|---|
| 15 | |
|---|
| 16 | $fast_recount_query['fast-topic-posts']=array(" |
|---|
| 17 | INSERT INTO $bbdb->topics (topic_id, topic_posts) |
|---|
| 18 | (SELECT topic_id, count(post_status) as topic_posts |
|---|
| 19 | FROM $bbdb->posts WHERE post_status = '0' GROUP BY topic_id) |
|---|
| 20 | ON DUPLICATE KEY UPDATE topic_posts=VALUES(topic_posts) "); |
|---|
| 21 | |
|---|
| 22 | $fast_recount_query['fast-topic-deleted-posts']=array(" |
|---|
| 23 | DELETE FROM $bbdb->topicmeta WHERE meta_key = 'deleted_posts '"," |
|---|
| 24 | INSERT INTO $bbdb->topicmeta (meta_key, topic_id, meta_value) |
|---|
| 25 | (SELECT 'deleted_posts', topic_id, count(post_status) as meta_value |
|---|
| 26 | FROM $bbdb->posts WHERE post_status != '0' GROUP BY topic_id) "); |
|---|
| 27 | |
|---|
| 28 | $fast_recount_query['fast-forums']=array(" |
|---|
| 29 | INSERT INTO $bbdb->forums (forum_id, posts) |
|---|
| 30 | (SELECT forum_id, count(post_status) as posts |
|---|
| 31 | FROM $bbdb->posts WHERE post_status = '0' GROUP BY forum_id) |
|---|
| 32 | ON DUPLICATE KEY UPDATE posts=VALUES(posts) "," |
|---|
| 33 | INSERT INTO $bbdb->forums (forum_id, topics) |
|---|
| 34 | (SELECT forum_id, count(topic_status) as topics |
|---|
| 35 | FROM $bbdb->topics WHERE topic_status = '0' GROUP BY forum_id) |
|---|
| 36 | ON DUPLICATE KEY UPDATE topics=VALUES(topics) "); |
|---|
| 37 | |
|---|
| 38 | $fast_recount=array_reverse($fast_recount); |
|---|
| 39 | foreach ($fast_recount as $key=>$value) {array_unshift($recount_list,array($key, __("FAST RECOUNT $value"),'fast_recount'));} |
|---|
| 40 | $fast_recount=array_reverse($fast_recount); |
|---|
| 41 | |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | function fast_recount() { |
|---|
| 45 | global $bbdb, $fast_recount, $fast_recount_query; |
|---|
| 46 | if (!bb_current_user_can('administrate')) {return;} |
|---|
| 47 | bb_check_admin_referer( 'do-counts' ); |
|---|
| 48 | |
|---|
| 49 | foreach ($fast_recount as $key=>$value) { |
|---|
| 50 | if (isset($_POST[$key]) && 1 == $_POST[$key] ) { |
|---|
| 51 | unset($_POST[$key]); // or we'll get called multiple times |
|---|
| 52 | $status=array(); |
|---|
| 53 | echo "\t<li>\n"; |
|---|
| 54 | echo "\t\t" . __("FAST RECOUNT $value..."); |
|---|
| 55 | foreach ($fast_recount_query[$key] as $query) {$status[]=$bbdb->query($query);} |
|---|
| 56 | echo "\t\t (".implode(':',$status).")<br />\n"; |
|---|
| 57 | echo "\t\t" . __("Done fast recounting $value."); |
|---|
| 58 | echo "\n\t</li>\n"; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | ?> |
|---|