Ticket #1799: 1799.6.diff
File 1799.6.diff, 18.7 KB (added by , 10 years ago) |
---|
-
src/includes/core/actions.php
255 255 add_action( 'bbp_approved_reply', 'bbp_update_reply_walker' ); 256 256 add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' ); 257 257 258 // Update forum topic/reply counts 259 add_action( 'bbp_new_reply', 'bbp_increase_forum_reply_count' ); 260 add_action( 'bbp_new_topic', 'bbp_increase_forum_topic_count' ); 261 add_action( 'bbp_trashed_reply', 'bbp_decrease_forum_reply_count' ); 262 add_action( 'bbp_trashed_topic', 'bbp_decrease_forum_topic_count' ); 263 add_action( 'bbp_trashed_topic', 'bbp_increase_forum_topic_count_hidden' ); 264 add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count' ); 265 add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count' ); 266 add_action( 'bbp_untrashed_topic', 'bbp_decrease_forum_topic_count_hidden' ); 267 add_action( 'bbp_spammed_reply', 'bbp_decrease_forum_reply_count' ); 268 add_action( 'bbp_spammed_topic', 'bbp_decrease_forum_topic_count' ); 269 add_action( 'bbp_spammed_topic', 'bbp_increase_forum_topic_count_hidden' ); 270 add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count' ); 271 add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count' ); 272 add_action( 'bbp_unspammed_topic', 'bbp_decrease_forum_topic_count_hidden' ); 273 add_action( 'bbp_approved_reply', 'bbp_increase_forum_reply_count' ); 274 add_action( 'bbp_approved_topic', 'bbp_increase_forum_topic_count' ); 275 add_action( 'bbp_approved_topic', 'bbp_decrease_forum_topic_count_hidden' ); 276 add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count' ); 277 add_action( 'bbp_unapproved_topic', 'bbp_decrease_forum_topic_count' ); 278 add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' ); 279 280 // Update topic reply counts 281 add_action( 'bbp_new_reply', 'bbp_increase_topic_reply_count' ); 282 add_action( 'bbp_trashed_reply', 'bbp_decrease_topic_reply_count' ); 283 add_action( 'bbp_trashed_reply', 'bbp_increase_topic_reply_count_hidden' ); 284 add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count' ); 285 add_action( 'bbp_untrashed_reply', 'bbp_decrease_topic_reply_count_hidden' ); 286 add_action( 'bbp_spammed_reply', 'bbp_decrease_topic_reply_count' ); 287 add_action( 'bbp_spammed_reply', 'bbp_increase_topic_reply_count_hidden' ); 288 add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count' ); 289 add_action( 'bbp_unspammed_reply', 'bbp_decrease_topic_reply_count_hidden' ); 290 add_action( 'bbp_approved_reply', 'bbp_increase_topic_reply_count' ); 291 add_action( 'bbp_approved_reply', 'bbp_decrease_forum_reply_count_hidden' ); 292 add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count' ); 293 add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' ); 294 258 295 // Users topic & reply counts 259 296 add_action( 'bbp_new_topic', 'bbp_increase_user_topic_count' ); 260 297 add_action( 'bbp_new_reply', 'bbp_increase_user_reply_count' ); -
src/includes/forums/functions.php
1085 1085 } 1086 1086 1087 1087 /** 1088 * Increase the total topic count of a forum by one 1089 * 1090 * @since bbPress () 1091 * 1092 * @param int $forum_id Optional. Forum id. 1093 * @uses bbp_get_forum_id() To get the forum id 1094 * @uses bbp_bump_forum_topic_count() To bump forum topic count 1095 */ 1096 function bbp_increase_forum_topic_count( $forum_id = 0 ) { 1097 if ( empty( $forum_id ) ) { 1098 return; 1099 } 1100 1101 if ( bbp_is_topic( $forum_id ) ) { 1102 $topic_id = $forum_id; 1103 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1104 1105 // If this is a new, unpublished, topic, increase hidden count and bail 1106 if ( 'bbp_new_topic' === current_action() && ( ! bbp_is_topic_published( $topic_id ) && ! bbp_is_topic_closed( $topic_id ) ) ) { 1107 bbp_increase_forum_topic_count_hidden( $forum_id ); 1108 return; 1109 } 1110 } 1111 1112 bbp_bump_forum_topic_count( $forum_id ); 1113 } 1114 1115 /** 1116 * Decrease the total topic count of a forum by one 1117 * 1118 * @since bbPress () 1119 * 1120 * @param int $forum_id Optional. Forum id. 1121 * @uses bbp_get_forum_id() To get the forum id 1122 * @uses bbp_bump_forum_topic_count() To bump forum topic count 1123 */ 1124 function bbp_decrease_forum_topic_count( $forum_id = 0 ) { 1125 if ( empty( $forum_id ) ) { 1126 return; 1127 } 1128 1129 if ( bbp_is_topic( $forum_id ) ) { 1130 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1131 } 1132 1133 bbp_bump_forum_topic_count( $forum_id, -1 ); 1134 } 1135 1136 /** 1088 1137 * Bump the total hidden topic count of a forum 1089 1138 * 1090 1139 * @since bbPress (r3825) … … 1112 1161 } 1113 1162 1114 1163 /** 1164 * Increase the total hidden topic count of a forum by one 1165 * 1166 * @since bbPress () 1167 * 1168 * @param int $forum_id Optional. Forum id. 1169 * @uses bbp_get_forum_id() To get the forum id 1170 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count 1171 */ 1172 function bbp_increase_forum_topic_count_hidden( $forum_id = 0 ) { 1173 if ( empty( $forum_id ) ) { 1174 return; 1175 } 1176 1177 if ( bbp_is_topic( $forum_id ) ) { 1178 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1179 } 1180 1181 bbp_bump_forum_topic_count_hidden( $forum_id ); 1182 } 1183 1184 /** 1185 * Decrease the total hidden topic count of a forum by one 1186 * 1187 * @since bbPress () 1188 * 1189 * @param int $forum_id Optional. Forum id. 1190 * @uses bbp_get_forum_id() To get the forum id 1191 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count 1192 */ 1193 function bbp_decrease_forum_topic_count_hidden( $forum_id = 0 ) { 1194 if ( empty( $forum_id ) ) { 1195 return; 1196 } 1197 1198 if ( bbp_is_topic( $forum_id ) ) { 1199 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1200 } 1201 1202 bbp_bump_forum_topic_count_hidden( $forum_id, -1 ); 1203 } 1204 1205 /** 1115 1206 * Bump the total topic count of a forum 1116 1207 * 1117 1208 * @since bbPress (r3825) … … 1161 1252 return (int) apply_filters( 'bbp_bump_forum_reply_count', (int) $total_reply_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors ); 1162 1253 } 1163 1254 1255 /** 1256 * Increase the total reply count of a forum by one 1257 * 1258 * @since bbPress () 1259 * 1260 * @param int $forum_id Optional. Forum id. 1261 * @uses bbp_get_forum_id() To get the forum id 1262 * @uses bbp_bump_forum_reply_count() To bump forum topic count 1263 */ 1264 function bbp_increase_forum_reply_count( $forum_id = 0 ) { 1265 if ( empty( $forum_id ) ) { 1266 return; 1267 } 1268 1269 if ( bbp_is_reply( $forum_id ) ) { 1270 $reply_id = $forum_id; 1271 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1272 1273 // Don't update if this is a new, unpublished, reply 1274 if ( 'bbp_new_reply' === current_action() && ! bbp_is_reply_published( $reply_id ) ) { 1275 return; 1276 } 1277 } 1278 1279 bbp_bump_forum_reply_count( $forum_id, 1 ); 1280 } 1281 1282 /** 1283 * Decrease the total reply count of a forum by one 1284 * 1285 * @since bbPress () 1286 * 1287 * @param int $forum_id Optional. Forum id. 1288 * @uses bbp_get_forum_id() To get the forum id 1289 * @uses bbp_bump_forum_reply_count() To bump forum topic count 1290 */ 1291 function bbp_decrease_forum_reply_count( $forum_id = 0 ) { 1292 if ( empty( $forum_id ) ) { 1293 return; 1294 } 1295 1296 if ( bbp_is_reply( $forum_id ) ) { 1297 $forum_id = bbp_get_reply_forum_id( $forum_id ); 1298 } 1299 1300 bbp_bump_forum_reply_count( $forum_id, -1 ); 1301 } 1302 1164 1303 /** Forum Updaters ************************************************************/ 1165 1304 1166 1305 /** … … 1618 1757 } 1619 1758 1620 1759 // Counts 1621 bbp_update_forum_subforum_count ( $r['forum_id'] ); 1622 bbp_update_forum_reply_count ( $r['forum_id'] ); 1623 bbp_update_forum_topic_count ( $r['forum_id'] ); 1624 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); 1760 bbp_update_forum_subforum_count( $r['forum_id'] ); 1625 1761 1762 // Only update topic count if we're deleting a topic, or in the dashboard 1763 if ( in_array( current_action(), array( 'bbp_deleted_topic', 'save_post' ) ) ) { 1764 bbp_update_forum_reply_count( $r['forum_id'] ); 1765 bbp_update_forum_topic_count( $r['forum_id'] ); 1766 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); 1767 } 1768 1626 1769 // Update the parent forum if one was passed 1627 1770 if ( !empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) { 1628 1771 bbp_update_forum( array( -
src/includes/replies/functions.php
974 974 } 975 975 976 976 // Counts 977 bbp_update_topic_voice_count ( $ancestor ); 978 bbp_update_topic_reply_count ( $ancestor ); 979 bbp_update_topic_reply_count_hidden( $ancestor ); 977 bbp_update_topic_voice_count( $ancestor ); 980 978 979 // Only update reply count if we're deleting a reply, or in the dashboard 980 if ( in_array( current_action(), array( 'bbp_deleted_reply', 'save_post' ) ) ) { 981 bbp_update_topic_reply_count( $ancestor ); 982 bbp_update_topic_reply_count_hidden( $ancestor ); 983 } 984 981 985 // Forum meta relating to most recent topic 982 986 } elseif ( bbp_is_forum( $ancestor ) ) { 983 987 … … 1000 1004 } 1001 1005 1002 1006 // Counts 1003 bbp_update_forum_reply_count( $ancestor ); 1007 // Only update reply count if we're deleting a reply, or in the dashboard 1008 if ( in_array( current_action(), array( 'bbp_deleted_reply', 'save_post' ) ) ) { 1009 bbp_update_forum_reply_count( $ancestor ); 1010 } 1004 1011 } 1005 1012 } 1006 1013 } -
src/includes/topics/functions.php
2342 2342 } 2343 2343 2344 2344 /** 2345 * Increase the total reply count of a topic by one 2346 * 2347 * @since bbPress () 2348 * 2349 * @param int $topic_id Optional. Forum id. 2350 * @uses bbp_is_reply() To check if the passed topic id is a reply 2351 * @uses bbp_get_reply_topic_id() To get the topic id 2352 * @uses bbp_bump_topic_reply_count() To bump topic reply count 2353 */ 2354 function bbp_increase_topic_reply_count( $topic_id = 0 ) { 2355 if ( empty( $topic_id ) ) { 2356 return; 2357 } 2358 2359 if ( bbp_is_reply( $topic_id ) ) { 2360 $reply_id = $topic_id; 2361 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2362 2363 // If this is a new, unpublished, reply, update hidden count and bail 2364 if ( 'bbp_new_reply' === current_action() && ! bbp_is_reply_published( $reply_id ) ) { 2365 bbp_increase_topic_reply_count_hidden( $topic_id ); 2366 return; 2367 } 2368 } 2369 2370 bbp_bump_topic_reply_count( $topic_id ); 2371 } 2372 2373 /** 2374 * Decrease the total reply count of a topic by one 2375 * 2376 * @since bbPress () 2377 * 2378 * @param int $topic_id Optional. Topic id. 2379 * @uses bbp_is_reply() To check if the passed topic id is a reply 2380 * @uses bbp_get_reply_topic_id() To get the topic id 2381 * @uses bbp_bump_topic_reply_count() To bump topic reply count 2382 */ 2383 function bbp_decrease_topic_reply_count( $topic_id = 0 ) { 2384 if ( empty( $topic_id ) ) { 2385 return; 2386 } 2387 2388 if ( bbp_is_reply( $topic_id ) ) { 2389 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2390 } 2391 2392 bbp_bump_topic_reply_count( $topic_id, -1 ); 2393 } 2394 2395 /** 2345 2396 * Bump the total hidden reply count of a topic 2346 2397 * 2347 2398 * @since bbPress (r3825) … … 2368 2419 return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference ); 2369 2420 } 2370 2421 2422 /** 2423 * Increase the total hidden reply count of a topic by one 2424 * 2425 * @since bbPress () 2426 * 2427 * @param int $topic_id Optional. Topic id. 2428 * @uses bbp_is_reply() To check if the passed topic id is a reply 2429 * @uses bbp_get_reply_topic_id() To get the topic id 2430 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count 2431 */ 2432 function bbp_increase_topic_reply_count_hidden( $topic_id = 0 ) { 2433 if ( empty( $topic_id ) ) { 2434 return; 2435 } 2436 2437 if ( bbp_is_reply( $topic_id ) ) { 2438 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2439 } 2440 2441 bbp_bump_topic_reply_count_hidden( $topic_id ); 2442 } 2443 2444 /** 2445 * Decrease the total hidden reply count of a topic by one 2446 * 2447 * @since bbPress () 2448 * 2449 * @param int $topic_id Optional. Topic id. 2450 * @uses bbp_is_reply() To check if the passed topic id is a reply 2451 * @uses bbp_get_reply_topic_id() To get the topic id 2452 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count 2453 */ 2454 function bbp_decrease_topic_reply_count_hidden( $topic_id = 0 ) { 2455 if ( empty( $topic_id ) ) { 2456 return; 2457 } 2458 2459 if ( bbp_is_reply( $topic_id ) ) { 2460 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2461 } 2462 2463 bbp_bump_topic_reply_count_hidden( $topic_id, -1 ); 2464 } 2465 2371 2466 /** Topic Updaters ************************************************************/ 2372 2467 2373 2468 /** -
tests/phpunit/testcases/forums/functions/counts.php
25 25 } 26 26 27 27 /** 28 * @covers ::bbp_increase_forum_topic_count 29 */ 30 public function test_bbp_increase_forum_topic_count() { 31 $f = $this->factory->forum->create(); 32 33 $count = bbp_get_forum_topic_count( $f ); 34 $this->assertSame( '0', $count ); 35 36 bbp_increase_forum_topic_count( $f ); 37 38 $count = bbp_get_forum_topic_count( $f ); 39 $this->assertSame( '1', $count ); 40 } 41 42 /** 43 * @covers ::bbp_decrease_forum_topic_count 44 */ 45 public function test_bbp_decrease_forum_topic_count() { 46 $f = $this->factory->forum->create(); 47 48 $count = bbp_get_forum_topic_count( $f ); 49 $this->assertSame( '0', $count ); 50 51 $t = $this->factory->topic->create_many( 9, array( 52 'post_parent' => $f, 53 ) ); 54 55 bbp_update_forum_topic_count( $f ); 56 57 $count = bbp_get_forum_topic_count( $f ); 58 $this->assertSame( '9', $count ); 59 60 bbp_update_forum_topic_count( $f ); 61 62 bbp_decrease_forum_topic_count( $f ); 63 64 $count = bbp_get_forum_topic_count( $f ); 65 $this->assertSame( '8', $count ); 66 } 67 68 /** 28 69 * @covers ::bbp_bump_forum_topic_count_hidden 29 70 */ 30 71 public function test_bbp_bump_forum_topic_count_hidden() { … … 40 81 } 41 82 42 83 /** 84 * @covers ::bbp_increase_forum_topic_count_hidden 85 */ 86 public function test_bbp_increase_forum_topic_count_hidden() { 87 $f = $this->factory->forum->create(); 88 89 $count = bbp_get_forum_topic_count_hidden( $f ); 90 $this->assertSame( '0', $count ); 91 92 bbp_increase_forum_topic_count_hidden( $f ); 93 94 $count = bbp_get_forum_topic_count_hidden( $f ); 95 $this->assertSame( '1', $count ); 96 } 97 98 /** 99 * @covers ::bbp_decrease_forum_topic_count_hidden 100 */ 101 public function test_bbp_decrease_forum_topic_count_hidden() { 102 $f = $this->factory->forum->create(); 103 104 $count = bbp_get_forum_topic_count_hidden( $f ); 105 $this->assertSame( '0', $count ); 106 107 $t = $this->factory->topic->create_many( 9, array( 108 'post_parent' => $f, 109 'post_status' => bbp_get_spam_status_id(), 110 'topic_meta' => array( 111 'forum_id' => $f, 112 'spam_meta_status' => 'publish', 113 ) 114 ) ); 115 116 bbp_update_forum_topic_count_hidden( $f ); 117 118 $count = bbp_get_forum_topic_count_hidden( $f ); 119 $this->assertSame( '9', $count ); 120 121 bbp_decrease_forum_topic_count_hidden( $f ); 122 123 $count = bbp_get_forum_topic_count_hidden( $f ); 124 $this->assertSame( '8', $count ); 125 } 126 127 128 /** 43 129 * @covers ::bbp_bump_forum_reply_count 44 130 */ 45 131 public function test_bbp_bump_forum_reply_count() { … … 54 140 $this->assertSame( '1', $count ); 55 141 } 56 142 143 57 144 /** 145 * @covers ::bbp_increase_forum_reply_count 146 */ 147 public function test_bbp_increase_forum_reply_count() { 148 $f = $this->factory->forum->create(); 149 150 $count = bbp_get_forum_reply_count( $f ); 151 $this->assertSame( '0', $count ); 152 153 bbp_increase_forum_reply_count( $f ); 154 155 $count = bbp_get_forum_reply_count( $f ); 156 $this->assertSame( '1', $count ); 157 } 158 159 /** 160 * @covers ::bbp_decrease_forum_reply_count 161 */ 162 public function test_bbp_decrease_forum_reply_count() { 163 $f = $this->factory->forum->create(); 164 165 $count = bbp_get_forum_reply_count( $f ); 166 $this->assertSame( '0', $count ); 167 168 $t = $this->factory->topic->create( array( 169 'post_parent' => $f, 170 ) ); 171 172 $r = $this->factory->reply->create_many( 9, array( 173 'post_parent' => $t, 174 ) ); 175 176 bbp_update_forum_reply_count( $f ); 177 178 $count = bbp_get_forum_reply_count( $f ); 179 $this->assertSame( '9', $count ); 180 181 bbp_decrease_forum_reply_count( $f ); 182 183 $count = bbp_get_forum_reply_count( $f ); 184 $this->assertSame( '8', $count ); 185 } 186 187 /** 58 188 * @covers ::bbp_update_forum_subforum_count 59 189 */ 60 190 public function test_bbp_update_forum_subforum_count() { -
tests/phpunit/testcases/topics/functions/counts.php
25 25 } 26 26 27 27 /** 28 * @covers ::bbp_increase_topic_reply_count 29 */ 30 public function test_bbp_increase_topic_reply_count() { 31 $t = $this->factory->topic->create(); 32 33 $count = bbp_get_topic_reply_count( $t ); 34 $this->assertSame( '0', $count ); 35 36 bbp_increase_topic_reply_count( $t ); 37 38 $count = bbp_get_topic_reply_count( $t ); 39 $this->assertSame( '1', $count ); 40 } 41 42 /** 43 * @covers ::bbp_decrease_topic_reply_count 44 */ 45 public function test_bbp_decrease_topic_reply_count() { 46 $t = $this->factory->topic->create(); 47 48 $count = bbp_get_topic_reply_count( $t ); 49 $this->assertSame( '0', $count ); 50 51 // Set the count manually to 9 52 bbp_update_topic_reply_count( $t, 9 ); 53 54 $count = bbp_get_topic_reply_count( $t ); 55 $this->assertSame( '9', $count ); 56 57 bbp_decrease_topic_reply_count( $t ); 58 59 $count = bbp_get_topic_reply_count( $t ); 60 $this->assertSame( '8', $count ); 61 } 62 63 /** 28 64 * @covers ::bbp_bump_topic_reply_count_hidden 29 65 */ 30 66 public function test_bbp_bump_topic_reply_count_hidden() { … … 40 76 } 41 77 42 78 /** 79 * @covers ::bbp_increase_topic_reply_count_hidden 80 */ 81 public function test_bbp_increase_topic_reply_count_hidden() { 82 $t = $this->factory->topic->create(); 83 84 $count = bbp_get_topic_reply_count_hidden( $t ); 85 $this->assertSame( '0', $count ); 86 87 bbp_increase_topic_reply_count_hidden( $t ); 88 89 $count = bbp_get_topic_reply_count_hidden( $t ); 90 $this->assertSame( '1', $count ); 91 } 92 93 /** 94 * @covers ::bbp_decrease_topic_reply_count_hidden 95 */ 96 public function test_bbp_decrease_topic_reply_count_hidden() { 97 $t = $this->factory->topic->create(); 98 99 $count = bbp_get_topic_reply_count_hidden( $t ); 100 $this->assertSame( '0', $count ); 101 102 // Set the count manually to 9 103 bbp_update_topic_reply_count_hidden( $t, 9 ); 104 105 $count = bbp_get_topic_reply_count_hidden( $t ); 106 $this->assertSame( '9', $count ); 107 108 bbp_decrease_topic_reply_count_hidden( $t ); 109 110 $count = bbp_get_topic_reply_count_hidden( $t ); 111 $this->assertSame( '8', $count ); 112 } 113 114 /** 43 115 * @covers ::bbp_update_topic_reply_count 44 116 */ 45 117 public function test_bbp_update_topic_reply_count() {