My new project: Tact, a simple chat app.

Migrating a blog from pMachine to Wordpress 2

March 20, 2006

I just helped someone to migrate from pMachine to Wordpress 2. Now there’s this page available that walks and talks you through it and links to a script that supposedly does the conversion.

The conversion seemed to go kinda fine, but the grievance was that the permissions weren’t working after the conversion. Enter the webSWAT team again. Let’s try to dig into this. (I’ve never seen pMachine code. But I did install Wordpress 2 to check stuff out.)

The conversion script is kinda usual code. But these lines are really the problem.


// Importing members
echo "# Importing members... \n\n";
$pm_members = $pmdb->get_results('SELECT * FROM '.PM_MEMBERS);
$wpdb->query("UPDATE $tableusers SET ID=0 WHERE user_login='admin'");
foreach($pm_members as $member) {
  $query = "INSERT INTO $tableusers (ID, user_login, user_pass, user_nickname, user_icq, user_email, user_url, user_aim, user_msn, user_yim, user_idmode, user_ip, dateYMDhour, user_description, user_level, user_status, user_nicename) VALUES ($member->id, '$member->username', '$member->password', '$member->signature', '$member->icq', '".str_replace('_at_', '@', $member->email)."', '$member->url', '$member->aol_im', '$member->msn_im', '$member->yahoo_im', 'nickname', '$member->ipaddress', '".gmdate('Y-m-d H:i:s', $member->joindate)."', '$member->bio', '0', '0', '".sanitize_title_with_dashes($member->username)."')";
// echo $query;
$wpdb->query($query);
}

First off, it messes up the admin user badly, ripping it off any permissions. In WP2, there are separate tables wp_users and wp_usermeta. Permissions are in the latter. And just by changing an ID in the wp_users, you’re obviously ridding admin of its privileges and special attributes.

Secondly, the import just doesn’t work :) in WP2, the wp_users columns are different (fewer). There are none of thuse user_msn or user_yim columns so this just fails with WP2.

The solution is just not to do the user import (comment this part of the script out) and fix the post associations later in the backend. Or, if you have posts and comments by multiple authors, then fix the insert (just nuke the nonexisting columns).