From d8f42243a9e7e320587ee19aac6517ff2160af1b Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 24 May 2007 22:40:24 +0000 Subject: [PATCH] Category/tag to taxonomy upgrade. First cut. git-svn-id: https://develop.svn.wordpress.org/trunk@5539 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/upgrade-functions.php | 66 ++++++++++++++++++++++++++++++++-- wp-admin/upgrade-schema.php | 2 +- wp-includes/version.php | 2 +- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php index 9b2529b71d..7ff8e072e0 100644 --- a/wp-admin/upgrade-functions.php +++ b/wp-admin/upgrade-functions.php @@ -185,9 +185,9 @@ function upgrade_all() { if ( $wp_current_db_version < 4351 ) upgrade_old_slugs(); - if ( $wp_current_db_version < 5200 ) { + if ( $wp_current_db_version < 5539 ) upgrade_230(); - } + maybe_disable_automattic_widgets(); @@ -572,11 +572,71 @@ function upgrade_210() { } function upgrade_230() { - global $wp_current_db_version; + global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 5200 ) { populate_roles_230(); } + + // Convert categories to terms. + $tt_ids = array(); + $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories"); + foreach ($categories as $category) { + $term_id = (int) $category->cat_ID; + $name = $wpdb->escape($category->cat_name); + $description = $wpdb->escape($category->category_description); + $slug = $wpdb->escape($category->category_nicename); + $parent = $wpdb->escape($category->category_parent); + $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')"); + + if ( !empty($category->category_count) ) { + $count = (int) $category->category_count; + $taxonomy = 'category'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } else if ( !empty($category->link_count) ) { + $count = (int) $category->link_count; + $taxonomy = 'link_category'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } else if ( !empty($category->tag_count) ) { + $count = (int) $category->tag_count; + $taxonomy = 'post_tag'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } else { + $count = 0; + $taxonomy = 'category'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } + } + + $posts = $wpdb->get_results("SELECT * FROM $wpdb->post2cat"); + foreach ( $posts as $post ) { + $post_id = (int) $post->post_id; + $term_id = (int) $post->category_id; + $taxonomy = 'category'; + if ( !empty($post->rel_type) && 'tag' == $post->rel_type) + $taxonomy = 'tag'; + $tt_id = $tt_ids[$term_id][$taxonomy]; + if ( empty($tt_id) ) + continue; + + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post_id', '$tt_id')"); + } + + $links = $wpdb->get_results("SELECT * FROM $wpdb->link2cat"); + foreach ( $links as $link ) { + $link_id = (int) $link->link_id; + $term_id = (int) $link->category_id; + $taxonomy = 'link_category'; + $tt_id = $tt_ids[$term_id][$taxonomy]; + if ( empty($tt_id) ) + continue; + + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link_id', '$tt_id')"); + } } function upgrade_old_slugs() { diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php index 41dcf5ab10..c3c03a3b1d 100644 --- a/wp-admin/upgrade-schema.php +++ b/wp-admin/upgrade-schema.php @@ -26,7 +26,7 @@ CREATE TABLE $wpdb->term_taxonomy ( parent bigint(20) NOT NULL default 0, count bigint(20) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), - UNIQUE KEY (term_id, taxonomy) + UNIQUE KEY (term_id,taxonomy) ) $charset_collate; CREATE TABLE $wpdb->term_relationships ( object_id bigint(20) NOT NULL default 0, diff --git a/wp-includes/version.php b/wp-includes/version.php index 022728edbf..51e5d564ec 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -3,6 +3,6 @@ // This holds the version number in a separate file so we can bump it without cluttering the SVN $wp_version = '2.3-alpha'; -$wp_db_version = 5495; +$wp_db_version = 5539; ?>