<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12652] trunk: Use update and insert.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12652">12652</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-01-07 20:13:54 +0000 (Thu, 07 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use update and insert. Props DD32. fixes <a href="http://trac.wordpress.org/ticket/6836">#6836</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminimportwordpressphp">trunk/wp-admin/import/wordpress.php</a></li>
<li><a href="#trunkwpadminimportwpcat2tagphp">trunk/wp-admin/import/wp-cat2tag.php</a></li>
<li><a href="#trunkwpadminincludesbookmarkphp">trunk/wp-admin/includes/bookmark.php</a></li>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
<li><a href="#trunkwpadminincludesuserphp">trunk/wp-admin/includes/user.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminimportwordpressphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/wordpress.php (12651 => 12652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/wordpress.php        2010-01-07 19:55:48 UTC (rev 12651)
+++ trunk/wp-admin/import/wordpress.php        2010-01-07 20:13:54 UTC (rev 12652)
</span><span class="lines">@@ -747,7 +747,7 @@
</span><span class="cx">                         $local_child_id = $this->post_ids_processed[$child_id];
</span><span class="cx">                         $local_parent_id = $this->post_ids_processed[$parent_id];
</span><span class="cx">                         if ($local_child_id and $local_parent_id) {
</span><del>-                                $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", $local_parent_id, $local_child_id));
</del><ins>+                                $wpdb->update($wpdb->posts, array('post_parent' => $local_parent_id), array('ID' => $local_child_id) );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpadminimportwpcat2tagphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/wp-cat2tag.php (12651 => 12652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/wp-cat2tag.php        2010-01-07 19:55:48 UTC (rev 12651)
+++ trunk/wp-admin/import/wp-cat2tag.php        2010-01-07 20:13:54 UTC (rev 12652)
</span><span class="lines">@@ -272,7 +272,7 @@
</span><span class="cx">                                         if ( $values ) {
</span><span class="cx">                                                 $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)");
</span><span class="cx">
</span><del>-                                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $category->count, $category->term_id) );
</del><ins>+                                                $wpdb->update($wpdb->term_taxonomy, array('count' => $category->count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') );
</ins><span class="cx">                                         }
</span><span class="cx">
</span><span class="cx">                                         echo __('Converted successfully.') . "</li>\n";
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx">                                                 $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)");
</span><span class="cx">
</span><span class="cx">                                                 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag_ttid) );
</span><del>-                                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $count, $category->term_id) );
</del><ins>+                                                $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') );
</ins><span class="cx">                                         }
</span><span class="cx">                                         echo __('Tag added to all posts in this category.') . " *</li>\n";
</span><span class="cx">
</span><span class="lines">@@ -311,10 +311,10 @@
</span><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 // Change the category to a tag.
</span><del>-                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) );
</del><ins>+                                $wpdb->update($wpdb->term_taxonomy, array('taxonomy' => 'post_tag'), array('term_id' => $category->term_id, 'taxonomy' => 'category') );
</ins><span class="cx">
</span><span class="cx">                                 // Set all parents to 0 (root-level) if their parent was the converted tag
</span><del>-                                $parents = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) );
</del><ins>+                                $wpdb->update($wpdb->term_taxonomy, array('parent' => 0), array('parent' => $category->term_id, 'taxonomy' => 'category') );
</ins><span class="cx">
</span><span class="cx">                                 if ( $parents ) $clear_parents = true;
</span><span class="cx">                                 $clean_cat_cache[] = $category->term_id;
</span><span class="lines">@@ -379,7 +379,7 @@
</span><span class="cx">
</span><span class="cx">                                                 if ( $default_cat != $tag->term_id ) {
</span><span class="cx">                                                         $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag->term_id) );
</span><del>-                                                        $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'category'", $count, $tag->term_id) );
</del><ins>+                                                        $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $tag->term_id, 'taxonomy' => 'category') );
</ins><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="cx">
</span><span class="lines">@@ -394,12 +394,13 @@
</span><span class="cx">                                 // Change the tag to a category.
</span><span class="cx">                                 $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) );
</span><span class="cx">                                 if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) {
</span><del>-                                        $reset_parent = '';
</del><ins>+                                        $new_fields = array('taxonomy' => 'category');
</ins><span class="cx">                                         $clear_parents = true;
</span><del>-                                } else
-                                        $reset_parent = ", parent = '0'";
</del><ins>+                                } else {
+                                        $new_fields = array('taxonomy' => 'category', 'parent' => 0);
+                                }
</ins><span class="cx">
</span><del>-                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) );
</del><ins>+                                $wpdb->update($wpdb->term_taxonomy, $new_fields, array('term_id' => $tag->term_id, 'taxonomy' => 'post_tag') );
</ins><span class="cx">
</span><span class="cx">                                 $clean_term_cache[] = $tag->term_id;
</span><span class="cx">                                 $clean_cat_cache[] = $cat['term_id'];
</span></span></pre></div>
<a id="trunkwpadminincludesbookmarkphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/bookmark.php (12651 => 12652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/bookmark.php        2010-01-07 19:55:48 UTC (rev 12651)
+++ trunk/wp-admin/includes/bookmark.php        2010-01-07 20:13:54 UTC (rev 12652)
</span><span class="lines">@@ -186,19 +186,14 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ( $update ) {
</span><del>-                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 ) ) ) {
</del><ins>+                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') ) ) {
</ins><span class="cx">                         if ( $wp_error )
</span><span class="cx">                                 return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
</span><span class="cx">                         else
</span><span class="cx">                                 return 0;
</span><span class="cx">                 }
</span><span class="cx">         } else {
</span><del>-                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 ) ) ) {
</del><ins>+                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') ) ) {
</ins><span class="cx">                         if ( $wp_error )
</span><span class="cx">                                 return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
</span><span class="cx">                         else
</span></span></pre></div>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (12651 => 12652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2010-01-07 19:55:48 UTC (rev 12651)
+++ trunk/wp-admin/includes/template.php        2010-01-07 20:13:54 UTC (rev 12652)
</span><span class="lines">@@ -1776,7 +1776,7 @@
</span><span class="cx">                         // catch and repair bad pages
</span><span class="cx">                         if ( $page->post_parent == $page->ID ) {
</span><span class="cx">                                 $page->post_parent = 0;
</span><del>-                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
</del><ins>+                                $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));
</ins><span class="cx">                                 clean_page_cache( $page->ID );
</span><span class="cx">                         }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/user.php (12651 => 12652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/user.php        2010-01-07 19:55:48 UTC (rev 12651)
+++ trunk/wp-admin/includes/user.php        2010-01-07 20:13:54 UTC (rev 12652)
</span><span class="lines">@@ -435,8 +435,8 @@
</span><span class="cx">
</span><span class="cx">         } else {
</span><span class="cx">                 $reassign = (int) $reassign;
</span><del>-                $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) );
</del><ins>+                $wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) );
+                $wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         // FINALLY, delete user
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (12651 => 12652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-01-07 19:55:48 UTC (rev 12651)
+++ trunk/wp-includes/post.php        2010-01-07 20:13:54 UTC (rev 12652)
</span><span class="lines">@@ -3787,7 +3787,7 @@
</span><span class="cx">         // all revisions and (possibly) one autosave
</span><span class="cx">         $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
</span><span class="cx">
</span><del>-        // WP_POST_REVISIONS = (int) (# of autasaves to save)
</del><ins>+        // WP_POST_REVISIONS = (int) (# of autosaves to save)
</ins><span class="cx">         $delete = count($revisions) - WP_POST_REVISIONS;
</span><span class="cx">
</span><span class="cx">         if ( $delete < 1 )
</span></span></pre>
</div>
</div>
</body>
</html>