Wednesday, 24 April 2013

Website Content Migration from Drupal to Wordpress

WordPress is absolutely free and open source content management system (CMS) coded in PHP language. It is simple and easy to use open source technology based on PHP and MySQL framework. It has variety of features such as built in template library, plug in based architecture support. The plug in feature in the website gives superb feel to the bloggers with awesome features and functions. Wordpress provides high customization, robustness and flexibility.

Nowadays many people are thinking of migrating their website from Drupal to WordPress. At first glance, it seems easy but actually it requires a lot of patience and care in doing it. For example: You have a WordPress website installed with its theme and now you want to get all the contents into your WordPress database such as pages, posts, comments, forums etc. from your Drupal website. One way of doing this is you can replicate the data of the comments (from comments table of Drupal to comments table of WordPress), posts (from node and node_revisions table of Drupal to posts table of WordPress) and categories (move data from term_data of Drupal to term_taxonomy table of WordPress).

Hurdles or issues to be taken care of while migrating from Drupal to WordPress

Mapping the URL

The pattern of URL followed in Drupal is more flexible than in WordPress. URL pattern in Drupal can be defined at the node level. So it becomes difficult to have the same URLs when you are replicating the Drupal pages and posts.

Content fields and type

Creating customized types and fields in Drupal is easy but migrating them to WordPress is challenging. In WordPress, each type or field is stored in different table and different structure.

Suppose you have a database called WordPress using ‘wp_’ prefix and a database named Drupal. Now following script should be used.

# To clear all existing WordPress content
TRUNCATE TABLE wordpress.wp_comments; TRUNCATE TABLE wordpress.wp_links; TRUNCATE TABLE wordpress.wp_postmeta; TRUNCATE TABLE wordpress.wp_posts; TRUNCATE TABLE wordpress.wp_term_relationships; TRUNCATE TABLE wordpress.wp_term_taxonomy; TRUNCATE TABLE wordpress.wp_terms;

# To create Categories
INSERT INTO wordpress.wp_terms (term_id, `name`, slug, term_group) SELECT d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_'), 0 FROM drupal.term_data d INNER JOIN drupal.term_hierarchy h USING(tid);

# To import pages / posts
INSERT INTO wordpress.wp_posts (id, post_content, post_date, post_excerpt, post_title, post_name, post_modified, post_type, `post_status`) SELECT DISTINCT n.nnid `id`, FROM_UNIXTIME(n.created) `post_date`, r.body `post_content`, n.title `post_title`, r.teaser `post_excerpt`, IF(SUBSTR(a.dst, 11, 1) = '/', SUBSTR(a.dst, 12), a.dst) `post_name`, FROM_UNIXTIME(n.changed) `post_modified`, n.type `post_type`, IF(n.status = 1, 'publish', 'private') `post_status` FROM drupal.node n INNER JOIN drupal.node_revisions r USING(vid) LEFT OUTER JOIN drupal.url_alias a ON a.src = CONCAT('node/', n.nnid) WHERE n.type IN ('post', 'page', 'article');

# Turn your articles to posts
update wordpress.wp_posts set post_type='post' where post_type='article';

# To update count of category
UPDATE wordpress.wp_term_taxonomy tt SET `count` = ( SELECT COUNT(tr.object_id) FROM wordpress.wp_term_relationships tr WHERE tr.term_taxonomy_id = tt.term_taxonomy_id);

# To import the comments
INSERT INTO wordpress.wp_comments (comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url, comment_approved) SELECT nnid, FROM_UNIXTIME(timestamp), comment, thread, name, mail, homepage, status FROM drupal.comments;

# To fix breaks in post
UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '', '');

# To fix images in post
UPDATE wordpress.wp_posts SET post_content = REPLACE(post_content, '"/files/', '"/wp-content/uploads/');

About the Author:
This article is contributed by ValueCoders, a web/mobile development firm, specialized in CMS development, through which you can hire Drupal programmers, Joomla programmers, magento programmers, etc. One can also hire WordPress developer here for effective WordPress development services.

No comments:

Post a Comment