Changeset 4495 for trunk/wp-admin/upgrade-functions.php
- Timestamp:
- 11/19/2006 07:56:05 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/upgrade-functions.php
r4366 r4495 121 121 "), $blog_url, $name, $password); 122 122 123 @wp_mail($email, __('New WordPress Blog'), $message, $message_headers); 123 @wp_mail($email, __('New WordPress Blog'), $message, $message_headers); 124 124 } 125 125 endif; … … 138 138 make_db_current_silent(); 139 139 upgrade_all(); 140 wp_cache_flush(); 140 wp_cache_flush(); 141 141 } 142 142 endif; … … 188 188 if ($posts) { 189 189 foreach($posts as $post) { 190 if ('' == $post->post_name) { 190 if ('' == $post->post_name) { 191 191 $newtitle = sanitize_title($post->post_title); 192 192 $wpdb->query("UPDATE $wpdb->posts SET post_name = '$newtitle' WHERE ID = '$post->ID'"); … … 197 197 $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories"); 198 198 foreach ($categories as $category) { 199 if ('' == $category->category_nicename) { 199 if ('' == $category->category_nicename) { 200 200 $newtitle = sanitize_title($category->cat_name); 201 201 $wpdb->query("UPDATE $wpdb->categories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'"); … … 252 252 global $wpdb; 253 253 254 254 // Set user_nicename. 255 255 $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users"); 256 257 if ('' == $user->user_nicename) { 258 259 260 261 256 foreach ($users as $user) { 257 if ('' == $user->user_nicename) { 258 $newname = sanitize_title($user->user_nickname); 259 $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'"); 260 } 261 } 262 262 263 263 $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users"); 264 264 foreach ($users as $row) { 265 265 if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) { 266 266 $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\''); 267 267 } 268 268 } … … 306 306 307 307 function upgrade_130() { 308 309 310 308 global $wpdb; 309 310 // Remove extraneous backslashes. 311 311 $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts"); 312 312 if ($posts) { 313 313 foreach($posts as $post) { 314 315 316 314 $post_content = addslashes(deslash($post->post_content)); 315 $post_title = addslashes(deslash($post->post_title)); 316 $post_excerpt = addslashes(deslash($post->post_excerpt)); 317 317 if ( empty($post->guid) ) 318 318 $guid = get_permalink($post->ID); … … 320 320 $guid = $post->guid; 321 321 322 323 } 324 } 325 326 322 $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt', guid = '$guid' WHERE ID = '$post->ID'"); 323 } 324 } 325 326 // Remove extraneous backslashes. 327 327 $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments"); 328 328 if ($comments) { 329 329 foreach($comments as $comment) { 330 331 332 333 } 334 } 335 336 330 $comment_content = addslashes(deslash($comment->comment_content)); 331 $comment_author = addslashes(deslash($comment->comment_author)); 332 $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'"); 333 } 334 } 335 336 // Remove extraneous backslashes. 337 337 $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links"); 338 338 if ($links) { 339 339 foreach($links as $link) { 340 341 342 343 } 344 } 345 346 347 348 349 350 351 352 353 354 355 356 357 358 340 $link_name = addslashes(deslash($link->link_name)); 341 $link_description = addslashes(deslash($link->link_description)); 342 $wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'"); 343 } 344 } 345 346 // The "paged" option for what_to_show is no more. 347 if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') { 348 $wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'"); 349 } 350 351 $active_plugins = __get_option('active_plugins'); 352 353 // If plugins are not stored in an array, they're stored in the old 354 // newline separated format. Convert to new format. 355 if ( !is_array( $active_plugins ) ) { 356 $active_plugins = explode("\n", trim($active_plugins)); 357 update_option('active_plugins', $active_plugins); 358 } 359 359 360 360 // Obsolete tables … … 500 500 $now = gmdate('Y-m-d H:i:59'); 501 501 $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'"); 502 502 503 503 $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'"); 504 504 if ( !empty($posts) ) … … 509 509 // Create categories for link categories if a category with the same 510 510 // name doesn't exist. Create a map of link cat IDs to cat IDs. 511 $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories"); 511 $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories"); 512 512 foreach ( $link_cats as $link_cat) { 513 513 if ( $cat_id = category_exists($link_cat->cat_name) ) { … … 528 528 $wpdb->query("INSERT INTO $wpdb->link2cat (link_id, category_id) 529 529 VALUES ('$link->link_id', '$link_cat')"); 530 } 531 } 532 530 } 531 } 532 533 533 // Set default to the last category we grabbed during the upgrade loop. 534 534 update_option('default_link_category', $default_link_cat); … … 549 549 // General 550 550 function maybe_create_table($table_name, $create_ddl) { 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 551 global $wpdb; 552 foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { 553 if ($table == $table_name) { 554 return true; 555 } 556 } 557 //didn't find it try to create it. 558 $q = $wpdb->query($create_ddl); 559 // we cannot directly tell that whether this succeeded! 560 foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { 561 if ($table == $table_name) { 562 return true; 563 } 564 } 565 return false; 566 566 } 567 567 … … 592 592 */ 593 593 function maybe_add_column($table_name, $column_name, $create_ddl) { 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 594 global $wpdb, $debug; 595 foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { 596 if ($debug) echo("checking $column == $column_name<br />"); 597 if ($column == $column_name) { 598 return true; 599 } 600 } 601 //didn't find it try to create it. 602 $q = $wpdb->query($create_ddl); 603 // we cannot directly tell that whether this succeeded! 604 foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { 605 if ($column == $column_name) { 606 return true; 607 } 608 } 609 return false; 610 610 } 611 611 … … 616 616 if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) { 617 617 foreach ($options as $option) { 618 // "When trying to design a foolproof system, 618 // "When trying to design a foolproof system, 619 619 // never underestimate the ingenuity of the fools :)" -- Dougal 620 620 if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); … … 647 647 648 648 function deslash($content) { 649 650 651 652 653 654 655 656 657 658 659 660 661 662 649 // Note: \\\ inside a regex denotes a single backslash. 650 651 // Replace one or more backslashes followed by a single quote with 652 // a single quote. 653 $content = preg_replace("/\\\+'/", "'", $content); 654 655 // Replace one or more backslashes followed by a double quote with 656 // a double quote. 657 $content = preg_replace('/\\\+"/', '"', $content); 658 659 // Replace one or more backslashes with one backslash. 660 $content = preg_replace("/\\\+/", "\\", $content); 661 662 return $content; 663 663 } 664 664 … … 827 827 } 828 828 } 829 // Add the column list to the index create string 829 // Add the column list to the index create string 830 830 $index_string .= ' ('.$index_columns.')'; 831 831
Note: See TracChangeset
for help on using the changeset viewer.