WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/13/2014 08:04:02 PM (5 years ago)
Author:
boonebgorges
Message:

Don't split shared terms on term update.

Splitting shared terms means assigning a new term_id to a given term_taxonomy_id.
It was uncovered that this change could cause problems for sites that have
cached the original term_id somehow - say, in postmeta - since future lookups
using that term_id will now fail.

Removing for 4.1-beta1. We'll look at improvements to backward compatibility
to try to get this back into a later beta.

Props mboynes.
See #30335.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term.php

    r30241 r30336  
    691691    }
    692692
    693     /**
    694      * @ticket 5809
    695      */
    696     public function test_wp_update_term_should_split_shared_term() {
    697         global $wpdb;
    698 
    699         register_taxonomy( 'wptests_tax', 'post' );
    700         register_taxonomy( 'wptests_tax_2', 'post' );
    701 
    702         $t1 = wp_insert_term( 'Foo', 'wptests_tax' );
    703         $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' );
    704 
    705         // Manually modify because split terms shouldn't naturally occur.
    706         $wpdb->update( $wpdb->term_taxonomy,
    707             array( 'term_id' => $t1['term_id'] ),
    708             array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ),
    709             array( '%d' ),
    710             array( '%d' )
    711         );
    712 
    713         $posts = $this->factory->post->create_many( 2 );
    714         wp_set_object_terms( $posts[0], array( 'Foo' ), 'wptests_tax' );
    715         wp_set_object_terms( $posts[1], array( 'Foo' ), 'wptests_tax_2' );
    716 
    717         // Verify that the terms are shared.
    718         $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );
    719         $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );
    720         $this->assertSame( $t1_terms[0]->term_id, $t2_terms[0]->term_id );
    721 
    722         wp_update_term( $t2_terms[0]->term_id, 'wptests_tax_2', array(
    723             'name' => 'New Foo',
    724         ) );
    725 
    726         $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );
    727         $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );
    728         $this->assertNotEquals( $t1_terms[0]->term_id, $t2_terms[0]->term_id );
    729     }
    730 
    731     /**
    732      * @ticket 5809
    733      */
    734     public function test_wp_update_term_should_not_split_shared_term_before_410_schema_change() {
    735         global $wpdb;
    736 
    737         $db_version = get_option( 'db_version' );
    738         update_option( 'db_version', 30055 );
    739 
    740         register_taxonomy( 'wptests_tax', 'post' );
    741         register_taxonomy( 'wptests_tax_2', 'post' );
    742 
    743         $t1 = wp_insert_term( 'Foo', 'wptests_tax' );
    744         $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' );
    745 
    746         // Manually modify because split terms shouldn't naturally occur.
    747         $wpdb->update( $wpdb->term_taxonomy,
    748             array( 'term_id' => $t1['term_id'] ),
    749             array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ),
    750             array( '%d' ),
    751             array( '%d' )
    752         );
    753 
    754         $posts = $this->factory->post->create_many( 2 );
    755         wp_set_object_terms( $posts[0], array( 'Foo' ), 'wptests_tax' );
    756         wp_set_object_terms( $posts[1], array( 'Foo' ), 'wptests_tax_2' );
    757 
    758         // Verify that the term is shared.
    759         $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );
    760         $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );
    761         $this->assertSame( $t1_terms[0]->term_id, $t2_terms[0]->term_id );
    762 
    763         wp_update_term( $t2_terms[0]->term_id, 'wptests_tax_2', array(
    764             'name' => 'New Foo',
    765         ) );
    766 
    767         // Term should still be shared.
    768         $t1_terms = wp_get_object_terms( $posts[0], 'wptests_tax' );
    769         $t2_terms = wp_get_object_terms( $posts[1], 'wptests_tax_2' );
    770         $this->assertSame( $t1_terms[0]->term_id, $t2_terms[0]->term_id );
    771 
    772         update_option( 'db_version', $db_version );
    773     }
    774 
    775693    public function test_wp_update_term_alias_of_no_term_group() {
    776694        register_taxonomy( 'wptests_tax', 'post' );
Note: See TracChangeset for help on using the changeset viewer.