WordPress.org

Make WordPress Core

Changeset 5539


Ignore:
Timestamp:
05/24/07 22:40:24 (10 years ago)
Author:
ryan
Message:

Category/tag to taxonomy upgrade. First cut.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upgrade-functions.php

    r5432 r5539  
    186186        upgrade_old_slugs(); 
    187187     
    188     if ( $wp_current_db_version < 5200 ) { 
     188    if ( $wp_current_db_version < 5539 ) 
    189189        upgrade_230(); 
    190     } 
     190 
    191191     
    192192    maybe_disable_automattic_widgets(); 
     
    573573 
    574574function upgrade_230() { 
    575     global $wp_current_db_version; 
     575    global $wp_current_db_version, $wpdb; 
    576576     
    577577    if ( $wp_current_db_version < 5200 ) { 
    578578        populate_roles_230(); 
     579    } 
     580 
     581    // Convert categories to terms. 
     582    $tt_ids = array(); 
     583    $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories"); 
     584    foreach ($categories as $category) { 
     585        $term_id = (int) $category->cat_ID; 
     586        $name = $wpdb->escape($category->cat_name); 
     587        $description = $wpdb->escape($category->category_description); 
     588        $slug = $wpdb->escape($category->category_nicename); 
     589        $parent = $wpdb->escape($category->category_parent); 
     590        $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')"); 
     591 
     592        if ( !empty($category->category_count) ) { 
     593            $count = (int) $category->category_count; 
     594            $taxonomy = 'category'; 
     595            $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); 
     596            $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 
     597        } else if ( !empty($category->link_count) ) { 
     598            $count = (int) $category->link_count; 
     599            $taxonomy = 'link_category'; 
     600            $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); 
     601            $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 
     602        } else if ( !empty($category->tag_count) ) { 
     603            $count = (int) $category->tag_count; 
     604            $taxonomy = 'post_tag'; 
     605            $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); 
     606            $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 
     607        } else { 
     608            $count = 0; 
     609            $taxonomy = 'category'; 
     610            $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); 
     611            $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 
     612        } 
     613    } 
     614 
     615    $posts = $wpdb->get_results("SELECT * FROM $wpdb->post2cat"); 
     616    foreach ( $posts as $post ) { 
     617        $post_id = (int) $post->post_id; 
     618        $term_id = (int) $post->category_id; 
     619        $taxonomy = 'category'; 
     620        if ( !empty($post->rel_type) && 'tag' == $post->rel_type) 
     621            $taxonomy = 'tag'; 
     622        $tt_id = $tt_ids[$term_id][$taxonomy]; 
     623        if ( empty($tt_id) ) 
     624            continue; 
     625 
     626        $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post_id', '$tt_id')"); 
     627    } 
     628 
     629    $links = $wpdb->get_results("SELECT * FROM $wpdb->link2cat"); 
     630    foreach ( $links as $link ) { 
     631        $link_id = (int) $link->link_id; 
     632        $term_id = (int) $link->category_id; 
     633        $taxonomy = 'link_category'; 
     634        $tt_id = $tt_ids[$term_id][$taxonomy]; 
     635        if ( empty($tt_id) ) 
     636            continue; 
     637 
     638        $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link_id', '$tt_id')"); 
    579639    } 
    580640} 
  • trunk/wp-admin/upgrade-schema.php

    r5516 r5539  
    2727 count bigint(20) NOT NULL default 0, 
    2828 PRIMARY KEY (term_taxonomy_id), 
    29  UNIQUE KEY (term_id, taxonomy) 
     29 UNIQUE KEY (term_id,taxonomy) 
    3030) $charset_collate; 
    3131CREATE TABLE $wpdb->term_relationships ( 
  • trunk/wp-includes/version.php

    r5510 r5539  
    44 
    55$wp_version = '2.3-alpha'; 
    6 $wp_db_version = 5495; 
     6$wp_db_version = 5539; 
    77 
    88?> 
Note: See TracChangeset for help on using the changeset viewer.