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
This commit is contained in:
ryan 2009-03-31 19:16:53 +00:00
parent 533114e89f
commit f84839d5af
2 changed files with 7 additions and 7 deletions

View File

@ -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);

View File

@ -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']) ) {