Make WordPress Core

Changeset 11945


Ignore:
Timestamp:
09/17/2009 08:51:12 PM (17 years ago)
Author:
westi
Message:

Move the storage of the metadata for trashed comments into the comment meta table rather than storing it in an option. See #4529.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r11930 r11945  
    21942194                                                        $action .= ' hide-if-no-js';
    21952195                                                elseif ($action == 'untrash' && $the_comment_status == 'trash') {
    2196                                                         $trash_meta = get_option('wp_trash_meta');
    2197                                                         if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id]['status'])) {
    2198                                                                 if ($trash_meta['comments'][$comment_id]['status'] == '1')
    2199                                                                         $action .= ' approve';
    2200                                                                 else
    2201                                                                         $action .= ' unapprove';
    2202                                                         }
     2196                                                        if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
     2197                                                                $action .= ' approve';
     2198                                                        else
     2199                                                                $action .= ' unapprove';
    22032200                                                }
    22042201
  • trunk/wp-includes/comment.php

    r11943 r11945  
    820820        do_action('delete_comment', $comment_id);
    821821
    822         $trash_meta = get_option('wp_trash_meta');
    823         if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) {
    824                 unset($trash_meta['comments'][$comment_id]);
    825                 update_option('wp_trash_meta', $trash_meta);
    826         }
     822        delete_comment_meta($comment_id,'_wp_trash_meta_status');
     823        delete_comment_meta($comment_id,'_wp_trash_meta_time');
    827824
    828825        if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
    … …  
    866863        do_action('trash_comment', $comment_id);
    867864
    868         $trash_meta = get_option('wp_trash_meta', array());
    869         $trash_meta['comments'][$comment_id]['status'] = $comment->comment_approved;
    870         $trash_meta['comments'][$comment_id]['time'] = time();
    871         update_option('wp_trash_meta', $trash_meta);
    872 
     865        add_comment_meta($comment_id,'_wp_trash_meta_status', $comment->comment_approved);
     866        add_comment_meta($comment_id,'_wp_trash_meta_time', time() );   
     867       
    873868        wp_set_comment_status($comment_id, 'trash');
    874869
    … …  
    892887
    893888        $comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0');
    894 
    895         $trash_meta = get_option('wp_trash_meta');
    896         if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) {
    897                 $comment['comment_approved'] = $trash_meta['comments'][$comment_id]['status'];
    898                 unset($trash_meta['comments'][$comment_id]);
    899                 update_option('wp_trash_meta', $trash_meta);
    900         }
     889       
     890        //Either set comment_approved to the value in comment_meta or worse case to false which will mean moderation
     891        $comment['comment_approved'] = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
    901892
    902893        wp_update_comment($comment);
  • trunk/wp-includes/functions.php

    r11930 r11945  
    33813381        }
    33823382
    3383         //Trashed Comments
    3384         //TODO Come up with a better store for the comment trash meta.
    3385         $trash_meta = get_option('wp_trash_meta');
    3386         if ( !is_array($trash_meta) )
    3387                 return;
    3388 
    3389         foreach ( (array) $trash_meta['comments'] as $id => $meta ) {
    3390                 if ( $meta['time'] < $delete_timestamp ) {
    3391                         wp_delete_comment($id);
    3392                         unset($trash_meta['comments'][$id]);
    3393                 }
    3394         }
    3395 
    3396         update_option('wp_trash_meta', $trash_meta);
     3383        $comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
     3384       
     3385        foreach ( (array) $comments_to_delete as $comment ) {
     3386                wp_delete_comment($comment['comment_id']);
     3387        }
    33973388}
    33983389?>
Note: See TracChangeset for help on using the changeset viewer.