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
This commit is contained in:
westi 2009-09-17 20:51:12 +00:00
parent 607ec769f0
commit ef11608c43
3 changed files with 16 additions and 37 deletions

View File

@ -2193,14 +2193,11 @@ 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')
if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
$action .= ' approve';
else
$action .= ' unapprove';
}
}
echo "<span class='$action'>$sep$link</span>";
}

View File

@ -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,10 +862,8 @@ 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');
@ -892,12 +887,8 @@ function wp_untrash_comment($comment_id = 0) {
$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);

View File

@ -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;
$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) $trash_meta['comments'] as $id => $meta ) {
if ( $meta['time'] < $delete_timestamp ) {
wp_delete_comment($id);
unset($trash_meta['comments'][$id]);
foreach ( (array) $comments_to_delete as $comment ) {
wp_delete_comment($comment['comment_id']);
}
}
update_option('wp_trash_meta', $trash_meta);
}
?>