0

I am trying to migrade Drupal into WordPress, and I have a problem with users migration and post ownership.

More specific.

In my WordPress installation I have move my posts from Drupal. Among the transfered fields is the node ID too. So, now my posts in WordPress having the same IDs like in Drupal nodes table.

Also I have migrate my users, but my current problem is, how to assign the appropriate user to the corresponding post in WordPress.

For the migration I have follow this tutorial that in some place has this code:

# Reassign post authorship.
UPDATE 
    wordpress.wp_posts
SET 
    post_author = NULL
WHERE 
    post_author 
NOT IN
    (
        SELECT 
            DISTINCT ID 
        FROM 
            wordpress.wp_users
    );

Unfortunatelly this does not work for me, because I am getting this Warning:

64 warning(s): 1048 Column 'post_author' cannot be null

So, what I did, is to write the following Query to retrieve any required information:

SELECT 
    DISTINCT(n.nid) AS  `PostID`,
    n.uid           AS  `AuthorID`,
    wu.ID           AS  `WPUserID`
FROM 
    drupal.node n
LEFT JOIN
    drupal.users u
ON
    n.uid = u.uid
LEFT JOIN
    wp_users wu
ON
    wu.user_login = u.name
WHERE
    wu.ID   > 1

The above Query can return to me the post ID (that it is relevant to Drupal one), and the WordPress User ID, as the user in WordPress has a new ID.

So the question is, how can I mix this Query with the UPDATE query above, in order to set the appropriate user to the appropriate post ?

Just for help

This is the Drupal Users Table Signature:

