Apr 132011
 

SQL-запросы для переноса базы с Drupal’а на WordPress:

Категории и теги:

INSERT INTO wp_terms (term_id, `name`, slug, term_group)
SELECT
d.tid, d.name, REPLACE(LOWER(d.name), ‘ ‘, ‘-‘), 0
FROM term_data d
INNER JOIN term_hierarchy h
USING(tid)
;

INSERT INTO wp_term_taxonomy (term_id, taxonomy, description, parent)
SELECT
d.tid `term_id`,
‘category’ `taxonomy`,
d.description `description`,
h.parent `parent`
FROM term_data d
INNER JOIN term_hierarchy h
USING(tid)
;

Посты:

INSERT INTO
wp_posts (id, post_date, post_date_gmt, post_content, post_title,
post_excerpt, post_name, post_modified, post_modified_gmt, post_author)
SELECT DISTINCT
n.nid, FROM_UNIXTIME(created), FROM_UNIXTIME(created), body, n.title,
teaser,
n.nid,
FROM_UNIXTIME(changed), FROM_UNIXTIME(changed), n.uid
FROM node n, node_revisions r
WHERE n.vid = r.vid

INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
SELECT nid, tid FROM term_node;

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

Комментарии:

INSERT INTO wp_comments (comment_post_ID, comment_date, comment_date_gmt, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url, comment_approved, user_id)
SELECT nid, FROM_UNIXTIME(timestamp), FROM_UNIXTIME(timestamp), comment, thread, name, mail, homepage, status, uid FROM comments;

Обновляем счетчик комментариев:

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

Неведомая хуита:

UPDATE wp_posts SET post_content = REPLACE(post_content, ”, ”);

Ссылки на файлы:

UPDATE wp_posts SET post_content = REPLACE(post_content, ‘”/sites/default/files/’, ‘”/wp-content/uploads/’);

Пользователи:

INSERT INTO wp_users ( ID, user_login, user_pass, user_nicename, user_email, user_registered, display_name )
SELECT uid, name, pass, name, mail, FROM_UNIXTIME(created), name FROM users;