From f84839d5af4dc5c6274dc84ad34f082b10dfd5fc Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 31 Mar 2009 19:16:53 +0000 Subject: [PATCH] Fix delete statements to ensure data integrity when innodb and foreign keys are used. Props Denis-de-Bernardy. see #9422 git-svn-id: http://svn.automattic.com/wordpress/trunk@10851 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/user.php | 2 +- wp-includes/post.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index af724ce021..e93fc428bd 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -431,8 +431,8 @@ function wp_delete_user($id, $reassign = 'novalue') { // FINALLY, delete user do_action('delete_user', $id); - $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) ); $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) ); + $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) ); $user = new WP_User($id); diff --git a/wp-includes/post.php b/wp-includes/post.php index 15526bcf7f..8cc0d7b341 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1159,15 +1159,17 @@ function wp_delete_post($postid = 0) { foreach ( $revision_ids as $revision_id ) wp_delete_post_revision( $revision_id ); + do_action('deleted_post', $postid); + // Point all attachments to this post up one level $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) ); - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid )); - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d", $postid )); + $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid )); + if ( 'page' == $post->post_type ) { clean_page_cache($postid); @@ -1179,8 +1181,6 @@ function wp_delete_post($postid = 0) { clean_post_cache($postid); } - do_action('deleted_post', $postid); - return $post; } @@ -2516,12 +2516,12 @@ function wp_delete_attachment($postid) { /** @todo Delete for pluggable post taxonomies too */ wp_delete_object_term_relationships($postid, array('category', 'post_tag')); - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid )); - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid )); $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid )); + $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid )); + $uploadPath = wp_upload_dir(); if ( ! empty($meta['thumb']) ) {