web/wp-admin/includes/upgrade.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
   267 	if( ! is_blog_installed() )
   267 	if( ! is_blog_installed() )
   268 		return;
   268 		return;
   269 
   269 
   270 	wp_check_mysql_version();
   270 	wp_check_mysql_version();
   271 	wp_cache_flush();
   271 	wp_cache_flush();
       
   272 	pre_schema_upgrade();
   272 	make_db_current_silent();
   273 	make_db_current_silent();
   273 	upgrade_all();
   274 	upgrade_all();
   274 	wp_cache_flush();
   275 	wp_cache_flush();
   275 }
   276 }
   276 endif;
   277 endif;
   342 	if ( $wp_current_db_version < 8989 )
   343 	if ( $wp_current_db_version < 8989 )
   343 		upgrade_270();
   344 		upgrade_270();
   344 
   345 
   345 	if ( $wp_current_db_version < 10360 )
   346 	if ( $wp_current_db_version < 10360 )
   346 		upgrade_280();
   347 		upgrade_280();
       
   348 
       
   349 	if ( $wp_current_db_version < 11958 )
       
   350 		upgrade_290();
   347 
   351 
   348 	maybe_disable_automattic_widgets();
   352 	maybe_disable_automattic_widgets();
   349 
   353 
   350 	update_option( 'db_version', $wp_db_version );
   354 	update_option( 'db_version', $wp_db_version );
   351 	update_option( 'db_upgraded', true );
   355 	update_option( 'db_upgraded', true );
   552 	$options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
   556 	$options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
   553 	foreach ( $options as $option ) {
   557 	foreach ( $options as $option ) {
   554 		if ( 1 != $option->dupes ) { // Could this be done in the query?
   558 		if ( 1 != $option->dupes ) { // Could this be done in the query?
   555 			$limit = $option->dupes - 1;
   559 			$limit = $option->dupes - 1;
   556 			$dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );
   560 			$dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );
   557 			$dupe_ids = join($dupe_ids, ',');
   561 			if ( $dupe_ids ) {
   558 			$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
   562 				$dupe_ids = join($dupe_ids, ',');
       
   563 				$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
       
   564 			}
   559 		}
   565 		}
   560 	}
   566 	}
   561 
   567 
   562 	make_site_theme();
   568 	make_site_theme();
   563 }
   569 }
   976 function upgrade_280() {
   982 function upgrade_280() {
   977 	global $wp_current_db_version;
   983 	global $wp_current_db_version;
   978 
   984 
   979 	if ( $wp_current_db_version < 10360 )
   985 	if ( $wp_current_db_version < 10360 )
   980 		populate_roles_280();
   986 		populate_roles_280();
       
   987 }
       
   988 
       
   989 /**
       
   990  * Execute changes made in WordPress 2.9.
       
   991  *
       
   992  * @since 2.9.0
       
   993  */
       
   994 function upgrade_290() {
       
   995 	global $wp_current_db_version;
       
   996 
       
   997 	if ( $wp_current_db_version < 11958 ) {
       
   998 		// Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion
       
   999 		if ( get_option( 'thread_comments_depth' ) == '1' ) {
       
  1000 			update_option( 'thread_comments_depth', 2 );
       
  1001 			update_option( 'thread_comments', 0 );
       
  1002 		}
       
  1003 	}
   981 }
  1004 }
   982 
  1005 
   983 
  1006 
   984 // The functions we use to actually do stuff
  1007 // The functions we use to actually do stuff
   985 
  1008 
  1654 			break;
  1677 			break;
  1655 		}
  1678 		}
  1656 	}
  1679 	}
  1657 }
  1680 }
  1658 
  1681 
       
  1682 /**
       
  1683  * Runs before the schema is upgraded.
       
  1684  */
       
  1685 function pre_schema_upgrade() {
       
  1686 	global $wp_current_db_version, $wp_db_version, $wpdb;
       
  1687 
       
  1688 	// Upgrade versions prior to 2.9
       
  1689 	if ( $wp_current_db_version < 11557 ) {
       
  1690 		// Delete duplicate options.  Keep the option with the highest option_id.
       
  1691 		$wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
       
  1692 
       
  1693 		// Drop the old primary key and add the new.
       
  1694 		$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
       
  1695 
       
  1696 		// Drop the old option_name index. dbDelta() doesn't do the drop.
       
  1697 		$wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name");
       
  1698 	}
       
  1699 
       
  1700 }
       
  1701 
  1659 ?>
  1702 ?>