[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 15:41:47 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):

 @imath I have a concern about how the SQL `UPDATE` will bypass updates to
 the object cache. I believe it would be preferable follow the model of
 `wp_delete_auto_drafts()` which grabs the post IDs and then loops over
 each to call `wp_delete_post()`. In the same way, instead of doing:

 {{{#!php
 <?php
 $wpdb->query(
         $wpdb->prepare(
                 "UPDATE {$wpdb->comments}
                 SET comment_type = 'comment'
                 WHERE comment_type = ''
                 ORDER BY comment_ID DESC
                 LIMIT %d",
                 $comment_batch_size
         )
 );
 }}}

 Should it not rather do:

 {{{#!php
 <?php
 $comment_ids = $wpdb->get_col(
         $wpdb->prepare(
                 "SELECT comment_id
                 FROM {$wpdb->comments}
                 WHERE comment_type = ''
                 ORDER BY comment_ID DESC
                 LIMIT %d",
                 $comment_batch_size
         )
 );
 foreach ( (array) $comment_ids as $comment_id ) {
         wp_update_comment(
                 [
                         'comment_ID'   => $comment_id,
                         'comment_type' => 'comment',
                 ]
         );
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49236#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list