Archive for April, 2009

Drupal to Wordpress

Sunday, April 12th, 2009

490篇文章,不到1000个会员,加上cache 的话,drupal数据库竟然16M之大,再加上的确玩不转Drupal,在转移服务器的时间,把drupal转移到了wp,现在wp数据的数据库只有1.6M,很小巧,很完美。

网上只有转移到wp2.3以下的方法,记录下步骤:
1、备份drupal数据至本地;
2、安装全新的wp(2.3版本一下);

3、在wp数据库中运行如下代码(wordpress和drupal分别为数据库名字,请自行修改):

use wordpress;
delete from wp_categories;
delete from wp_posts;
delete from wp_post2cat;
delete from wp_comments;

# categories
INSERT INTO
wp_categories (cat_ID, cat_name, category_nicename, category_description, category_parent)
SELECT term_data.tid, name, name, description, parent
FROM drupal.term_data, drupal.term_hierarchy
WHERE term_data.tid=term_hierarchy.tid;

# posts
INSERT INTO
wp_posts (id, post_date, post_content, post_title,
post_excerpt, post_name, post_modified)
SELECT DISTINCT
n.nid, FROM_UNIXTIME(created), body, n.title,
teaser,
REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.title),’ ‘, ‘_’),’.', ‘_’),’,', ‘_’),’+', ‘_’),
FROM_UNIXTIME(changed)
FROM drupal.node n, drupal.node_revisions r
WHERE n.vid = r.vid;

# category –> post relationships
INSERT INTO wp_post2cat (post_id,category_id) SELECT nid,tid FROM drupal.term_node ;

# category count updating
UPDATE `wp_categories` SET `category_count` = (SELECT COUNT(`post_id`) FROM `wp_post2cat` WHERE `wp_categories`.`cat_ID` = `wp_post2cat`.`category_id`);

# comments
INSERT INTO
wp_comments
(comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url)
SELECT
nid, FROM_UNIXTIME(timestamp),
comment, thread, name, mail, homepage
FROM drupal.comments ;

# update comments count on wp_posts table
UPDATE `wp_posts` SET `comment_count` = (SELECT COUNT(`comment_post_id`) FROM `wp_comments` WHERE `wp_posts`.`id` = `wp_comments`.`comment_post_id`);

# fix post slugs. first we have to remove the duplicate _____ chars, then replace that with a single – char
UPDATE wp_posts set post_name = REPLACE(post_name, ‘__’, ‘_’);
UPDATE wp_posts set post_name = REPLACE(post_name, ‘__’, ‘_’);
UPDATE wp_posts set post_name = REPLACE(post_name, ‘__’, ‘_’);
UPDATE wp_posts set post_name = REPLACE(post_name, ‘__’, ‘_’);
UPDATE wp_posts set post_name = REPLACE(post_name, ‘_’, ‘-’);

4、升级wp 至最新版本

利用以上方法成功将IDSOO从drupal6.6转到wordpress2.71,分类、评论均可转移,会员尚未成功转移。