Migrating Drupal To WordPress

drupal-to-wordpress

The following are my notes on a few sql queries used to convert the schema of a few Drupal tables to wordpress:

# Taxonomy Terms, only import ISG Drupal vocabulary
REPLACE INTO `wp3-isg`.wp_terms (term_id, `name`, slug, term_group)
SELECT
 d.tid, d.name, REPLACE(LOWER(d.name), ' ', '-'), 0
FROM `internal_drupal_5-2`.term_data d WHERE vid = '5'

# Tell WordPress to convert terms to tags
INSERT INTO `wp3-isg`.wp_term_taxonomy (term_taxonomy_id, term_id, taxonomy, description)
SELECT
 d.tid `term_taxonomy_id`,
 d.tid `term_id`,
 'post_tag' `taxonomy`,
 d.description `description`
FROM `internal_drupal_5-2`.term_data d WHERE vid = '5'
;

# Import POSTS
INSERT INTO
    `wp3-isg`.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 `internal_drupal_5-2`.node n, `internal_drupal_5-2`.node_revisions r
WHERE n.vid = r.vid AND n.type = 'isg'

# Associate the tags with wordpress posts
REPLACE INTO `wp3-isg`.wp_term_relationships (object_id, term_taxonomy_id)
SELECT  DISTINCT tn.nid, tn.tid 
FROM `internal_drupal_5-2`.term_node as tn, `internal_drupal_5-2`.term_data as td
WHERE td.vid= '5'

# Update Category Count
UPDATE wp_term_taxonomy tt
SET `count` = (
 SELECT COUNT(tr.object_id)
 FROM wp_term_relationships tr
 WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
);

# AUTHORS
INSERT IGNORE INTO `wp3-isg`.wp_users
    (ID, user_login, user_pass, user_nicename, user_email,
    user_registered, user_activation_key, user_status, display_name)
    SELECT DISTINCT
        u.uid, u.name, NULL, u.name, u.mail,
        FROM_UNIXTIME(created), '', 0, u.name
    FROM `internal_drupal_5-2`.users u
    INNER JOIN `internal_drupal_5-2`.users_roles r
        USING (uid)
    WHERE (r.rid = 6 and r.uid = u.uid
    )
;

Resources

http://socialcmsbuzz.com/convert-import-a-drupal-6-based-website-to-wordpress-v27-20052009/