WordPress.org

Make WordPress Core

Ticket #30261: 30261.3.diff

File 30261.3.diff, 8.2 KB (added by boonebgorges, 4 years ago)
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index ff34c2a..9a634b8 100644
    function upgrade_all() { 
    534534        // Don't harsh my mellow. upgrade_430() must be called before
    535535        // upgrade_420() to catch bad comments prior to any auto-expansion of
    536536        // MySQL column widths.
    537         if ( $wp_current_db_version < 32364 )
     537        if ( $wp_current_db_version < 32713 )
    538538                upgrade_430();
    539539
    540540        if ( $wp_current_db_version < 31351 )
    function upgrade_430() { 
    15591559                        wp_delete_comment( $comment->comment_ID, true );
    15601560                }
    15611561        }
     1562
     1563        if ( $wp_current_db_version < 32713 ) {
     1564                split_all_shared_terms();
     1565        }
    15621566}
    15631567
    15641568/**
    function maybe_convert_table_to_utf8mb4( $table ) { 
    18511855}
    18521856
    18531857/**
     1858 * Split all shared taxonomy terms.
     1859 *
     1860 * @since 4.3.0
     1861 */
     1862function split_all_shared_terms() {
     1863        global $wpdb;
     1864
     1865        // Get a list of shared term IDs, and the term-taxonomy pairs that correspond to them.
     1866        $shared_terms = $wpdb->get_results(
     1867                "SELECT tt.term_id, t.*, count(*) as term_tt_count FROM {$wpdb->term_taxonomy} tt
     1868                        LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id
     1869                        GROUP BY t.term_id
     1870                        HAVING term_tt_count > 1"
     1871        );
     1872
     1873        // Rekey for faster lookups.
     1874        $_shared_terms = array();
     1875        foreach ( $shared_terms as $shared_term ) {
     1876                $term_id = intval( $shared_term->term_id );
     1877                $_shared_terms[ $term_id ] = $shared_term;
     1878        }
     1879        $shared_terms = $_shared_terms;
     1880
     1881        // Get term taxonomy data for all shared terms.
     1882        $shared_term_ids = implode( ',', array_keys( $shared_terms ) );
     1883        $shared_tts = $wpdb->get_results( "SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})" );
     1884
     1885        // Split term data recording is slow, so we do it just once, outside the loop.
     1886        $suspend = wp_suspend_cache_invalidation( true );
     1887        $split_term_data = get_option( '_split_terms', array() );
     1888        $skipped_first_term = $taxonomies = array();
     1889        foreach ( $shared_tts as $shared_tt ) {
     1890                $term_id = intval( $shared_tt->term_id );
     1891
     1892                // Don't split the first tt belonging to a given term_id.
     1893                if ( ! isset( $skipped_first_term[ $term_id ] ) ) {
     1894                        $skipped_first_term[ $term_id ] = 1;
     1895                        continue;
     1896                }
     1897
     1898                if ( ! isset( $split_term_data[ $term_id ] ) ) {
     1899                        $split_term_data[ $term_id ] = array();
     1900                }
     1901
     1902                // Keep track of taxonomies whose hierarchies need flushing.
     1903                if ( ! isset( $taxonomies[ $shared_tt->taxonomy ] ) ) {
     1904                        $taxonomies[ $shared_tt->taxonomy ] = 1;
     1905                }
     1906
     1907                $split_term_data[ $term_id ][ $shared_tt->taxonomy ] = _split_shared_term( $shared_terms[ $term_id ], $shared_tt, false );
     1908        }
     1909
     1910        // Rebuild the cached hierarchy for each affected taxonomy.
     1911        foreach ( array_keys( $taxonomies ) as $tax ) {
     1912                delete_option( "{$tax}_children" );
     1913                _get_term_hierarchy( $tax );
     1914        }
     1915
     1916        wp_suspend_cache_invalidation( $suspend );
     1917        update_option( '_split_terms', $split_term_data );
     1918}
     1919
     1920/**
    18541921 * Retrieve all options as it was for 1.2.
    18551922 *
    18561923 * @since 1.2.0
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index 70c465a..32291e9 100644
    function _update_generic_term_count( $terms, $taxonomy ) { 
    41914191 *
    41924192 * @global wpdb $wpdb
    41934193 *
    4194  * @param int  $term_id          ID of the shared term.
    4195  * @param int  $term_taxonomy_id ID of the term_taxonomy item to receive a new term.
     4194 * @param int|object $term_id          ID of the shared term, or the shared term object.
     4195 * @param int|object $term_taxonomy_id ID of the term_taxonomy item to receive a new term, or the term_taxonomy object
     4196 *                                     (corresponding to a row from the term_taxonomy table).
     4197 * @param bool       $record           Whether to record data about the split term in the options table. The recording
     4198 *                                     process has the potential to be resource-intensive, so during batch operations
     4199 *                                     it can be beneficial to skip inline recording and do it just once, after the
     4200 *                                     batch is processed. Only set this to `false` if you know what you are doing.
     4201 *                                     Default: true.
    41964202 * @return int|WP_Error When the current term does not need to be split (or cannot be split on the current
    41974203 *                      database schema), `$term_id` is returned. When the term is successfully split, the
    41984204 *                      new term_id is returned. A WP_Error is returned for miscellaneous errors.
    41994205 */
    4200 function _split_shared_term( $term_id, $term_taxonomy_id ) {
     4206function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) {
    42014207        global $wpdb;
    42024208
     4209        if ( is_object( $term_id ) ) {
     4210                $shared_term = $term_id;
     4211                $term_id = intval( $shared_term->term_id );
     4212        }
     4213
     4214        if ( is_object( $term_taxonomy_id ) ) {
     4215                $term_taxonomy = $term_taxonomy_id;
     4216                $term_taxonomy_id = intval( $term_taxonomy->term_taxonomy_id );
     4217        }
     4218
    42034219        // Don't try to split terms if database schema does not support shared slugs.
    42044220        $current_db_version = get_option( 'db_version' );
    42054221        if ( $current_db_version < 30133 ) {
    function _split_shared_term( $term_id, $term_taxonomy_id ) { 
    42084224
    42094225        // If there are no shared term_taxonomy rows, there's nothing to do here.
    42104226        $shared_tt_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy tt WHERE tt.term_id = %d AND tt.term_taxonomy_id != %d", $term_id, $term_taxonomy_id ) );
     4227
    42114228        if ( ! $shared_tt_count ) {
    42124229                return $term_id;
    42134230        }
    42144231
    42154232        // Pull up data about the currently shared slug, which we'll use to populate the new one.
    4216         $shared_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.* FROM $wpdb->terms t WHERE t.term_id = %d", $term_id ) );
     4233        if ( empty( $shared_term ) ) {
     4234                $shared_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.* FROM $wpdb->terms t WHERE t.term_id = %d", $term_id ) );
     4235        }
    42174236
    42184237        $new_term_data = array(
    42194238                'name' => $shared_term->name,
    function _split_shared_term( $term_id, $term_taxonomy_id ) { 
    42344253        );
    42354254
    42364255        // Reassign child terms to the new parent.
    4237         $term_taxonomy = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
    4238         $children_tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE taxonomy = %s AND parent = %d", $term_taxonomy->taxonomy, $term_id ) );
     4256        if ( empty( $term_taxonomy ) ) {
     4257                $term_taxonomy = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
     4258        }
    42394259
     4260        $children_tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = %s", $term_id, $term_taxonomy->taxonomy ) );
    42404261        if ( ! empty( $children_tt_ids ) ) {
    42414262                foreach ( $children_tt_ids as $child_tt_id ) {
    42424263                        $wpdb->update( $wpdb->term_taxonomy,
    42434264                                array( 'parent' => $new_term_id ),
    42444265                                array( 'term_taxonomy_id' => $child_tt_id )
    42454266                        );
     4267
    42464268                        clean_term_cache( $term_id, $term_taxonomy->taxonomy );
    42474269                }
    42484270        } else {
    function _split_shared_term( $term_id, $term_taxonomy_id ) { 
    42594281        }
    42604282
    42614283        // Keep a record of term_ids that have been split, keyed by old term_id. See {@see wp_get_split_term()}.
    4262         $split_term_data = get_option( '_split_terms', array() );
    4263         if ( ! isset( $split_term_data[ $term_id ] ) ) {
    4264                 $split_term_data[ $term_id ] = array();
    4265         }
    4266 
    4267         $split_term_data[ $term_id ][ $term_taxonomy->taxonomy ] = $new_term_id;
     4284        if ( $record ) {
     4285                $split_term_data = get_option( '_split_terms', array() );
     4286                if ( ! isset( $split_term_data[ $term_id ] ) ) {
     4287                        $split_term_data[ $term_id ] = array();
     4288                }
    42684289
    4269         update_option( '_split_terms', $split_term_data );
     4290                $split_term_data[ $term_id ][ $term_taxonomy->taxonomy ] = $new_term_id;
     4291                update_option( '_split_terms', $split_term_data );
     4292        }
    42704293
    42714294        /**
    42724295         * Fires after a previously shared taxonomy term is split into two separate terms.
  • src/wp-includes/version.php

    diff --git src/wp-includes/version.php src/wp-includes/version.php
    index ea523a6..c3b3e71 100644
    $wp_version = '4.3-alpha-32280-src'; 
    1111 *
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 32453;
     14$wp_db_version = 32713;
    1515
    1616/**
    1717 * Holds the TinyMCE version