From c64297ce61aa9c81af3beb6027f4a4bbd8f5f757 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 7 Aug 2020 14:29:02 +0000 Subject: [PATCH] Comments: Update comment cache in the upgrade routine for changing the `comment_type` DB field value in comments table. This ensures that comment object cache is cleared after changing the comment type to `comment` instead of an empty string. Add a unit test for `_wp_batch_update_comment_type()`. Follow-up to [47597], [47626], [48225], [48227]. Props imath, westonruter. Fixes #49236. Built from https://develop.svn.wordpress.org/trunk@48748 git-svn-id: http://core.svn.wordpress.org/trunk@48510 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 23 +++++++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index efcf384815..47e74bc3f2 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -3839,11 +3839,11 @@ function _wp_batch_update_comment_type() { */ $comment_batch_size = (int) apply_filters( 'wp_update_comment_type_batch_size', 100 ); - // Update the `comment_type` field value to be `comment` for the next batch of comments. - $wpdb->query( + // Get the IDs of the comments to update. + $comment_ids = $wpdb->get_col( $wpdb->prepare( - "UPDATE {$wpdb->comments} - SET comment_type = 'comment' + "SELECT comment_ID + FROM {$wpdb->comments} WHERE comment_type = '' ORDER BY comment_ID DESC LIMIT %d", @@ -3851,6 +3851,21 @@ function _wp_batch_update_comment_type() { ) ); + if ( $comment_ids ) { + $comment_id_list = implode( ',', $comment_ids ); + + // Update the `comment_type` field value to be `comment` for the next batch of comments. + $wpdb->query( + "UPDATE {$wpdb->comments} + SET comment_type = 'comment' + WHERE comment_type = '' + AND comment_ID IN ({$comment_id_list})" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared + ); + + // Make sure to clean the comment cache. + clean_comment_cache( $comment_ids ); + } + delete_option( $lock_name ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index ecfc7c825d..40285a2c69 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-48745'; +$wp_version = '5.6-alpha-48748'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.