A WordPress-centric search engine for devs and theme authors



upgrade_110 ›

Since1.2.0
Deprecatedn/a
upgrade_110 ( No parameters )
Defined at:
Codex:

Execute changes made in WordPress 1.2.



Source

function upgrade_110() {
	global $wpdb;

	// Set user_nicename.
	$users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
	foreach ( $users as $user ) {
		if ( '' == $user->user_nicename ) {
			$newname = sanitize_title( $user->user_nickname );
			$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
		}
	}

	$users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
	foreach ( $users as $row ) {
		if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
			$wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );
		}
	}

	// Get the GMT offset, we'll use that later on
	$all_options = get_alloptions_110();

	$time_difference = $all_options->time_difference;

		$server_time = time() + date( 'Z' );
	$weblogger_time  = $server_time + $time_difference * HOUR_IN_SECONDS;
	$gmt_time        = time();

	$diff_gmt_server       = ( $gmt_time - $server_time ) / HOUR_IN_SECONDS;
	$diff_weblogger_server = ( $weblogger_time - $server_time ) / HOUR_IN_SECONDS;
	$diff_gmt_weblogger    = $diff_gmt_server - $diff_weblogger_server;
	$gmt_offset            = -$diff_gmt_weblogger;

	// Add a gmt_offset option, with value $gmt_offset
	add_option( 'gmt_offset', $gmt_offset );

	// Check if we already set the GMT fields (if we did, then
	// MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
	// <michel_v> I just slapped myself silly for not thinking about it earlier
	$got_gmt_fields = ! ( $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) == '0000-00-00 00:00:00' );

	if ( ! $got_gmt_fields ) {

		// Add or subtract time to all dates, to get GMT dates
		$add_hours   = intval( $diff_gmt_weblogger );
		$add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) );
		$wpdb->query( "UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
		$wpdb->query( "UPDATE $wpdb->posts SET post_modified = post_date" );
		$wpdb->query( "UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'" );
		$wpdb->query( "UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
		$wpdb->query( "UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)" );
	}

}