Ticket #49236: 49236.4.patch
File 49236.4.patch, 3.1 KB (added by , 4 years ago) |
---|
-
src/wp-includes/comment.php
diff --git src/wp-includes/comment.php src/wp-includes/comment.php index efcf384815..4f9ddbc753 100644
function _wp_batch_update_comment_type() { 3839 3839 */ 3840 3840 $comment_batch_size = (int) apply_filters( 'wp_update_comment_type_batch_size', 100 ); 3841 3841 3842 // Update the `comment_type` field value to be `comment` for the next batch of comments.3843 $ wpdb->query(3842 // Get the IDs of the comments needing to be updated. 3843 $comment_ids = $wpdb->get_col( 3844 3844 $wpdb->prepare( 3845 " UPDATE {$wpdb->comments}3846 SET comment_type = 'comment'3845 "SELECT comment_ID 3846 FROM {$wpdb->comments} 3847 3847 WHERE comment_type = '' 3848 3848 ORDER BY comment_ID DESC 3849 3849 LIMIT %d", … … function _wp_batch_update_comment_type() { 3851 3851 ) 3852 3852 ); 3853 3853 3854 if ( count( $comment_ids ) > 0 ) { 3855 $comment_ids_in = implode( ',', wp_parse_id_list( $comment_ids ) ); 3856 3857 //Update the `comment_type` field value to be `comment` for the next batch of comments. 3858 $wpdb->query( 3859 "UPDATE {$wpdb->comments} 3860 SET comment_type = 'comment' 3861 WHERE comment_type = '' 3862 AND comment_ID IN ({$comment_ids_in})" 3863 ); 3864 3865 // Make sure to clean the comment cache. 3866 clean_comment_cache( $comment_ids ); 3867 } 3868 3854 3869 delete_option( $lock_name ); 3855 3870 } 3856 3871 -
new file tests/phpunit/tests/comment/wpBatchUpdateCommentType.php
diff --git tests/phpunit/tests/comment/wpBatchUpdateCommentType.php tests/phpunit/tests/comment/wpBatchUpdateCommentType.php new file mode 100644 index 0000000000..c035351683
- + 1 <?php 2 3 /** 4 * @group comment 5 * @covers ::_wp_batch_update_comment_type 6 */ 7 class Tests_Batch_Update_Comment_Type extends WP_UnitTestCase { 8 9 public function test__wp_batch_update_comment_type() { 10 global $wpdb; 11 $comments = self::factory()->comment->create_many( 3 ); 12 $comment_objects = array(); 13 $updated_comment_objects = array(); 14 $expected_types = array(); 15 $comment_ids = implode( ',', $comments ); 16 17 clean_comment_cache( $comments ); 18 19 $wpdb->query( 20 "UPDATE {$wpdb->comments} 21 SET comment_type = '' 22 WHERE comment_type = 'comment' 23 AND comment_ID in ({$comment_ids})" 24 ); 25 26 foreach ( $comments as $comment_ID ) { 27 $comment_objects[ $comment_ID ] = get_comment( $comment_ID ); 28 } 29 30 $this->assertEmpty( array_filter( wp_list_pluck( $comment_objects, 'comment_type' ) ) ); 31 32 add_filter( 'wp_update_comment_type_batch_size', array( $this, 'filter_comment_type_batch_size' ) ); 33 add_filter( 'schedule_event', '__return_null' ); 34 35 _wp_batch_update_comment_type(); 36 37 remove_filter( 'wp_update_comment_type_batch_size', array( $this, 'filter_comment_type_batch_size' ) ); 38 remove_filter( 'schedule_event', '__return_null' ); 39 40 foreach ( $comments as $comment_ID ) { 41 $updated_comment_objects[ $comment_ID ] = get_comment( $comment_ID ); 42 $expected_types[ $comment_ID ] = 'comment'; 43 } 44 45 $this->assertEquals( $expected_types, wp_list_pluck( $updated_comment_objects, 'comment_type' ) ); 46 } 47 48 public function filter_comment_type_batch_size() { 49 return 3; 50 } 51 }