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.
Reviewed by desrosj, SergeyBiryukov.
Merges [48748] and [48751] to the 5.5 branch.
Fixes #49236.
Built from https://develop.svn.wordpress.org/branches/5.5@48752


git-svn-id: http://core.svn.wordpress.org/branches/5.5@48514 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-08-07 16:35:08 +00:00
parent 719ef3461b
commit 52b59a5f07
3 changed files with 26 additions and 9 deletions

View File

@ -2174,9 +2174,6 @@ function upgrade_550() {
global $wp_current_db_version; global $wp_current_db_version;
if ( $wp_current_db_version < 48121 ) { if ( $wp_current_db_version < 48121 ) {
update_option( 'finished_updating_comment_type', 0 );
wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
$comment_previously_approved = get_option( 'comment_whitelist', '' ); $comment_previously_approved = get_option( 'comment_whitelist', '' );
update_option( 'comment_previously_approved', $comment_previously_approved ); update_option( 'comment_previously_approved', $comment_previously_approved );
delete_option( 'comment_whitelist' ); delete_option( 'comment_whitelist' );
@ -2198,6 +2195,11 @@ function upgrade_550() {
delete_option( 'blacklist_keys' ); delete_option( 'blacklist_keys' );
delete_option( 'blocklist_keys' ); delete_option( 'blocklist_keys' );
} }
if ( $wp_current_db_version < 48748 ) {
update_option( 'finished_updating_comment_type', 0 );
wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_update_comment_type_batch' );
}
} }
/** /**

View File

@ -3839,11 +3839,11 @@ function _wp_batch_update_comment_type() {
*/ */
$comment_batch_size = (int) apply_filters( 'wp_update_comment_type_batch_size', 100 ); $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. // Get the IDs of the comments to update.
$wpdb->query( $comment_ids = $wpdb->get_col(
$wpdb->prepare( $wpdb->prepare(
"UPDATE {$wpdb->comments} "SELECT comment_ID
SET comment_type = 'comment' FROM {$wpdb->comments}
WHERE comment_type = '' WHERE comment_type = ''
ORDER BY comment_ID DESC ORDER BY comment_ID DESC
LIMIT %d", 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 ); delete_option( $lock_name );
} }

View File

@ -13,14 +13,14 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-RC2-48747'; $wp_version = '5.5-RC2-48752';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
* *
* @global int $wp_db_version * @global int $wp_db_version
*/ */
$wp_db_version = 48575; $wp_db_version = 48748;
/** /**
* Holds the TinyMCE version. * Holds the TinyMCE version.