Ticket #30261: 30261.3.diff
File 30261.3.diff, 8.2 KB (added by , 10 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() { 534 534 // Don't harsh my mellow. upgrade_430() must be called before 535 535 // upgrade_420() to catch bad comments prior to any auto-expansion of 536 536 // MySQL column widths. 537 if ( $wp_current_db_version < 32 364)537 if ( $wp_current_db_version < 32713 ) 538 538 upgrade_430(); 539 539 540 540 if ( $wp_current_db_version < 31351 ) … … function upgrade_430() { 1559 1559 wp_delete_comment( $comment->comment_ID, true ); 1560 1560 } 1561 1561 } 1562 1563 if ( $wp_current_db_version < 32713 ) { 1564 split_all_shared_terms(); 1565 } 1562 1566 } 1563 1567 1564 1568 /** … … function maybe_convert_table_to_utf8mb4( $table ) { 1851 1855 } 1852 1856 1853 1857 /** 1858 * Split all shared taxonomy terms. 1859 * 1860 * @since 4.3.0 1861 */ 1862 function 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 /** 1854 1921 * Retrieve all options as it was for 1.2. 1855 1922 * 1856 1923 * @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 ) { 4191 4191 * 4192 4192 * @global wpdb $wpdb 4193 4193 * 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. 4196 4202 * @return int|WP_Error When the current term does not need to be split (or cannot be split on the current 4197 4203 * database schema), `$term_id` is returned. When the term is successfully split, the 4198 4204 * new term_id is returned. A WP_Error is returned for miscellaneous errors. 4199 4205 */ 4200 function _split_shared_term( $term_id, $term_taxonomy_id ) {4206 function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { 4201 4207 global $wpdb; 4202 4208 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 4203 4219 // Don't try to split terms if database schema does not support shared slugs. 4204 4220 $current_db_version = get_option( 'db_version' ); 4205 4221 if ( $current_db_version < 30133 ) { … … function _split_shared_term( $term_id, $term_taxonomy_id ) { 4208 4224 4209 4225 // If there are no shared term_taxonomy rows, there's nothing to do here. 4210 4226 $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 4211 4228 if ( ! $shared_tt_count ) { 4212 4229 return $term_id; 4213 4230 } 4214 4231 4215 4232 // 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 } 4217 4236 4218 4237 $new_term_data = array( 4219 4238 'name' => $shared_term->name, … … function _split_shared_term( $term_id, $term_taxonomy_id ) { 4234 4253 ); 4235 4254 4236 4255 // 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 } 4239 4259 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 ) ); 4240 4261 if ( ! empty( $children_tt_ids ) ) { 4241 4262 foreach ( $children_tt_ids as $child_tt_id ) { 4242 4263 $wpdb->update( $wpdb->term_taxonomy, 4243 4264 array( 'parent' => $new_term_id ), 4244 4265 array( 'term_taxonomy_id' => $child_tt_id ) 4245 4266 ); 4267 4246 4268 clean_term_cache( $term_id, $term_taxonomy->taxonomy ); 4247 4269 } 4248 4270 } else { … … function _split_shared_term( $term_id, $term_taxonomy_id ) { 4259 4281 } 4260 4282 4261 4283 // 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 } 4268 4289 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 } 4270 4293 4271 4294 /** 4272 4295 * 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'; 11 11 * 12 12 * @global int $wp_db_version 13 13 */ 14 $wp_db_version = 32 453;14 $wp_db_version = 32713; 15 15 16 16 /** 17 17 * Holds the TinyMCE version