Use update and insert. Props DD32. fixes #6836

git-svn-id: http://svn.automattic.com/wordpress/trunk@12652 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-01-07 20:13:54 +00:00
parent 083064e628
commit 0d31c12db6
6 changed files with 17 additions and 21 deletions

View File

@ -747,7 +747,7 @@ class WP_Import {
$local_child_id = $this->post_ids_processed[$child_id];
$local_parent_id = $this->post_ids_processed[$parent_id];
if ($local_child_id and $local_parent_id) {
$wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", $local_parent_id, $local_child_id));
$wpdb->update($wpdb->posts, array('post_parent' => $local_parent_id), array('ID' => $local_child_id) );
}
}
}

View File

@ -272,7 +272,7 @@ function check_all_tagrows() {
if ( $values ) {
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $category->count, $category->term_id) );
$wpdb->update($wpdb->term_taxonomy, array('count' => $category->count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') );
}
echo __('Converted successfully.') . "</li>\n";
@ -292,7 +292,7 @@ function check_all_tagrows() {
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag_ttid) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $count, $category->term_id) );
$wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') );
}
echo __('Tag added to all posts in this category.') . " *</li>\n";
@ -311,10 +311,10 @@ function check_all_tagrows() {
}
// Change the category to a tag.
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) );
$wpdb->update($wpdb->term_taxonomy, array('taxonomy' => 'post_tag'), array('term_id' => $category->term_id, 'taxonomy' => 'category') );
// Set all parents to 0 (root-level) if their parent was the converted tag
$parents = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) );
$wpdb->update($wpdb->term_taxonomy, array('parent' => 0), array('parent' => $category->term_id, 'taxonomy' => 'category') );
if ( $parents ) $clear_parents = true;
$clean_cat_cache[] = $category->term_id;
@ -379,7 +379,7 @@ function check_all_tagrows() {
if ( $default_cat != $tag->term_id ) {
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag->term_id) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'category'", $count, $tag->term_id) );
$wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $tag->term_id, 'taxonomy' => 'category') );
}
}
@ -394,12 +394,13 @@ function check_all_tagrows() {
// Change the tag to a category.
$parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) );
if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) {
$reset_parent = '';
$new_fields = array('taxonomy' => 'category');
$clear_parents = true;
} else
$reset_parent = ", parent = '0'";
} else {
$new_fields = array('taxonomy' => 'category', 'parent' => 0);
}
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) );
$wpdb->update($wpdb->term_taxonomy, $new_fields, array('term_id' => $tag->term_id, 'taxonomy' => 'post_tag') );
$clean_term_cache[] = $tag->term_id;
$clean_cat_cache[] = $cat['term_id'];

View File

@ -186,19 +186,14 @@ function wp_insert_link( $linkdata, $wp_error = false ) {
}
if ( $update ) {
if ( false === $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_url = %s,
link_name = %s, link_image = %s, link_target = %s,
link_visible = %s, link_description = %s, link_rating = %s,
link_rel = %s, link_notes = %s, link_rss = %s
WHERE link_id = %s", $link_url, $link_name, $link_image, $link_target, $link_visible, $link_description, $link_rating, $link_rel, $link_notes, $link_rss, $link_id ) ) ) {
if ( ! $wpdb->update( $wpdb->links, compact('link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_rating', 'link_rel', 'link_notes', 'link_rss'), compact('link_id') ) ) {
if ( $wp_error )
return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
else
return 0;
}
} else {
if ( false === $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
$link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss ) ) ) {
if ( ! $wpdb->insert( $wpdb->links, compact('link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss') ) ) {
if ( $wp_error )
return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
else

View File

@ -1776,7 +1776,7 @@ function page_rows($pages, $pagenum = 1, $per_page = 20) {
// catch and repair bad pages
if ( $page->post_parent == $page->ID ) {
$page->post_parent = 0;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
$wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));
clean_page_cache( $page->ID );
}

View File

@ -435,8 +435,8 @@ function wp_delete_user($id, $reassign = 'novalue') {
} else {
$reassign = (int) $reassign;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $id) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $id) );
$wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) );
$wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) );
}
// FINALLY, delete user

View File

@ -3787,7 +3787,7 @@ function wp_save_post_revision( $post_id ) {
// all revisions and (possibly) one autosave
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
// WP_POST_REVISIONS = (int) (# of autasaves to save)
// WP_POST_REVISIONS = (int) (# of autosaves to save)
$delete = count($revisions) - WP_POST_REVISIONS;
if ( $delete < 1 )