Advertisements

upgrade_110

Definition:
function upgrade_110() {}

Execute changes made in WordPress 1.2.

Source code

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*3600;

	$gmt_time = time();



	$diff_gmt_server = ($gmt_time - $server_time) / 3600;

	$diff_weblogger_server = ($weblogger_time - $server_time) / 3600;

	$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 substract 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)");

	}



}

3223

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: