From ef11608c43960873573362b0104e18932a1f253c Mon Sep 17 00:00:00 2001 From: westi Date: Thu, 17 Sep 2009 20:51:12 +0000 Subject: [PATCH] Move the storage of the metadata for trashed comments into the comment meta table rather than storing it in an option. See #4529. git-svn-id: http://svn.automattic.com/wordpress/trunk@11945 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/template.php | 11 ++++------- wp-includes/comment.php | 25 ++++++++----------------- wp-includes/functions.php | 17 ++++------------- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index b5acd3c9a5..a28a2ae873 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -2193,13 +2193,10 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax ) $action .= ' hide-if-no-js'; elseif ($action == 'untrash' && $the_comment_status == 'trash') { - $trash_meta = get_option('wp_trash_meta'); - if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id]['status'])) { - if ($trash_meta['comments'][$comment_id]['status'] == '1') - $action .= ' approve'; - else - $action .= ' unapprove'; - } + if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true)) + $action .= ' approve'; + else + $action .= ' unapprove'; } echo "$sep$link"; diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 8c91b5d5ad..8411197c97 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -819,11 +819,8 @@ function wp_delete_comment($comment_id) { do_action('delete_comment', $comment_id); - $trash_meta = get_option('wp_trash_meta'); - if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) { - unset($trash_meta['comments'][$comment_id]); - update_option('wp_trash_meta', $trash_meta); - } + delete_comment_meta($comment_id,'_wp_trash_meta_status'); + delete_comment_meta($comment_id,'_wp_trash_meta_time'); if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) return false; @@ -865,11 +862,9 @@ function wp_trash_comment($comment_id = 0) { do_action('trash_comment', $comment_id); - $trash_meta = get_option('wp_trash_meta', array()); - $trash_meta['comments'][$comment_id]['status'] = $comment->comment_approved; - $trash_meta['comments'][$comment_id]['time'] = time(); - update_option('wp_trash_meta', $trash_meta); - + add_comment_meta($comment_id,'_wp_trash_meta_status', $comment->comment_approved); + add_comment_meta($comment_id,'_wp_trash_meta_time', time() ); + wp_set_comment_status($comment_id, 'trash'); do_action('trashed_comment', $comment_id); @@ -891,13 +886,9 @@ function wp_untrash_comment($comment_id = 0) { do_action('untrash_comment', $comment_id); $comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0'); - - $trash_meta = get_option('wp_trash_meta'); - if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) { - $comment['comment_approved'] = $trash_meta['comments'][$comment_id]['status']; - unset($trash_meta['comments'][$comment_id]); - update_option('wp_trash_meta', $trash_meta); - } + + //Either set comment_approved to the value in comment_meta or worse case to false which will mean moderation + $comment['comment_approved'] = get_comment_meta($comment_id, '_wp_trash_meta_status', true); wp_update_comment($comment); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index cc0ce8aaa6..6bfc69e516 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3380,19 +3380,10 @@ function wp_scheduled_delete() { wp_delete_post($post['post_id']); } - //Trashed Comments - //TODO Come up with a better store for the comment trash meta. - $trash_meta = get_option('wp_trash_meta'); - if ( !is_array($trash_meta) ) - return; - - foreach ( (array) $trash_meta['comments'] as $id => $meta ) { - if ( $meta['time'] < $delete_timestamp ) { - wp_delete_comment($id); - unset($trash_meta['comments'][$id]); - } + $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); + + foreach ( (array) $comments_to_delete as $comment ) { + wp_delete_comment($comment['comment_id']); } - - update_option('wp_trash_meta', $trash_meta); } ?> \ No newline at end of file