Changeset 6330
- Timestamp:
- 02/26/2017 11:12:37 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/replies/functions.php
r6318 r6330 1019 1019 bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 1020 1020 1021 // Always update voice counts 1022 bbp_update_topic_voice_count( $ancestor ); 1023 1021 1024 // Only update reply count if we're deleting a reply, or in the dashboard. 1022 1025 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) { 1023 1026 bbp_update_topic_reply_count( $ancestor ); 1024 1027 bbp_update_topic_reply_count_hidden( $ancestor ); 1025 bbp_update_topic_voice_count( $ancestor );1026 1028 } 1027 1029 -
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 -
trunk/tests/phpunit/testcases/core/update.php
r5997 r6330 87 87 ) ); 88 88 89 bbp_create_initial_content( array( 'forum_parent' => $category_id ) ); 89 $u = $this->factory->user->create(); 90 91 bbp_create_initial_content( array( 92 'forum_parent' => $category_id, 93 'forum_author' => $u, 94 'topic_author' => $u, 95 'reply_author' => $u 96 ) ); 90 97 91 98 $forum_id = bbp_forum_query_subforum_ids( $category_id ); -
trunk/tests/phpunit/testcases/topics/functions/counts.php
r6036 r6330 16 16 remove_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10 ); 17 17 18 $f = $this->factory->forum->create(); 19 $t = $this->factory->topic->create( array( 20 'post_parent' => $f, 21 'post_author' => bbp_get_current_user_id(), 18 $u = $this->factory->user->create(); 19 $u2 = $this->factory->user->create(); 20 $f = $this->factory->forum->create(); 21 $t = $this->factory->topic->create( array( 22 'post_parent' => $f, 23 'post_author' => $u, 22 24 'topic_meta' => array( 23 25 'forum_id' => $f, … … 26 28 $r1 = $this->factory->reply->create( array( 27 29 'post_parent' => $t, 28 'post_author' => bbp_get_current_user_id(), 29 'reply_meta' => array( 30 'forum_id' => $f, 31 'topic_id' => $t, 32 ), 33 ) ); 34 $u = $this->factory->user->create(); 30 'post_author' => $u, 31 'reply_meta' => array( 32 'forum_id' => $f, 33 'topic_id' => $t, 34 ), 35 ) ); 35 36 36 37 // Don't attempt to send an email. This is for speed and PHP errors. … … 51 52 $r2 = $this->factory->reply->create( array( 52 53 'post_parent' => $t, 53 'post_author' => $u ,54 'post_author' => $u2, 54 55 'reply_meta' => array( 55 56 'forum_id' => $f, … … 59 60 60 61 // Simulate the 'bbp_new_topic' action. 61 do_action( 'bbp_new_reply', $r2, $t, $f, false, $u );62 do_action( 'bbp_new_reply', $r2, $t, $f, false, $u2 ); 62 63 63 64 $count = bbp_get_topic_reply_count( $t, true ); … … 73 74 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 2 ); 74 75 add_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11, 5 ); 75 76 76 } 77 77 … … 80 80 */ 81 81 public function test_bbp_topic_deleted_reply_counts() { 82 $f = $this->factory->forum->create(); 83 $t = $this->factory->topic->create( array( 84 'post_parent' => $f, 85 'post_author' => bbp_get_current_user_id(), 82 $u = $this->factory->user->create(); 83 $u2 = $this->factory->user->create(); 84 $f = $this->factory->forum->create(); 85 $t = $this->factory->topic->create( array( 86 'post_parent' => $f, 87 'post_author' => $u, 86 88 'topic_meta' => array( 87 89 'forum_id' => $f, … … 90 92 $r1 = $this->factory->reply->create( array( 91 93 'post_parent' => $t, 92 'post_author' => bbp_get_current_user_id(), 93 'reply_meta' => array( 94 'forum_id' => $f, 95 'topic_id' => $t, 96 ), 97 ) ); 98 $u = $this->factory->user->create(); 94 'post_author' => $u, 95 'reply_meta' => array( 96 'forum_id' => $f, 97 'topic_id' => $t, 98 ), 99 ) ); 99 100 100 101 $count = bbp_update_topic_reply_count( $t ); … … 109 110 $r2 = $this->factory->reply->create( array( 110 111 'post_parent' => $t, 111 'post_author' => $u ,112 'post_author' => $u2, 112 113 'reply_meta' => array( 113 114 'forum_id' => $f, … … 143 144 */ 144 145 public function test_bbp_topic_trashed_untrashed_reply_counts() { 145 $u = $this->factory->user->create(); 146 $f = $this->factory->forum->create(); 147 $t = $this->factory->topic->create( array( 148 'post_parent' => $f, 146 $u = $this->factory->user->create(); 147 $u2 = $this->factory->user->create(); 148 $f = $this->factory->forum->create(); 149 $t = $this->factory->topic->create( array( 150 'post_parent' => $f, 151 'post_author' => $u, 149 152 'topic_meta' => array( 150 153 'forum_id' => $f, … … 153 156 $r = $this->factory->reply->create_many( 2, array( 154 157 'post_parent' => $t, 158 'post_author' => $u, 155 159 'reply_meta' => array( 156 160 'forum_id' => $f, … … 160 164 $r3 = $this->factory->reply->create( array( 161 165 'post_parent' => $t, 162 'post_author' => $u ,166 'post_author' => $u2, 163 167 'reply_meta' => array( 164 168 'forum_id' => $f, … … 205 209 */ 206 210 public function test_bbp_topic_spammed_unspammed_reply_counts() { 207 $u = $this->factory->user->create(); 208 $f = $this->factory->forum->create(); 209 $t = $this->factory->topic->create( array( 210 'post_parent' => $f, 211 $u = $this->factory->user->create(); 212 $u2 = $this->factory->user->create(); 213 $f = $this->factory->forum->create(); 214 $t = $this->factory->topic->create( array( 215 'post_parent' => $f, 216 'post_author' => $u, 211 217 'topic_meta' => array( 212 218 'forum_id' => $f, … … 215 221 $r = $this->factory->reply->create_many( 2, array( 216 222 'post_parent' => $t, 223 'post_author' => $u, 217 224 'reply_meta' => array( 218 225 'forum_id' => $f, … … 222 229 $r3 = $this->factory->reply->create( array( 223 230 'post_parent' => $t, 224 'post_author' => $u ,231 'post_author' => $u2, 225 232 'reply_meta' => array( 226 233 'forum_id' => $f, … … 265 272 */ 266 273 public function test_bbp_topic_approved_unapproved_reply_counts() { 267 $u = $this->factory->user->create(); 268 $f = $this->factory->forum->create(); 269 $t = $this->factory->topic->create( array( 270 'post_parent' => $f, 274 $u = $this->factory->user->create(); 275 $u2 = $this->factory->user->create(); 276 $f = $this->factory->forum->create(); 277 $t = $this->factory->topic->create( array( 278 'post_parent' => $f, 279 'post_author' => $u, 271 280 'topic_meta' => array( 272 281 'forum_id' => $f, … … 275 284 $r = $this->factory->reply->create_many( 2, array( 276 285 'post_parent' => $t, 286 'post_author' => $u, 277 287 'reply_meta' => array( 278 288 'forum_id' => $f, … … 282 292 $r3 = $this->factory->reply->create( array( 283 293 'post_parent' => $t, 284 'post_author' => $u ,294 'post_author' => $u2, 285 295 'reply_meta' => array( 286 296 'forum_id' => $f, … … 543 553 $t = $this->factory->topic->create(); 544 554 555 bbp_update_topic_voice_count( $t ); 556 $count = bbp_get_topic_voice_count( $t ); 557 $this->assertSame( '0', $count ); 558 559 $r = $this->factory->reply->create( array( 560 'post_author' => $u[0], 561 'post_parent' => $t, 562 ) ); 563 564 bbp_update_topic_voice_count( $t ); 545 565 $count = bbp_get_topic_voice_count( $t ); 546 566 $this->assertSame( '1', $count ); 547 567 548 568 $r = $this->factory->reply->create( array( 549 'post_author' => $u[ 0],569 'post_author' => $u[1], 550 570 'post_parent' => $t, 551 571 ) ); … … 554 574 $count = bbp_get_topic_voice_count( $t ); 555 575 $this->assertSame( '2', $count ); 556 557 $count = bbp_update_topic_voice_count( $t );558 $this->assertSame( 2, $count );559 560 $r = $this->factory->reply->create( array(561 'post_author' => $u[1],562 'post_parent' => $t,563 ) );564 565 bbp_update_topic_voice_count( $t );566 $count = bbp_get_topic_voice_count( $t );567 $this->assertSame( '3', $count );568 576 } 569 577 -
trunk/tests/phpunit/testcases/topics/functions/topic.php
r6036 r6330 15 15 */ 16 16 public function test_bbp_insert_topic() { 17 17 $u = $this->factory->user->create_many( 2 ); 18 18 $f = $this->factory->forum->create(); 19 19 … … 22 22 23 23 $t = $this->factory->topic->create( array( 24 'post_title' => 'Topic 1',24 'post_title' => 'Topic 1', 25 25 'post_content' => 'Content for Topic 1', 26 'post_parent' => $f, 27 'post_date' => $post_date, 28 'topic_meta' => array( 26 'post_parent' => $f, 27 'post_date' => $post_date, 28 'post_author' => $u[0], 29 'topic_meta' => array( 29 30 'forum_id' => $f, 30 31 ), … … 33 34 $r = $this->factory->reply->create( array( 34 35 'post_parent' => $t, 35 'post_date' => $post_date, 36 'reply_meta' => array( 36 'post_date' => $post_date, 37 'post_author' => $u[1], 38 'reply_meta' => array( 37 39 'forum_id' => $f, 38 40 'topic_id' => $t, … … 54 56 // Topic meta. 55 57 $this->assertSame( $f, bbp_get_topic_forum_id( $t ) ); 56 $this->assertSame( 1, bbp_get_topic_reply_count( $t, true ) );57 $this->assertSame( 0, bbp_get_topic_reply_count_hidden( $t, true ) );58 $this->assertSame( 1,bbp_get_topic_voice_count( $t, true ) );58 $this->assertSame( 1, bbp_get_topic_reply_count( $t, true ) ); 59 $this->assertSame( 0, bbp_get_topic_reply_count_hidden( $t, true ) ); 60 $this->assertSame( 2, bbp_get_topic_voice_count( $t, true ) ); 59 61 $this->assertSame( $r, bbp_get_topic_last_reply_id( $t ) ); 60 62 $this->assertSame( $r, bbp_get_topic_last_active_id( $t ) ); -
trunk/tests/phpunit/testcases/topics/template/counts.php
r5870 r6330 194 194 $t = $this->factory->topic->create( array( 195 195 'post_parent' => $f, 196 'post_parent' => $u[0], 196 197 'topic_meta' => array( 197 198 'forum_id' => $f, … … 208 209 ) ); 209 210 210 $count = bbp_ get_topic_voice_count( $t, true);211 $this->assertSame( 2, $count );211 $count = bbp_update_topic_voice_count( $t ); 212 $this->assertSame( 1, $count ); 212 213 213 214 $r2 = $this->factory->reply->create( array( … … 221 222 ) ); 222 223 223 $count = bbp_get_topic_voice_count( $t, true ); 224 $count = bbp_update_topic_voice_count( $t ); 225 $this->assertSame( 1, $count ); 226 227 bbp_approve_reply( $r2 ); 228 229 $count = bbp_update_topic_voice_count( $t ); 224 230 $this->assertSame( 2, $count ); 225 226 bbp_approve_reply( $r2 );227 228 $count = bbp_get_topic_voice_count( $t, true );229 $this->assertSame( 3, $count );230 231 } 231 232 }
Note: See TracChangeset
for help on using the changeset viewer.