Changeset 6330 for trunk/src/includes/topics/functions.php
- Timestamp:
- 02/26/2017 11:12:37 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/topics/functions.php
r6318 r6330 1282 1282 } 1283 1283 1284 /** Engagements ***********************************************************/ 1285 1286 // Get engagements from source topic 1287 $engagements = bbp_get_topic_engagements( $source_topic->ID ); 1288 1289 // Maybe migrate engagements 1290 if ( ! empty( $engagements ) ) { 1291 foreach ( $engagements as $engager ) { 1292 bbp_add_user_engagement( $engager, $destination_topic->ID ); 1293 } 1294 } 1295 1284 1296 /** Subscriptions *********************************************************/ 1285 1297 … … 1287 1299 $subscribers = bbp_get_topic_subscribers( $source_topic->ID ); 1288 1300 1289 // Remove the topic from everybody's subscriptions 1290 if ( ! empty( $subscribers ) ) { 1291 1292 // Loop through each user 1293 foreach ( (array) $subscribers as $subscriber ) { 1294 1295 // Shift the subscriber if told to 1296 if ( ! empty( $_POST['bbp_topic_subscribers'] ) && ( "1" === $_POST['bbp_topic_subscribers'] ) && bbp_is_subscriptions_active() ) { 1297 bbp_add_user_subscription( $subscriber, $destination_topic->ID ); 1298 } 1299 1300 // Remove old subscription 1301 bbp_remove_user_subscription( $subscriber, $source_topic->ID ); 1301 // Maybe migrate subscriptions 1302 if ( ! empty( $subscribers ) && ! empty( $_POST['bbp_topic_subscribers'] ) && ( '1' === $_POST['bbp_topic_subscribers'] ) ) { 1303 foreach ( $subscribers as $subscriber ) { 1304 bbp_add_user_subscription( $subscriber, $destination_topic->ID ); 1302 1305 } 1303 1306 } … … 1308 1311 $favoriters = bbp_get_topic_favoriters( $source_topic->ID ); 1309 1312 1310 // Remove the topic from everybody's favorites 1311 if ( ! empty( $favoriters ) ) { 1312 1313 // Loop through each user 1314 foreach ( (array) $favoriters as $favoriter ) { 1315 1316 // Shift the favoriter if told to 1317 if ( ! empty( $_POST['bbp_topic_favoriters'] ) && "1" === $_POST['bbp_topic_favoriters'] ) { 1318 bbp_add_user_favorite( $favoriter, $destination_topic->ID ); 1319 } 1320 1321 // Remove old favorite 1322 bbp_remove_user_favorite( $favoriter, $source_topic->ID ); 1313 // Maybe migrate favorites 1314 if ( ! empty( $favoriters ) && ! empty( $_POST['bbp_topic_favoriters'] ) && ( '1' === $_POST['bbp_topic_favoriters'] ) ) { 1315 foreach ( $favoriters as $favoriter ) { 1316 bbp_add_user_favorite( $favoriter, $destination_topic->ID ); 1323 1317 } 1324 1318 } … … 1356 1350 delete_post_meta( $source_topic->ID, '_bbp_reply_count' ); 1357 1351 delete_post_meta( $source_topic->ID, '_bbp_reply_count_hidden' ); 1352 1353 // Delete source topics user relationships 1354 delete_post_meta( $source_topic->ID, '_bbp_favorite' ); 1355 delete_post_meta( $source_topic->ID, '_bbp_subscription' ); 1356 delete_post_meta( $source_topic->ID, '_bbp_engagement' ); 1358 1357 1359 1358 // Get the replies of the source topic … … 2966 2965 } 2967 2966 2967 // Delete all engagements 2968 delete_post_meta( $topic_id, '_bbp_engagement' ); 2969 2968 2970 // Query the DB to get voices in this topic 2969 $bbp_db = bbp_db(); 2970 $query = $bbp_db->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = %s AND post_type = %s ) OR ( ID = %d AND post_type = %s )", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2971 $voices = (int) $bbp_db->get_var( $query ); 2971 $bbp_db = bbp_db(); 2972 $sql = "SELECT DISTINCT post_author FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = %s AND post_type = %s ) OR ( ID = %d AND post_type = %s )"; 2973 $query = $bbp_db->prepare( $sql, $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2974 $results = $bbp_db->get_col( $query ); 2975 2976 // Parse results into voices 2977 $voices = ! is_wp_error( $results ) 2978 ? wp_parse_id_list( array_filter( $results ) ) 2979 : array(); 2972 2980 2973 2981 // Update the voice count for this topic id 2974 update_post_meta( $topic_id, '_bbp_voice_count', $voices ); 2975 2976 return (int) apply_filters( 'bbp_update_topic_voice_count', $voices, $topic_id ); 2982 foreach ( $voices as $user_id ) { 2983 bbp_add_user_engagement( $user_id, $topic_id ); 2984 } 2985 2986 // Get the count 2987 $count = count( $voices ); 2988 2989 // Update the voice count for this topic id 2990 update_post_meta( $topic_id, '_bbp_voice_count', $count ); 2991 2992 return (int) apply_filters( 'bbp_update_topic_voice_count', $count, $topic_id ); 2977 2993 } 2978 2994
Note: See TracChangeset
for help on using the changeset viewer.