[wp-trac] [WordPress Trac] #49236: Use 'comment' instead of '' for the comment_type db field for comments
WordPress Trac
noreply at wordpress.org
Tue Aug 4 20:36:42 UTC 2020
#49236: Use 'comment' instead of '' for the comment_type db field for comments
-------------------------------------------------+-------------------------
Reporter: imath | Owner:
| SergeyBiryukov
Type: enhancement | Status: closed
Priority: normal | Milestone: 5.5
Component: Comments | Version: 5.4
Severity: normal | Resolution: fixed
Keywords: has-patch early commit has-dev-note | Focuses:
-------------------------------------------------+-------------------------
Comment (by westonruter):
Changing `get_comment()` like so wouldn't be enough since it wouldn't
account for people using `WP_Comment` directly. So it would need to be
done at a lower level, like:
{{{#!diff
<?php
--- a/src/wp-includes/class-wp-comment.php
+++ b/src/wp-includes/class-wp-comment.php
@@ -186,6 +186,10 @@ final class WP_Comment {
return false;
}
+ if ( empty( $_comment->comment_type ) ) {
+ $_comment->comment_type = 'comment';
+ }
+
wp_cache_add( $_comment->comment_ID, $_comment,
'comment' );
}
}}}
So I think I prefer the second alternative you proposed, where `UPDATE` is
done followed by `clean_comment_cache()`, although with one adjustment:
add a safeguard in the `WHERE` to double-confirm that the `comment_type`
is indeed empty. Like so:
{{{#!diff
--- a/src/wp-includes/comment.php
+++ b/src/wp-includes/comment.php
@@ -3840,10 +3840,10 @@ 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(
+ $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,18 @@ function _wp_batch_update_comment_type() {
)
);
+ $in_comment_ids = implode( ',', wp_parse_id_list( $comment_ids )
);
+
+ $wpdb->query(
+ $wpdb->prepare(
+ "UPDATE {$wpdb->comments}
+ SET comment_type = 'comment'
+ WHERE comment_type = '' AND comment_ID IN
({$in_comment_ids})"
+ )
+ );
+
+ clean_comment_cache( $comment_ids );
+
delete_option( $lock_name );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49236#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list