Changeset 6268

Show
Ignore:
Timestamp:
10/17/07 21:09:02 (11 months ago)
Author:
ryan
Message:

Group results when selecting from post2cat and link2cat to avoid dupes. fixes #5223 for 2.3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.3/wp-admin/includes/upgrade.php

    r6158 r6268  
    534534    // Convert categories to terms. 
    535535    $tt_ids = array(); 
     536    $have_tags = false; 
    536537    $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID"); 
    537538    foreach ($categories as $category) { 
     
    580581 
    581582        if ( !empty($category->tag_count) ) { 
     583            $have_tags = true; 
    582584            $count = (int) $category->tag_count; 
    583585            $taxonomy = 'post_tag'; 
     
    594596    } 
    595597 
    596     $posts = $wpdb->get_results("SELECT * FROM $wpdb->post2cat"); 
     598    $select = 'post_id, category_id'; 
     599    if ( $have_tags ) 
     600        $select .= ', rel_type'; 
     601 
     602    $posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id"); 
    597603    foreach ( $posts as $post ) { 
    598604        $post_id = (int) $post->post_id; 
     
    659665        update_option('default_link_category', $default_link_cat); 
    660666    } else { 
    661         $links = $wpdb->get_results("SELECT * FROM $wpdb->link2cat"); 
     667        $links = $wpdb->get_results("SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id"); 
    662668        foreach ( $links as $link ) { 
    663669            $link_id = (int) $link->link_id; 
     
    10031009                        // Add the column list to the index create string 
    10041010                        $index_string .= ' ('.$index_columns.')'; 
    1005                         error_log("Index string: $index_string", 0); 
    10061011                        if(!(($aindex = array_search($index_string, $indices)) === false)) { 
    10071012                            unset($indices[$aindex]);