Last active
November 1, 2019 13:19
-
-
Save angezanetti/8634987 to your computer and use it in GitHub Desktop.
Migrate SPIP to Wordpress with SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Source http://contrib.spip.net/Export-Spip-vers-Wordpress | |
-- Imports terms | |
REPLACE INTO wp_terms(term_id, name, slug, term_group) | |
SELECT id_rubrique, titre, CONCAT("rub",id_rubrique), 1 FROM spip_rubriques; | |
-- Update urls | |
UPDATE wp_terms, spip_urls | |
SET slug = spip_urls.url | |
WHERE spip_urls.id_objet = term_id | |
AND spip_urls.type = "rubrique" | |
-- Import posts | |
REPLACE INTO wp_posts( | |
ID | |
, post_author | |
, post_date, post_date_gmt | |
, post_content | |
, post_title | |
#, post_category | |
# , post_status | |
, to_ping , pinged | |
, post_modified, post_modified_gmt | |
) | |
SELECT | |
p.id_article | |
, u.id_auteur | |
, p.date, p.date | |
, concat(p.chapo, p.descriptif, p.texte) | |
, titre | |
#, p.id_rubrique | |
, '', '' | |
, p.date_modif, p.date_modif | |
FROM | |
spip_articles AS p | |
LEFT JOIN spip_auteurs_articles AS u ON u.id_article = p.id_article; | |
-- Link posts to terms | |
REPLACE INTO wp_term_relationships(object_id, term_taxonomy_id) | |
SELECT p.id_article, p.id_rubrique FROM spip_articles AS p; | |
-- Import comments | |
REPLACE INTO wp_comments( | |
comment_ID | |
, comment_post_ID | |
, comment_author | |
, comment_author_email | |
,comment_author_url | |
, comment_date | |
, comment_date_gmt | |
, comment_content | |
, comment_parent | |
, comment_approved | |
) | |
SELECT | |
id_forum | |
, id_article | |
, auteur | |
, email_auteur | |
, url_site | |
, date_heure | |
, date_heure | |
, texte | |
, id_parent | |
, 0 | |
FROM spip_forum; | |
-- Approve comments ( not really working here ) | |
update wp_comments, spip_forum | |
SET comment_approved = 1 | |
WHERE wp_comments .comment_ID = spip_forum.id_article | |
AND spip_forum.statut = "publie" | |
-- Update comments numbers per post ( Nor Working for me ) | |
UPDATE wp_posts | |
SET comment_count = (SELECT COUNT( * ) | |
from wp_comments, wp_posts WHERE comment_post_ID = ID and comment_approved = 1) | |
-- Update the syntax (basically transform weird SPIP stuff into HTML | |
update wp_posts set post_content = replace(post_content, '{{', ' <b> ') where instr(post_content, '{{') > 0 | |
update wp_posts set post_content = replace(post_content, '}}', ' </b> ') where instr(post_content, '}}') > 0 | |
update wp_posts set post_content = replace(post_content, '{', ' <i> ') where instr(post_content, '{') > 0 | |
update wp_posts set post_content = replace(post_content, '}', ' </i> ') where instr(post_content, '}') > 0 | |
update wp_posts set post_content = replace(post_content, '{{{', ' <h1> ') where instr(post_content, '{{{') > 0 | |
update wp_posts set post_content = replace(post_content, '}}}', ' </h1> ') where instr(post_content, '}}}') > 0 | |
update wp_posts set post_content = replace(post_content, '[[', ' <blockquote> ') where instr(post_content, '[[') > 0 | |
update wp_posts set post_content = replace(post_content, ']]', ' </blockquote> ') where instr(post_content, ']]') > 0 | |
update wp_posts set post_content = replace(post_content, '*]', ' </strong></i> ') where instr(post_content, '*]') > 0 | |
update wp_posts set post_content = replace(post_content, '[*', ' </strong></i> ') where instr(post_content, '*]') > 0 |
I don't seem to have spip_auteurs_articles? How can I import import the posts?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this code. Quite helpful.