De Drupal a WordPress

Recientemente estuve trabajando en la migración de un blog de Drupal 7 a WordPress 3.3.

Basándome en ésta guía dirigida a migrar de Drupal 6 a WordPress, y con algunas pocas modificaciones, pude realizar el proceso sin mayores inconvenientes.

A continución dejo el detalle de los pasos realizados.

Detalles:

  • La base de datos utilizada por Drupal 7 se llama drupal, y la utilizada por WordPress 3.3, wordpress.
  • Ninguna de las instrucciones que aquí se indican escriben en la Base de Datos drupal, por lo tanto, el procedimiento se puede aplicar de forma reiterada la cantidad de veces que sea necesario.

Limpieza de las tablas de wordpress

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;

Migración de las categorías

REPLACE INTO wordpress.wp_terms (term_id, `name`, slug, term_group)
SELECT DISTINCT d.tid, d.name,
REPLACE(LOWER(d.name), ' ', '_'), 0
FROM drupal.taxonomy_term_data d
INNER JOIN drupal.taxonomy_term_hierarchy h
USING(tid)
WHERE (1);

INSERT INTO wordpress.wp_term_taxonomy (term_taxonomy_id, term_id, taxonomy, description, parent)
SELECT DISTINCT d.tid 'term_id', d.tid 'term_id', 'category' category, d.description 'description', h.parent 'parent'
FROM drupal.taxonomy_term_data d
INNER JOIN drupal.taxonomy_term_hierarchy h
USING(tid)
WHERE (1);

Migración de los POSTS

INSERT INTO wordpress.wp_posts (id, post_author, post_date, post_content, post_title,
            post_excerpt, post_name, post_modified, post_type, post_status)
SELECT nid 'id', n.uid 'post_author', FROM_UNIXTIME(n.created) 'post_date', r.body_value 'post_content',
       n.title 'post_title', r.body_summary 'post_excerpt', n.title 'post_title', 'post', 'post',
IF(n.status = 1, 'publish', 'private') 'post_status'
FROM drupal.node n, drupal.field_data_body r
WHERE n.nid = r.entity_id;

Asociación de Posts y Categorías

INSERT INTO wordpress.wp_term_relationships (object_id, term_taxonomy_id)
SELECT DISTINCT nid, tid
FROM drupal.taxonomy_index;

Contabilización de post en cada categoría

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);

Migración y asociación de comentarios

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 dc.nid, FROM_UNIXTIME(dc.created), df.comment_body_value, dc.thread, dc.name,
       dc.mail, dc.homepage, ((dc.status + 1) % 2) 'status'
FROM drupal.comment dc, drupal.field_data_comment_body df
WHERE cid = entity_id;

Contabilización de comentarios en cada Post

UPDATE wordpress.wp_posts SET `comment_count` = ( SELECT COUNT(`comment_post_id`)
FROM wordpress.wp_comments
WHERE wordpress.wp_posts.`id` = wordpress.wp_comments.`comment_post_id` );

One thought on “De Drupal a WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *