Make WordPress Core

Ticket #5034: 5034.2.diff

File 5034.2.diff, 3.3 KB (added by wonderboymusic, 11 years ago)
  • wp-admin/includes/upgrade.php

    diff --git wp-admin/includes/upgrade.php wp-admin/includes/upgrade.php
    index 0d17d8f..78610be 100644
    function upgrade_all() { 
    404404
    405405        maybe_disable_link_manager();
    406406
     407        maybe_wp_tt_primary_key_parent();
     408
    407409        maybe_disable_automattic_widgets();
    408410
    409411        update_option( 'db_version', $wp_db_version );
    function maybe_disable_link_manager() { 
    19591961}
    19601962
    19611963/**
     1964 * Alter UNIQUE KEY for wp_term_taxonomy to include parent
     1965 *
     1966 * @since 3.7.0
     1967 */
     1968function maybe_wp_tt_primary_key_parent() {
     1969        global $wp_current_db_version, $wpdb;
     1970
     1971        $keys = $wpdb->get_results( "SHOW KEYS FROM $wpdb->term_taxonomy WHERE Key_name = 'term_id_taxonomy'" );
     1972
     1973        if ( $wp_current_db_version >= 22448 && count( $keys ) )
     1974                $wpdb->query("ALTER TABLE $wpdb->term_taxonomy DROP INDEX term_id_taxonomy, ADD UNIQUE INDEX term_id_taxonomy_parent (`term_id`, `taxonomy`, `parent`)");
     1975}
     1976
     1977/**
    19621978 * Runs before the schema is upgraded.
    19631979 *
    19641980 * @since 2.9.0
  • wp-includes/taxonomy.php

    diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
    index 955369e..21d7e22 100644
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    20872087        }
    20882088
    20892089        if ( $term_id = term_exists($slug) ) {
    2090                 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
     2090                $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A );
    20912091                // We've got an existing term in the same taxonomy, which matches the name of the new term:
    20922092                if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) {
    20932093                        // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level.
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    20952095                        if ( in_array($name, $siblings) ) {
    20962096                                return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']);
    20972097                        } else {
    2098                                 $slug = wp_unique_term_slug($slug, (object) $args);
    2099                                 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) )
    2100                                         return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);
    2101                                 $term_id = (int) $wpdb->insert_id;
     2098                                $term_id = (int) $existing_term['term_id'];
    21022099                        }
    21032100                } elseif ( $existing_term['name'] != $name ) {
    21042101                        // We've got an existing term, with a different name, Create the new term.
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    21262123                do_action( 'edited_terms', $term_id, $taxonomy );
    21272124        }
    21282125
    2129         $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) );
     2126        $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d AND tt.parent = %d", $taxonomy, $term_id, $parent ) );
    21302127
    21312128        if ( !empty($tt_id) )
    21322129                return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);