Changeset 2353
- Timestamp:
- 08/12/2009 06:19:11 AM (17 years ago)
- Location:
- trunk/bb-admin
- Files:
-
- 1 added
- 1 edited
-
includes/functions.bb-recount.php (added)
-
tools-recount.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-admin/tools-recount.php
r2236 r2353 1 1 <?php 2 require_once('admin.php'); 2 require_once( 'admin.php' ); 3 require_once( 'includes/functions.bb-recount.php' ); 3 4 4 5 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) { 5 6 bb_check_admin_referer( 'do-counts' ); 6 7 8 // Stores messages 7 9 $messages = array(); 8 if ( isset($_POST['topic-posts']) && 1 == $_POST['topic-posts'] ) { 9 if ( $topics = (array) $bbdb->get_results("SELECT topic_id, COUNT(post_id) AS count FROM $bbdb->posts WHERE post_status = '0' GROUP BY topic_id") ) { 10 $messages[] = __('Counted posts'); 11 foreach ($topics as $topic) { 12 $topic_id = (int) $topic->topic_id; 13 $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->topics SET topic_posts = %s WHERE topic_id = %s" ), $topic->count, $topic_id ); 14 } 15 unset($topics, $topic, $topic_id); 16 } 10 11 if ( !empty( $_POST['topic-posts'] ) ) { 12 $messages[] = bb_recount_topic_posts(); 17 13 } 18 14 19 if ( isset($_POST['topic-voices']) && 1 == $_POST['topic-voices'] ) { 20 if ( $topics = (array) $bbdb->get_results("SELECT topic_id FROM $bbdb->topics ORDER BY topic_id") ) { 21 $messages[] = __('Counted voices'); 22 foreach ($topics as $topic) { 23 $topic_id = (int) $topic->topic_id; 24 if ( $voices = $bbdb->get_col( $bbdb->prepare( "SELECT DISTINCT poster_id FROM $bbdb->posts WHERE topic_id = %s AND post_status = '0';", $topic_id ) ) ) { 25 $voices = count( $voices ); 26 bb_update_topicmeta( $topic_id, 'voices_count', $voices ); 27 } 28 } 29 unset($topics, $topic, $topic_id); 30 } 15 if ( !empty( $_POST['topic-voices'] ) ) { 16 $messages[] = bb_recount_topic_voices(); 31 17 } 32 18 33 if ( isset($_POST['topic-deleted-posts']) && 1 == $_POST['topic-deleted-posts'] ) { 34 $old = (array) $bbdb->get_col("SELECT object_id FROM $bbdb->meta WHERE object_type = 'bb_topics' AND meta_key = 'deleted_posts'"); 35 $old = array_flip($old); 36 if ( $topics = (array) $bbdb->get_results("SELECT topic_id, COUNT(post_id) AS count FROM $bbdb->posts WHERE post_status != '0' GROUP BY topic_id") ) { 37 $messages[] = __('Counting deleted posts…'); 38 foreach ( $topics as $topic ) { 39 bb_update_topicmeta( $topic->topic_id, 'deleted_posts', $topic->count ); 40 unset($old[$topic->topic_id]); 41 } 42 unset($topics, $topic); 43 } 44 if ( $old ) { 45 $old = join(',', array_flip($old)); 46 $bbdb->query("DELETE FROM $bbdb->meta WHERE object_type = 'bb_topic' AND object_id IN ($old) AND meta_key = 'deleted_posts'"); 47 $messages[] = __('…counted deleted posts'); 48 } else { 49 $messages[] = __('…no deleted posts to count'); 50 } 19 if ( !empty( $_POST['topic-deleted-posts'] ) ) { 20 $messages[] = bb_recount_topic_deleted_posts(); 51 21 } 52 22 53 if ( isset($_POST['forums']) && 1 == $_POST['forums'] ) { 54 if ( $all_forums = (array) $bbdb->get_col("SELECT forum_id FROM $bbdb->forums") ) { 55 $messages[] = __('Counted forum topics and posts'); 56 $all_forums = array_flip( $all_forums ); 57 $forums = $bbdb->get_results("SELECT forum_id, COUNT(topic_id) AS topic_count, SUM(topic_posts) AS post_count FROM $bbdb->topics WHERE topic_status = 0 GROUP BY forum_id"); 58 foreach ( (array) $forums as $forum ) { 59 $bbdb->query("UPDATE $bbdb->forums SET topics = '$forum->topic_count', posts = '$forum->post_count' WHERE forum_id = '$forum->forum_id'"); 60 unset($all_forums[$forum->forum_id]); 61 } 62 if ( $all_forums ) { 63 $all_forums = implode(',', array_flip( $all_forums ) ); 64 $bbdb->query("UPDATE $bbdb->forums SET topics = 0, posts = 0 WHERE forum_id IN ($all_forums)"); 65 } 66 unset($all_forums, $forums, $forum); 67 } 23 if ( !empty( $_POST['forums'] ) ) { 24 $messages[] = bb_recount_forum_topics(); 25 $messages[] = bb_recount_forum_posts(); 68 26 } 69 27 70 if ( isset($_POST['topics-replied']) && 1 == $_POST['topics-replied'] ) { 71 if ( $users = (array) $bbdb->get_col("SELECT ID FROM $bbdb->users") ) { 72 $messages[] = __('Counted topics to which each user has replied'); 73 foreach ( $users as $user ) 74 bb_update_topics_replied( $user ); 75 unset($users, $user); 76 } 28 if ( !empty( $_POST['topics-replied'] ) ) { 29 $messages[] = bb_recount_user_topics_replied(); 77 30 } 78 31 79 if ( isset($_POST['topic-tag-count']) && 1 == $_POST['topic-tag-count'] ) { 80 // Reset tag count to zero 81 $bbdb->query( "UPDATE $bbdb->topics SET tag_count = 0" ); 82 83 // Get all tags 84 $terms = $wp_taxonomy_object->get_terms( 'bb_topic_tag' ); 85 86 if ( !is_wp_error( $terms ) && is_array( $terms ) ) { 87 $messages[] = __('Counted topic tags'); 88 foreach ( $terms as $term ) { 89 $topic_ids = bb_get_tagged_topic_ids( $term->term_id ); 90 if ( !is_wp_error( $topic_ids ) && is_array( $topic_ids ) ) { 91 $bbdb->query( 92 "UPDATE $bbdb->topics SET tag_count = tag_count + 1 WHERE topic_id IN (" . join( ',', $topic_ids ) . ")" 93 ); 94 } 95 unset( $topic_ids ); 96 } 97 } 98 unset( $terms, $term ); 32 if ( !empty( $_POST['topic-tag-count'] ) ) { 33 $messages[] = bb_recount_topic_tags(); 99 34 } 100 35 101 if ( isset($_POST['tags-tag-count']) && 1 == $_POST['tags-tag-count'] ) { 102 // Get all tags 103 $terms = $wp_taxonomy_object->get_terms( 'bb_topic_tag', array( 'hide_empty' => false ) ); 104 105 if ( !is_wp_error( $terms ) && is_array( $terms ) ) { 106 $messages[] = __('Counted tagged topics'); 107 $_terms = array(); 108 foreach ( $terms as $term ) { 109 $_terms[] = $term->term_id; 110 } 111 if ( count( $_terms ) ) { 112 $wp_taxonomy_object->update_term_count( $_terms, 'bb_topic_tag' ); 113 } 114 } 115 unset( $term, $_terms ); 36 if ( !empty( $_POST['tags-tag-count'] ) ) { 37 $messages[] = bb_recount_tag_topics(); 116 38 } 117 39 118 if ( isset($_POST['tags-delete-empty']) && 1 == $_POST['tags-delete-empty'] ) { 119 // Get all tags 120 if ( !isset( $terms ) ) { 121 $terms = $wp_taxonomy_object->get_terms( 'bb_topic_tag', array( 'hide_empty' => false ) ); 122 } 123 124 if ( !is_wp_error( $terms ) && is_array( $terms ) ) { 125 $messages[] = __('Deleted tags with no topics'); 126 foreach ( $terms as $term ) { 127 $topic_ids = bb_get_tagged_topic_ids( $term->term_id ); 128 if ( !is_wp_error( $topic_ids ) && is_array( $topic_ids ) ) { 129 if ( false === $topic_ids || ( is_array( $topic_ids ) && !count( $topic_ids ) ) ) { 130 bb_destroy_tag( $term->term_taxonomy_id ); 131 } 132 } 133 unset( $topic_ids ); 134 } 135 } 136 unset( $terms, $term ); 40 if ( !empty( $_POST['tags-delete-empty'] ) ) { 41 $messages[] = bb_recount_tag_delete_empty(); 137 42 } 138 43 139 if ( isset($_POST['clean-favorites']) && 1 == $_POST['clean-favorites'] ) { 140 $favorites_key = $bbdb->prefix . 'favorites'; 141 if ( $users = $bbdb->get_results("SELECT user_id AS id, meta_value AS favorites FROM $bbdb->usermeta WHERE meta_key = '" . $favorites_key . "'") ) { 142 $messages[] = __('Removed deleted topics from users\' favorites'); 143 $topics = $bbdb->get_col("SELECT topic_id FROM $bbdb->topics WHERE topic_status = '0'"); 144 foreach ( $users as $user ) { 145 foreach ( explode(',', $user->favorites) as $favorite ) { 146 if ( !in_array($favorite, $topics) ) { 147 bb_remove_user_favorite( $user->id, $favorite ); 148 } 149 } 150 } 151 unset($topics, $users, $user, $favorite); 152 } 44 if ( !empty( $_POST['clean-favorites'] ) ) { 45 $messages[] = bb_recount_clean_favorites(); 153 46 } 154 47 … … 156 49 foreach ( (array) $recount_list as $item ) { 157 50 if ( isset($item[2]) && isset($_POST[$item[0]]) && 1 == $_POST[$item[0]] && is_callable($item[2]) ) { 158 call_user_func( $item[2] );51 $messages[] = call_user_func( $item[2] ); 159 52 } 160 53 } 161 54 55 wp_cache_flush(); 56 162 57 if ( count( $messages ) ) { 163 58 $messages = join( '</p>' . "\n" . '<p>', $messages ); … … 196 91 </div> 197 92 <?php 93 bb_option_form_element( 'row_limit', array( 94 'title' => __( 'Maximum rows per query' ), 95 'class' => array( 'short' ), 96 'note' => array( 97 __( 'The maximum number of rows to retrieve in any one database query, leave blank for no limit.' ), 98 __( 'Using this will caues bbPress to make smaller queries in larger numbers, which is usually slower, but useful if recounting is causing bbPress to run out of memory.' ) 99 ) 100 ) ); 198 101 } else { 199 102 ?>
Note: See TracChangeset
for help on using the changeset viewer.