Make WordPress Core


Ignore:
Timestamp:
02/03/2010 01:00:57 AM (17 years ago)
Author:
wpmuguru
Message:

fix potential global terms inconsistency, props rboren, see #11644

File:
1 edited

Legend:

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

    r12931 r12933  
    104104        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
    105105
    106         $wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
    107         $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '1', 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
     106        if ( is_multisite() ) {
     107                $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
     108                if ( $cat_id == null ) {
     109                        $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) );
     110                        $cat_id = $wpdb->insert_id;
     111                }
     112                update_option('default_category', $cat_id);
     113        } else {
     114                $cat_id = 1;
     115        }
     116
     117        $wpdb->insert( $wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
     118        $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
     119        $cat_tt_id = $wpdb->insert_id;
    108120
    109121        // Default link category
    … …  
    112124        $cat_slug = sanitize_title(_x('Blogroll', 'Default link category slug'));
    113125
    114         $wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
    115         $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '2', 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
     126        if ( is_multisite() ) {
     127                $blogroll_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
     128                if ( $blogroll_id == null ) {
     129                        $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) );
     130                        $blogroll_id = $wpdb->insert_id;
     131                }
     132                update_option('default_link_category', $blogroll_id);
     133        } else {
     134                $blogroll_id = 2;
     135        }
     136
     137        $wpdb->insert( $wpdb->terms, array('term_id' => $blogroll_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
     138        $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $blogroll_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
     139        $blogroll_tt_id = $wpdb->insert_id;
    116140
    117141        // Now drop in some default links
    … …  
    154178        foreach ( $default_links as $link ) {
    155179                $wpdb->insert( $wpdb->links, $link);
    156                 $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 2, 'object_id' => $wpdb->insert_id) );
     180                $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $blogroll_tt_id, 'object_id' => $wpdb->insert_id) );
    157181        }
    158182
    … …  
    191215                                                                'post_content_filtered' => ''
    192216                                                                ));
    193         $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 1, 'object_id' => 1) );
     217        $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
    194218
    195219        // Default comment
Note: See TracChangeset for help on using the changeset viewer.