Make WordPress Core

Changeset 48748


Ignore:
Timestamp:
08/07/2020 02:27:40 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r48658 r48748  
    38403840    $comment_batch_size = (int) apply_filters( 'wp_update_comment_type_batch_size', 100 );
    38413841
    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 to update.
     3843    $comment_ids = $wpdb->get_col(
    38443844        $wpdb->prepare(
    3845             "UPDATE {$wpdb->comments}
    3846             SET comment_type = 'comment'
     3845            "SELECT comment_ID
     3846            FROM {$wpdb->comments}
    38473847            WHERE comment_type = ''
    38483848            ORDER BY comment_ID DESC
     
    38523852    );
    38533853
     3854    if ( $comment_ids ) {
     3855        $comment_id_list = implode( ',', $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_id_list})" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
     3863        );
     3864
     3865        // Make sure to clean the comment cache.
     3866        clean_comment_cache( $comment_ids );
     3867    }
     3868
    38543869    delete_option( $lock_name );
    38553870}
Note: See TracChangeset for help on using the changeset viewer.