Make WordPress Core

Changeset 5552


Ignore:
Timestamp:
05/26/2007 05:47:20 PM (17 years ago)
Author:
ryan
Message:

During upgrade, make slugs unique and put like slugs in a term group. see #4189

Location:
trunk
Files:
2 edited

Legend:

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

    r5542 r5552  
    579579    // Convert categories to terms.
    580580    $tt_ids = array();
    581     $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories");
     581    $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID");
    582582    foreach ($categories as $category) {
    583583        $term_id = (int) $category->cat_ID;
     
    586586        $slug = $wpdb->escape($category->category_nicename);
    587587        $parent = $wpdb->escape($category->category_parent);
     588        $term_group = 0;
     589
     590        // Associate terms with the same slug in a term group and make slugs unique.
     591        if ( $exists = $wpdb->get_results("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) {
     592            $num = count($exists);
     593            $num++;
     594            $slug = $slug . "-$num";
     595            $term_group = $exists[0]->term_group;
     596            $id = $exists[0]->term_id;
     597            if ( empty( $term_group ) ) {
     598                $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1;
     599                $wpdb->query("UPDATE $wpdb->terms SET term_group = '$term_group' WHERE term_id = '$id'");
     600            }
     601        }
     602
    588603        $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')");
    589604
  • trunk/wp-includes/taxonomy.php

    r5533 r5552  
    6868        } else {
    6969            // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
    70             $term_group = $wpdb->get_var("SELECT MAX() term_group FROM $wpdb->terms GROUP BY term_group") + 1;
     70            $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1;
    7171            $wpdb->query("UPDATE $wpdb->terms SET term_group = $term_group WHERE term_id = $alias->term_id");
    7272        }
Note: See TracChangeset for help on using the changeset viewer.