Advertisements

upgrade_160

Definition:
function upgrade_160() {}

Execute changes made in WordPress 2.0.

Source code

function upgrade_160() {

	global $wpdb, $wp_current_db_version;



	populate_roles_160();



	$users = $wpdb->get_results("SELECT * FROM $wpdb->users");

	foreach ( $users as $user ) :

		if ( !empty( $user->user_firstname ) )

			update_user_meta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );

		if ( !empty( $user->user_lastname ) )

			update_user_meta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );

		if ( !empty( $user->user_nickname ) )

			update_user_meta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );

		if ( !empty( $user->user_level ) )

			update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );

		if ( !empty( $user->user_icq ) )

			update_user_meta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );

		if ( !empty( $user->user_aim ) )

			update_user_meta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );

		if ( !empty( $user->user_msn ) )

			update_user_meta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );

		if ( !empty( $user->user_yim ) )

			update_user_meta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );

		if ( !empty( $user->user_description ) )

			update_user_meta( $user->ID, 'description', $wpdb->escape($user->user_description) );



		if ( isset( $user->user_idmode ) ):

			$idmode = $user->user_idmode;

			if ($idmode == 'nickname') $id = $user->user_nickname;

			if ($idmode == 'login') $id = $user->user_login;

			if ($idmode == 'firstname') $id = $user->user_firstname;

			if ($idmode == 'lastname') $id = $user->user_lastname;

			if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;

			if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;

			if (!$idmode) $id = $user->user_nickname;

			$wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) );

		endif;



		// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.

		$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities');

		if ( empty($caps) || defined('RESET_CAPS') ) {

			$level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true);

			$role = translate_level_to_role($level);

			update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );

		}



	endforeach;

	$old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );

	$wpdb->hide_errors();

	foreach ( $old_user_fields as $old )

		$wpdb->query("ALTER TABLE $wpdb->users DROP $old");

	$wpdb->show_errors();



	// populate comment_count field of posts table

	$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );

	if ( is_array( $comments ) )

		foreach ($comments as $comment)

			$wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) );



	// Some alpha versions used a post status of object instead of attachment and put

	// the mime type in post_type instead of post_mime_type.

	if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {

		$objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");

		foreach ($objects as $object) {

			$wpdb->update( $wpdb->posts, array(	'post_status' => 'attachment',

												'post_mime_type' => $object->post_type,

												'post_type' => ''),

										 array( 'ID' => $object->ID ) );



			$meta = get_post_meta($object->ID, 'imagedata', true);

			if ( ! empty($meta['file']) )

				update_attached_file( $object->ID, $meta['file'] );

		}

	}

}

3227

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: