From 5939e76b0b20bf32235683c1f8d8b8253e4acb07 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 27 Oct 2005 22:04:12 +0000 Subject: [PATCH] DB versioning. fixes #1791 git-svn-id: http://svn.automattic.com/wordpress/trunk@2966 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/install.php | 2 +- wp-admin/upgrade-functions.php | 56 +++++++++++++++++++++++++--------- wp-admin/upgrade-schema.php | 6 ++-- wp-includes/version.php | 1 + 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/wp-admin/install.php b/wp-admin/install.php index 814803d9ff..dd7380e8f6 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -138,6 +138,7 @@ flush(); // Set everything up make_db_current_silent(); populate_options(); +populate_roles(); $wpdb->query("UPDATE $wpdb->options SET option_value = '$weblog_title' WHERE option_name = 'blogname'"); $wpdb->query("UPDATE $wpdb->options SET option_value = '$admin_email' WHERE option_name = 'admin_email'"); @@ -196,7 +197,6 @@ http://wordpress.org/ @wp_mail($admin_email, __('New WordPress Blog'), $message, $message_headers); -upgrade_all(); ?>

diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php index 238819317f..3ad6d9bbca 100644 --- a/wp-admin/upgrade-functions.php +++ b/wp-admin/upgrade-functions.php @@ -4,13 +4,38 @@ require_once(ABSPATH . '/wp-admin/admin-functions.php'); require_once(ABSPATH . '/wp-admin/upgrade-schema.php'); // Functions to be called in install and upgrade scripts function upgrade_all() { + global $wp_current_db_version, $wp_db_version; + $wp_current_db_version = __get_option('db_version'); + + // We are up-to-date. Nothing to do. + if ( $wp_db_version == $wp_current_db_version ) + return; + + // If the version is not set in the DB, try to guess the version. + if ( empty($wp_current_db_version) ) { + $wp_current_db_version = 0; + + // If the template option exists, we have 1.5. + $template = __get_option('template'); + if ( !empty($template) ) + $wp_current_db_version = 2541; + } + populate_options(); - upgrade_100(); - upgrade_101(); - upgrade_110(); - upgrade_130(); - upgrade_160(); + + if ( $wp_current_db_version < 2541 ) { + upgrade_100(); + upgrade_101(); + upgrade_110(); + upgrade_130(); + } + + if ( $wp_current_db_version < 2966 ) + upgrade_160(); + save_mod_rewrite_rules(); + + update_option('db_version', $wp_db_version); } function upgrade_100() { @@ -82,18 +107,16 @@ function upgrade_101() { function upgrade_110() { - global $wpdb; + global $wpdb; // Set user_nicename. - // FIXME: user_nickname is no longer in the user table. Need to update and - // move this code to where the new usermeta table is setup. -// $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users"); -// foreach ($users as $user) { -// if ('' == $user->user_nicename) { -// $newname = sanitize_title($user->user_nickname); -// $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'"); -// } -// } + $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users"); + foreach ($users as $user) { + if ('' == $user->user_nicename) { + $newname = sanitize_title($user->user_nickname); + $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'"); + } + } $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users"); foreach ($users as $row) { @@ -218,6 +241,9 @@ function upgrade_130() { function upgrade_160() { global $wpdb, $table_prefix; + + populate_roles_160(); + $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); foreach ( $users as $user ) : if ( !empty( $user->user_firstname ) ) diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php index a6df3d5b82..630100b9a7 100644 --- a/wp-admin/upgrade-schema.php +++ b/wp-admin/upgrade-schema.php @@ -222,8 +222,6 @@ function populate_options() { add_option('default_role', 'inactive'); add_option('rich_editing', 'true'); - populate_roles(); - // Delete unused options $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog'); foreach ($unusedoptions as $option) : @@ -238,6 +236,10 @@ function populate_options() { } function populate_roles() { + populate_roles_160(); +} + +function populate_roles_160() { global $wp_roles; // Add roles diff --git a/wp-includes/version.php b/wp-includes/version.php index 1c31ee7d37..01ac776764 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -3,5 +3,6 @@ // This just holds the version number, in a separate file so we can bump it without cluttering the SVN $wp_version = '1.6-ALPHA-2-still-dont-use'; +$wp_db_version = 2966; ?> \ No newline at end of file