[wp-trac] [WordPress Trac] #30261: Split all existing shared taxonomy terms on WP upgrade

WordPress Trac noreply at wordpress.org
Thu Aug 13 09:59:56 UTC 2015


#30261: Split all existing shared taxonomy terms on WP upgrade
-------------------------------------+---------------------------
 Reporter:  boonebgorges             |       Owner:  boonebgorges
     Type:  enhancement              |      Status:  reopened
 Priority:  high                     |   Milestone:  4.3
Component:  Taxonomy                 |     Version:
 Severity:  blocker                  |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+---------------------------

Comment (by Chouby):

 Replying to [comment:43 boonebgorges]:
 > Chouby - I apologize - I'm rereading your comment, and looking more
 closely at Polylang, and I see that you are splitting terms yourself. I'm
 not sure that I understand the reasoning behind this ("I need to do this
 as a term can not be in several translations groups"). It seems to me that
 you could probably *not* do this splitting yourself, and let WordPress
 handle it during the migration.
 Let say that you have two shared terms A and B translations of each other.
 When splitting A, I get A and A1 which would be both translations of B,
 breaking the reciprocity relationship. B must have only one translation.
 Thus I split B too.

 > In any case,
 >
 > > For me that would work only if split_all_shared_terms() checks if the
 term has not been already splitted (in one of the hooks)
 >
 > This does happen - `split_all_shared_terms()` will not attempt to split
 a term that has already been split. This is determined by a SQL query that
 checks for shared terms, *not* by checking the '_split_terms' cached.
 The problem is that I split terms inside the loop. There is no second
 check in this function.
 >And even if it *did* try to split it, `_split_shared_term()` bails with
 the original `$term_id` if the term is not, in fact, shared (ie it's
 already been split).
 I guess that you are referring to this test:

 {{{
         $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 ) );


         if ( ! $shared_tt_count ) {
                 return $term_id;
         }
 }}}
 The problem is that the test never passes in this context as you always
 count the first term (the one not modified in the splitting process).

 In the end, the term is split two times resulting in a big mess in the db.

 >So I think that Polylang shouldn't have to do the
 `update_option__split_terms` trick.
 I would much prefer working with the `split_shared_term` hook (especially
 if the final choice is to go to batches). But I would need you to check if
 the term has not been already split inside the loop.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30261#comment:51>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list