CREATE TABLE `users` (
    `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(60) NOT NULL DEFAULT '''',
    `pass` varchar(32) NOT NULL DEFAULT '''',
    `mail` varchar(64) DEFAULT '''',
    `mode` tinyint(4) NOT NULL DEFAULT ''0'',
    `sort` tinyint(4) DEFAULT ''0'',
    `threshold` tinyint(4) DEFAULT ''0'',
    `theme` varchar(255) NOT NULL DEFAULT '''',
    `signature` varchar(255) NOT NULL DEFAULT '''',
    `signature_format` smallint(6) NOT NULL DEFAULT ''0'',
    `created` int(11) NOT NULL DEFAULT ''0'',
    `access` int(11) NOT NULL DEFAULT ''0'',
    `login` int(11) NOT NULL DEFAULT ''0'',
    `status` tinyint(4) NOT NULL DEFAULT ''0'',
    `timezone` varchar(8) DEFAULT NULL,
    `language` varchar(12) NOT NULL DEFAULT '''',
    `picture` varchar(255) NOT NULL DEFAULT '''',
    `init` varchar(64) DEFAULT '''',
    `data` longtext,
    `timezone_name` varchar(50) NOT NULL DEFAULT '''',
    PRIMARY KEY (`uid`),
    UNIQUE KEY `name` (`name`),
    KEY `access` (`access`),
    KEY `created` (`created`),
    KEY `mail` (`mail`)
) ENGINE=MyISAM AUTO_INCREMENT=397 DEFAULT CHARSET=utf8

This is the Drupal nodes table signature:

CREATE TABLE `node` (
    `nid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `vid` int(10) unsigned NOT NULL DEFAULT ''0'',
    `type` varchar(32) NOT NULL DEFAULT '''',
    `language` varchar(12) NOT NULL DEFAULT '''',
    `title` varchar(255) NOT NULL DEFAULT '''',
    `uid` int(11) NOT NULL DEFAULT ''0'',
    `status` int(11) NOT NULL DEFAULT ''1'',
    `created` int(11) NOT NULL DEFAULT ''0'',
    `changed` int(11) NOT NULL DEFAULT ''0'',
    `comment` int(11) NOT NULL DEFAULT ''0'',
    `promote` int(11) NOT NULL DEFAULT ''0'',
    `moderate` int(11) NOT NULL DEFAULT ''0'',
    `sticky` int(11) NOT NULL DEFAULT ''0'',
    `tnid` int(10) unsigned NOT NULL DEFAULT ''0'',
    `translate` int(11) NOT NULL DEFAULT ''0'',
    PRIMARY KEY (`nid`),
    UNIQUE KEY `vid` (`vid`),
    KEY `node_changed` (`changed`),
    KEY `node_created` (`created`),
    KEY `node_moderate` (`moderate`),
    KEY `node_promote_status` (`promote`,`status`),
    KEY `node_status_type` (`status`,`type`,`nid`),
    KEY `node_title_type` (`title`,`type`(4)),
    KEY `node_type` (`type`(4)),
    KEY `uid` (`uid`),
    KEY `tnid` (`tnid`),
    KEY `translate` (`translate`)
) ENGINE=MyISAM AUTO_INCREMENT=247 DEFAULT CHARSET=utf8

This is the WordPress wp_posts table signature:

CREATE TABLE `wp_posts` (
    `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `post_author` bigint(20) unsigned NOT NULL DEFAULT ''0'',
    `post_date` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',
    `post_date_gmt` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',
    `post_content` longtext NOT NULL,
    `post_title` text NOT NULL,
    `post_excerpt` text NOT NULL,
    `post_status` varchar(20) NOT NULL DEFAULT ''publish'',
    `comment_status` varchar(20) NOT NULL DEFAULT ''open'',
    `ping_status` varchar(20) NOT NULL DEFAULT ''open'',
    `post_password` varchar(20) NOT NULL DEFAULT '''',
    `post_name` varchar(200) NOT NULL DEFAULT '''',
    `to_ping` text NOT NULL,
    `pinged` text NOT NULL,
    `post_modified` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',
    `post_modified_gmt` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',
    `post_content_filtered` longtext NOT NULL,
    `post_parent` bigint(20) unsigned NOT NULL DEFAULT ''0'',
    `guid` varchar(255) NOT NULL DEFAULT '''',
    `menu_order` int(11) NOT NULL DEFAULT ''0'',
    `post_type` varchar(20) NOT NULL DEFAULT ''post'',
    `post_mime_type` varchar(100) NOT NULL DEFAULT '''',
    `comment_count` bigint(20) NOT NULL DEFAULT ''0'',
    PRIMARY KEY (`ID`),
    KEY `post_name` (`post_name`),
    KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
    KEY `post_parent` (`post_parent`),
    KEY `post_author` (`post_author`)
) ENGINE=InnoDB AUTO_INCREMENT=247 DEFAULT CHARSET=utf8

And finally this is the WordPress Users table signature:

CREATE TABLE `wp_users` (
    `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `user_login` varchar(60) NOT NULL DEFAULT '''',
    `user_pass` varchar(64) NOT NULL DEFAULT '''',
    `user_nicename` varchar(50) NOT NULL DEFAULT '''',
    `user_email` varchar(100) NOT NULL DEFAULT '''',
    `user_url` varchar(100) NOT NULL DEFAULT '''',
    `user_registered` datetime NOT NULL DEFAULT ''0000-00-00 00:00:00'',
    `user_activation_key` varchar(60) NOT NULL DEFAULT '''',
    `user_status` int(11) NOT NULL DEFAULT ''0'',
    `display_name` varchar(250) NOT NULL DEFAULT '''',
    PRIMARY KEY (`ID`),
    KEY `user_login_key` (`user_login`),
    KEY `user_nicename` (`user_nicename`)
) ENGINE=InnoDB AUTO_INCREMENT=652 DEFAULT CHARSET=utf8
4

1 回答 1

1

在您的更新查询连接wp_postsnode表中,并将该post_author字段设置为uid节点表中的

UPDATE `wp_posts`  p
INNER JOIN `node` n  (ON n.nid=p.ID)
SET p.post_author = n.uid

我猜n.uid您已将这些 id 与 id 中的wp_users相同

于 2013-11-14T17:54:17.713 回答