WordPress.org

Make WordPress Core

Changeset 12652


Ignore:
Timestamp:
01/07/2010 08:13:54 PM (12 years ago)
Author:
ryan
Message:

Use update and insert. Props DD32. fixes #6836

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/wordpress.php

    r12515 r12652  
    748748            $local_parent_id = $this->post_ids_processed[$parent_id];
    749749            if ($local_child_id and $local_parent_id) {
    750                 $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", $local_parent_id, $local_child_id));
     750                $wpdb->update($wpdb->posts, array('post_parent' => $local_parent_id), array('ID' => $local_child_id) );
    751751            }
    752752        }
  • trunk/wp-admin/import/wp-cat2tag.php

    r12515 r12652  
    273273                        $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)");
    274274
    275                         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $category->count, $category->term_id) );
     275                        $wpdb->update($wpdb->term_taxonomy, array('count' => $category->count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') );
    276276                    }
    277277
     
    293293
    294294                        $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag_ttid) );
    295                         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $count, $category->term_id) );
     295                        $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') );
    296296                    }
    297297                    echo __('Tag added to all posts in this category.') . " *</li>\n";
     
    312312
    313313                // Change the category to a tag.
    314                 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) );
     314                $wpdb->update($wpdb->term_taxonomy, array('taxonomy' => 'post_tag'), array('term_id' => $category->term_id, 'taxonomy' => 'category') );
    315315
    316316                // Set all parents to 0 (root-level) if their parent was the converted tag
    317                 $parents = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) );
     317                $wpdb->update($wpdb->term_taxonomy, array('parent' => 0), array('parent' => $category->term_id, 'taxonomy' => 'category') );
    318318
    319319                if ( $parents ) $clear_parents = true;
     
    380380                        if ( $default_cat != $tag->term_id ) {
    381381                            $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag->term_id) );
    382                             $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'category'", $count, $tag->term_id) );
     382                            $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $tag->term_id, 'taxonomy' => 'category') );
    383383                        }
    384384                    }
     
    395395                $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) );
    396396                if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) {
    397                     $reset_parent = '';
     397                    $new_fields = array('taxonomy' => 'category');
    398398                    $clear_parents = true;
    399                 } else
    400                     $reset_parent = ", parent = '0'";
    401 
    402                 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) );
     399                } else {
     400                    $new_fields = array('taxonomy' => 'category', 'parent' => 0);
     401                }
     402
     403                $wpdb->update($wpdb->term_taxonomy, $new_fields, array('term_id' => $tag->term_id, 'taxonomy' => 'post_tag') );
    403404
    404405                $clean_term_cache[] = $tag->term_id;
  • trunk/wp-admin/includes/bookmark.php

    r12515 r12652  
    187187
    188188    if ( $update ) {
    189         if ( false === $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_url = %s,
    190             link_name = %s, link_image = %s, link_target = %s,
    191             link_visible = %s, link_description = %s, link_rating = %s,
    192             link_rel = %s, link_notes = %s, link_rss = %s
    193             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 ) ) ) {
     189        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') ) ) {
    194190            if ( $wp_error )
    195191                return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
     
    198194        }
    199195    } else {
    200         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)",
    201         $link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss ) ) ) {
     196        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') ) ) {
    202197            if ( $wp_error )
    203198                return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
  • trunk/wp-admin/includes/template.php

    r12616 r12652  
    17771777            if ( $page->post_parent == $page->ID ) {
    17781778                $page->post_parent = 0;
    1779                 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
     1779                $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));
    17801780                clean_page_cache( $page->ID );
    17811781            }
  • trunk/wp-admin/includes/user.php

    r12341 r12652  
    436436    } else {
    437437        $reassign = (int) $reassign;
    438         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $id) );
    439         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $id) );
     438        $wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) );
     439        $wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) );
    440440    }
    441441
  • trunk/wp-includes/post.php

    r12651 r12652  
    37883788    $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
    37893789
    3790     // WP_POST_REVISIONS = (int) (# of autasaves to save)
     3790    // WP_POST_REVISIONS = (int) (# of autosaves to save)
    37913791    $delete = count($revisions) - WP_POST_REVISIONS;
    37923792
Note: See TracChangeset for help on using the changeset viewer.