Changeset 6193
- Timestamp:
- 12/28/2016 10:47:16 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/tools.php
r6191 r6193 682 682 ) ); 683 683 684 // Migrate favorites from user-meta to post-meta684 // Migrate topic subscriptions from user-meta to post-meta 685 685 bbp_register_repair_tool( array( 686 'id' => 'bbp-user- subscriptions-move',687 'description' => __( 'Upgrade user subscriptions', 'bbpress' ),688 'callback' => 'bbp_admin_upgrade_user_ subscriptions',686 'id' => 'bbp-user-topic-subscriptions-move', 687 'description' => __( 'Upgrade user topic subscriptions', 'bbpress' ), 688 'callback' => 'bbp_admin_upgrade_user_topic_subscriptions', 689 689 'priority' => 105, 690 'overhead' => 'high', 691 'components' => array( bbp_get_user_rewrite_id() ) 692 ) ); 693 694 // Migrate forum subscriptions from user-meta to post-meta 695 bbp_register_repair_tool( array( 696 'id' => 'bbp-user-forum-subscriptions-move', 697 'description' => __( 'Upgrade user forum subscriptions', 'bbpress' ), 698 'callback' => 'bbp_admin_upgrade_user_forum_subscriptions', 699 'priority' => 110, 690 700 'overhead' => 'high', 691 701 'components' => array( bbp_get_user_rewrite_id() ) … … 2278 2288 2279 2289 /** 2280 * Upgrade user subscriptions for bbPress 2.6 and higher2290 * Upgrade user topic subscriptions for bbPress 2.6 and higher 2281 2291 * 2282 2292 * @since 2.6.0 bbPress (r6174) … … 2284 2294 * @return array An array of the status code and the message 2285 2295 */ 2286 function bbp_admin_upgrade_user_ subscriptions() {2296 function bbp_admin_upgrade_user_topic_subscriptions() { 2287 2297 2288 2298 // Define variables 2289 2299 $bbp_db = bbp_db(); 2290 $statement = __( 'Upgrading user subscriptions … %s', 'bbpress' );2291 $result = __( 'No subscriptions to upgrade.', 'bbpress' );2300 $statement = __( 'Upgrading user topic subscriptions … %s', 'bbpress' ); 2301 $result = __( 'No topic subscriptions to upgrade.', 'bbpress' ); 2292 2302 $changed = $total = 0; 2293 2303 $key = $bbp_db->prefix . '_bbp_subscriptions'; 2294 2304 $subscriptions = $bbp_db->get_results( $bbp_db->prepare( "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s", $key ) ); 2295 2305 2296 // Bail if no closed topics found2306 // Bail if no topic subscriptions found 2297 2307 if ( empty( $subscriptions ) || is_wp_error( $subscriptions ) ) { 2298 2308 return array( 1, sprintf( $statement, $result ) ); 2299 2309 } 2300 2310 2301 // Loop through each user's favorites2311 // Loop through each user's topic subscriptions 2302 2312 foreach ( $subscriptions as $meta ) { 2303 2313 … … 2307 2317 $changed = 0; 2308 2318 2309 // Add user ID to all favorited posts2319 // Add user ID to all subscribed topics 2310 2320 foreach ( $post_ids as $post_id ) { 2311 2321 … … 2335 2345 2336 2346 // Complete results 2337 $result = sprintf( _n( 'Complete! %d subscription upgraded.', 'Complete! %d subscriptions upgraded.', $total, 'bbpress' ), $total ); 2347 $result = sprintf( _n( 'Complete! %d topic subscription upgraded.', 'Complete! %d topic subscriptions upgraded.', $total, 'bbpress' ), $total ); 2348 2349 return array( 0, sprintf( $statement, $result ) ); 2350 } 2351 2352 /** 2353 * Upgrade user forum subscriptions for bbPress 2.6 and higher 2354 * 2355 * @since 2.6.0 bbPress (r6193) 2356 * 2357 * @return array An array of the status code and the message 2358 */ 2359 function bbp_admin_upgrade_user_forum_subscriptions() { 2360 2361 // Define variables 2362 $bbp_db = bbp_db(); 2363 $statement = __( 'Upgrading user forum subscriptions … %s', 'bbpress' ); 2364 $result = __( 'No forum subscriptions to upgrade.', 'bbpress' ); 2365 $changed = $total = 0; 2366 $key = $bbp_db->prefix . '_bbp_forum_subscriptions'; 2367 $subscriptions = $bbp_db->get_results( $bbp_db->prepare( "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s", $key ) ); 2368 2369 // Bail if no forum subscriptions found 2370 if ( empty( $subscriptions ) || is_wp_error( $subscriptions ) ) { 2371 return array( 1, sprintf( $statement, $result ) ); 2372 } 2373 2374 // Loop through each user's forum subscriptions 2375 foreach ( $subscriptions as $meta ) { 2376 2377 // Get post IDs 2378 $post_ids = explode( ',', $meta->meta_value ); 2379 $to_change = count( $post_ids ); 2380 $changed = 0; 2381 2382 // Add user ID to all subscribed forums 2383 foreach ( $post_ids as $post_id ) { 2384 2385 // Skip if already exists 2386 if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %d", $post_id, '_bbp_forum_subscription', $meta->user_id ) ) ) { 2387 continue; 2388 } 2389 2390 // Add the post meta 2391 $added = add_post_meta( $post_id, '_bbp_subscription', $meta->user_id, false ); 2392 2393 // Bump counts if successfully added 2394 if ( ! empty( $added ) ) { 2395 ++$changed; 2396 ++$total; 2397 } 2398 } 2399 2400 // Delete user meta if everything was copied successfully 2401 if ( $changed === $to_change ) { 2402 //delete_metadata_by_mid( 'user', $meta->umeta_id ); 2403 } 2404 } 2405 2406 // Cleanup 2407 unset( $subscriptions, $added, $post_ids ); 2408 2409 // Complete results 2410 $result = sprintf( _n( 'Complete! %d forum subscription upgraded.', 'Complete! %d forum subscriptions upgraded.', $total, 'bbpress' ), $total ); 2338 2411 2339 2412 return array( 0, sprintf( $statement, $result ) );
Note: See TracChangeset
for help on using the changeset viewer.