Changeset 6496
- Timestamp:
- 06/08/2017 01:37:58 AM (8 years ago)
- Location:
- trunk/src/includes/admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/tools.php
r6438 r6496 171 171 ) ); 172 172 173 // Sync all BuddyPress group forum relationships174 bbp_register_repair_tool( array(175 'id' => 'bbp-group-forums',176 'type' => 'repair',177 'description' => __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ),178 'callback' => 'bbp_admin_repair_group_forum_relationship',179 'priority' => 35,180 'overhead' => 'low',181 'components' => array( bbp_get_forum_post_type() )182 ) );183 184 173 // Update closed topic counts 185 174 bbp_register_repair_tool( array( … … 188 177 'description' => __( 'Repair closed topics', 'bbpress' ), 189 178 'callback' => 'bbp_admin_repair_closed_topics', 190 'priority' => 40,179 'priority' => 35, 191 180 'overhead' => 'medium', 192 181 'components' => array( bbp_get_topic_post_type() ) … … 199 188 'description' => __( 'Recount topics in each forum', 'bbpress' ), 200 189 'callback' => 'bbp_admin_repair_forum_topic_count', 201 'priority' => 4 5,190 'priority' => 40, 202 191 'overhead' => 'medium', 203 192 'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type() ) … … 210 199 'description' => __( 'Recount topics in each topic-tag', 'bbpress' ), 211 200 'callback' => 'bbp_admin_repair_topic_tag_count', 212 'priority' => 50,201 'priority' => 45, 213 202 'overhead' => 'medium', 214 203 'components' => array( bbp_get_topic_post_type(), bbp_get_topic_tag_tax_id() ) … … 221 210 'description' => __( 'Recount replies in each forum', 'bbpress' ), 222 211 'callback' => 'bbp_admin_repair_forum_reply_count', 223 'priority' => 5 5,212 'priority' => 50, 224 213 'overhead' => 'high', 225 214 'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() ) … … 232 221 'description' => __( 'Recount replies in each topic', 'bbpress' ), 233 222 'callback' => 'bbp_admin_repair_topic_reply_count', 223 'priority' => 55, 224 'overhead' => 'high', 225 'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) 226 ) ); 227 228 // Count topic engagements 229 bbp_register_repair_tool( array( 230 'id' => 'bbp-topic-engagements', 231 'type' => 'repair', 232 'description' => __( 'Recount engagements in each topic', 'bbpress' ), 233 'callback' => 'bbp_admin_repair_topic_voice_count', 234 234 'priority' => 60, 235 'overhead' => 'high',236 'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )237 ) );238 239 // Count topic voices240 bbp_register_repair_tool( array(241 'id' => 'bbp-topic-voices',242 'type' => 'repair',243 'description' => __( 'Recount voices in each topic', 'bbpress' ),244 'callback' => 'bbp_admin_repair_topic_voice_count',245 'priority' => 65,246 235 'overhead' => 'high', 247 236 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 254 243 'description' => __( 'Recount pending, spammed, and trashed replies in each topic', 'bbpress' ), 255 244 'callback' => 'bbp_admin_repair_topic_hidden_reply_count', 256 'priority' => 70,245 'priority' => 65, 257 246 'overhead' => 'high', 258 247 'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) … … 265 254 'description' => __( 'Recount topics for each user', 'bbpress' ), 266 255 'callback' => 'bbp_admin_repair_user_topic_count', 267 'priority' => 7 5,256 'priority' => 70, 268 257 'overhead' => 'medium', 269 258 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 276 265 'description' => __( 'Recount replies for each user', 'bbpress' ), 277 266 'callback' => 'bbp_admin_repair_user_reply_count', 278 'priority' => 80,267 'priority' => 75, 279 268 'overhead' => 'medium', 280 269 'components' => array( bbp_get_reply_post_type(), bbp_get_user_rewrite_id() ) … … 287 276 'description' => __( 'Remove unpublished topics from user favorites', 'bbpress' ), 288 277 'callback' => 'bbp_admin_repair_user_favorites', 289 'priority' => 8 5,278 'priority' => 80, 290 279 'overhead' => 'medium', 291 280 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 298 287 'description' => __( 'Remove unpublished topics from user subscriptions', 'bbpress' ), 299 288 'callback' => 'bbp_admin_repair_user_topic_subscriptions', 300 'priority' => 90,289 'priority' => 85, 301 290 'overhead' => 'medium', 302 291 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 309 298 'description' => __( 'Remove unpublished forums from user subscriptions', 'bbpress' ), 310 299 'callback' => 'bbp_admin_repair_user_forum_subscriptions', 311 'priority' => 9 5,300 'priority' => 90, 312 301 'overhead' => 'medium', 313 302 'components' => array( bbp_get_forum_post_type(), bbp_get_user_rewrite_id() ) … … 320 309 'description' => __( 'Remap existing users to default forum roles', 'bbpress' ), 321 310 'callback' => 'bbp_admin_repair_user_roles', 322 'priority' => 100,311 'priority' => 95, 323 312 'overhead' => 'low', 324 313 'components' => array( bbp_get_user_rewrite_id() ) … … 331 320 'description' => __( 'Upgrade user favorites', 'bbpress' ), 332 321 'callback' => 'bbp_admin_upgrade_user_favorites', 333 'priority' => 10 5,322 'priority' => 100, 334 323 'overhead' => 'high', 335 324 'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_favorites_rewrite_id() ) … … 342 331 'description' => __( 'Upgrade user topic subscriptions', 'bbpress' ), 343 332 'callback' => 'bbp_admin_upgrade_user_topic_subscriptions', 344 'priority' => 1 10,333 'priority' => 105, 345 334 'overhead' => 'high', 346 335 'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() ) … … 353 342 'description' => __( 'Upgrade user forum subscriptions', 'bbpress' ), 354 343 'callback' => 'bbp_admin_upgrade_user_forum_subscriptions', 355 'priority' => 11 5,344 'priority' => 110, 356 345 'overhead' => 'high', 357 346 'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() ) … … 364 353 'description' => __( 'Upgrade topic engagements', 'bbpress' ), 365 354 'callback' => 'bbp_admin_upgrade_user_engagements', 355 'priority' => 115, 356 'overhead' => 'medium', 357 'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_engagements_rewrite_id() ) 358 ) ); 359 360 // Sync all BuddyPress group forum relationships 361 bbp_register_repair_tool( array( 362 'id' => 'bbp-group-forums', 363 'type' => 'upgrade', 364 'description' => __( 'Upgrade BuddyPress Group Forum relationships', 'bbpress' ), 365 'callback' => 'bbp_admin_upgrade_group_forum_relationship', 366 366 'priority' => 120, 367 'overhead' => ' medium',368 'components' => array( bbp_get_ user_rewrite_id(), bbp_get_user_engagements_rewrite_id() )367 'overhead' => 'low', 368 'components' => array( bbp_get_forum_post_type() ) 369 369 ) ); 370 370 -
trunk/src/includes/admin/tools/repair.php
r6495 r6496 311 311 312 312 /** 313 * Repair group forum ID mappings after a bbPress 1.1 to bbPress 2.2 conversion314 *315 * @since 2.2.0 bbPress (r4395)316 *317 * @uses bbp_get_forum_post_type() To get the forum post type318 * @return If a wp_error() occurs and no converted forums are found319 */320 function bbp_admin_repair_group_forum_relationship() {321 322 // Define variables323 $bbp_db = bbp_db();324 $statement = __( 'Repairing BuddyPress group-forum relationships… %s', 'bbpress' );325 $g_count = 0;326 $f_count = 0;327 $s_count = 0;328 329 // Copy the BuddyPress filter here, incase BuddyPress is not active330 $prefix = apply_filters( 'bp_core_get_table_prefix', $bbp_db->base_prefix );331 $groups_table = $prefix . 'bp_groups';332 $groups_meta_table = $prefix . 'bp_groups_groupmeta';333 334 // Get the converted forum IDs335 $forum_ids = $bbp_db->query( "SELECT `forum`.`ID`, `forummeta`.`meta_value`336 FROM `{$bbp_db->posts}` AS `forum`337 LEFT JOIN `{$bbp_db->postmeta}` AS `forummeta`338 ON `forum`.`ID` = `forummeta`.`post_id`339 AND `forummeta`.`meta_key` = '_bbp_old_forum_id'340 WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "'341 GROUP BY `forum`.`ID`" );342 343 // Bail if forum IDs returned an error344 if ( is_wp_error( $forum_ids ) || empty( $bbp_db->last_result ) ) {345 return array( 2, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) );346 }347 348 // Stash the last results349 $results = $bbp_db->last_result;350 351 // Update each group forum352 foreach ( $results as $group_forums ) {353 354 // Only update if is a converted forum355 if ( empty( $group_forums->meta_value ) ) {356 continue;357 }358 359 // Attempt to update group meta360 $updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}'" );361 362 // Bump the count363 if ( ! empty( $updated ) && ! is_wp_error( $updated ) ) {364 ++$g_count;365 }366 367 // Update group to forum relationship data368 $group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}'" );369 if ( ! empty( $group_id ) ) {370 371 // Update the group to forum meta connection in forums372 update_post_meta( $group_forums->ID, '_bbp_group_ids', array( $group_id ) );373 374 // Get the group status375 $group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}'" );376 377 // Sync up forum visibility based on group status378 switch ( $group_status ) {379 380 // Public groups have public forums381 case 'public' :382 bbp_publicize_forum( $group_forums->ID );383 384 // Bump the count for output later385 ++$s_count;386 break;387 388 // Private/hidden groups have hidden forums389 case 'private' :390 case 'hidden' :391 bbp_hide_forum( $group_forums->ID );392 393 // Bump the count for output later394 ++$s_count;395 break;396 }397 398 // Bump the count for output later399 ++$f_count;400 }401 }402 403 // Make some logical guesses at the old group root forum404 if ( function_exists( 'bp_forums_parent_forum_id' ) ) {405 $old_default_forum_id = bp_forums_parent_forum_id();406 } elseif ( defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {407 $old_default_forum_id = (int) BP_FORUMS_PARENT_FORUM_ID;408 } else {409 $old_default_forum_id = 1;410 }411 412 // Try to get the group root forum413 $posts = get_posts( array(414 'post_type' => bbp_get_forum_post_type(),415 'meta_key' => '_bbp_old_forum_id',416 'meta_type' => 'NUMERIC',417 'meta_value' => $old_default_forum_id,418 'numberposts' => 1419 ) );420 421 // Found the group root forum422 if ( ! empty( $posts ) ) {423 424 // Rename 'Default Forum' since it's now visible in sitewide forums425 if ( 'Default Forum' === $posts[0]->post_title ) {426 wp_update_post( array(427 'ID' => $posts[0]->ID,428 'post_title' => __( 'Group Forums', 'bbpress' ),429 'post_name' => __( 'group-forums', 'bbpress' ),430 ) );431 }432 433 // Update the group forums root metadata434 update_option( '_bbp_group_forums_root_id', $posts[0]->ID );435 }436 437 // Remove old bbPress 1.1 roles (BuddyPress)438 remove_role( 'member' );439 remove_role( 'inactive' );440 remove_role( 'blocked' );441 remove_role( 'moderator' );442 remove_role( 'keymaster' );443 444 // Complete results445 $result = sprintf( __( 'Complete! %s groups updated; %s forums updated; %s forum statuses synced.', 'bbpress' ), bbp_number_format( $g_count ), bbp_number_format( $f_count ), bbp_number_format( $s_count ) );446 return array( 0, sprintf( $statement, $result ) );447 }448 449 /**450 313 * Recount forum topics 451 314 * -
trunk/src/includes/admin/tools/upgrades.php
r6340 r6496 204 204 205 205 /** 206 * Upgrade group forum ID mappings after a bbPress 1.x to bbPress 2.x conversion 207 * 208 * Previously named: bbp_admin_repair_group_forum_relationships() 209 * 210 * @since 2.6.0 bbPress (r4395) 211 * 212 * @uses bbp_get_forum_post_type() To get the forum post type 213 * @return If a wp_error() occurs and no converted forums are found 214 */ 215 function bbp_admin_upgrade_group_forum_relationships() { 216 217 // Define variables 218 $bbp_db = bbp_db(); 219 $statement = __( 'Upgrading BuddyPress group-forum relationships… %s', 'bbpress' ); 220 $g_count = 0; 221 $f_count = 0; 222 $s_count = 0; 223 224 // Copy the BuddyPress filter here, incase BuddyPress is not active 225 $prefix = apply_filters( 'bp_core_get_table_prefix', $bbp_db->base_prefix ); 226 $groups_table = $prefix . 'bp_groups'; 227 $groups_meta_table = $prefix . 'bp_groups_groupmeta'; 228 229 // Get the converted forum IDs 230 $forum_ids = $bbp_db->query( "SELECT `forum`.`ID`, `forummeta`.`meta_value` 231 FROM `{$bbp_db->posts}` AS `forum` 232 LEFT JOIN `{$bbp_db->postmeta}` AS `forummeta` 233 ON `forum`.`ID` = `forummeta`.`post_id` 234 AND `forummeta`.`meta_key` = '_bbp_old_forum_id' 235 WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "' 236 GROUP BY `forum`.`ID`" ); 237 238 // Bail if forum IDs returned an error 239 if ( is_wp_error( $forum_ids ) || empty( $bbp_db->last_result ) ) { 240 return array( 2, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) ); 241 } 242 243 // Stash the last results 244 $results = $bbp_db->last_result; 245 246 // Update each group forum 247 foreach ( $results as $group_forums ) { 248 249 // Only update if is a converted forum 250 if ( empty( $group_forums->meta_value ) ) { 251 continue; 252 } 253 254 // Attempt to update group meta 255 $updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}'" ); 256 257 // Bump the count 258 if ( ! empty( $updated ) && ! is_wp_error( $updated ) ) { 259 ++$g_count; 260 } 261 262 // Update group to forum relationship data 263 $group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}'" ); 264 if ( ! empty( $group_id ) ) { 265 266 // Update the group to forum meta connection in forums 267 update_post_meta( $group_forums->ID, '_bbp_group_ids', array( $group_id ) ); 268 269 // Get the group status 270 $group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}'" ); 271 272 // Sync up forum visibility based on group status 273 switch ( $group_status ) { 274 275 // Public groups have public forums 276 case 'public' : 277 bbp_publicize_forum( $group_forums->ID ); 278 279 // Bump the count for output later 280 ++$s_count; 281 break; 282 283 // Private/hidden groups have hidden forums 284 case 'private' : 285 case 'hidden' : 286 bbp_hide_forum( $group_forums->ID ); 287 288 // Bump the count for output later 289 ++$s_count; 290 break; 291 } 292 293 // Bump the count for output later 294 ++$f_count; 295 } 296 } 297 298 // Make some logical guesses at the old group root forum 299 if ( function_exists( 'bp_forums_parent_forum_id' ) ) { 300 $old_default_forum_id = bp_forums_parent_forum_id(); 301 } elseif ( defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) { 302 $old_default_forum_id = (int) BP_FORUMS_PARENT_FORUM_ID; 303 } else { 304 $old_default_forum_id = 1; 305 } 306 307 // Try to get the group root forum 308 $posts = get_posts( array( 309 'post_type' => bbp_get_forum_post_type(), 310 'meta_key' => '_bbp_old_forum_id', 311 'meta_type' => 'NUMERIC', 312 'meta_value' => $old_default_forum_id, 313 'numberposts' => 1 314 ) ); 315 316 // Found the group root forum 317 if ( ! empty( $posts ) ) { 318 319 // Rename 'Default Forum' since it's now visible in sitewide forums 320 if ( 'Default Forum' === $posts[0]->post_title ) { 321 wp_update_post( array( 322 'ID' => $posts[0]->ID, 323 'post_title' => __( 'Group Forums', 'bbpress' ), 324 'post_name' => __( 'group-forums', 'bbpress' ), 325 ) ); 326 } 327 328 // Update the group forums root metadata 329 update_option( '_bbp_group_forums_root_id', $posts[0]->ID ); 330 } 331 332 // Remove old bbPress 1.1 roles (BuddyPress) 333 remove_role( 'member' ); 334 remove_role( 'inactive' ); 335 remove_role( 'blocked' ); 336 remove_role( 'moderator' ); 337 remove_role( 'keymaster' ); 338 339 // Complete results 340 $result = sprintf( __( 'Complete! %s groups updated; %s forums updated; %s forum statuses synced.', 'bbpress' ), bbp_number_format( $g_count ), bbp_number_format( $f_count ), bbp_number_format( $s_count ) ); 341 return array( 0, sprintf( $statement, $result ) ); 342 } 343 344 /** 206 345 * Upgrade user favorites for bbPress 2.6 and higher 207 346 *
Note: See TracChangeset
for help on using the changeset viewer.