Si emigra d’inverno

November 15th, 2008 | Categories: Varie ed eventuali | Tags: , ,

Sto migrando phigate da Typo a Wordpress. State in fibrillazione con me, fintanto che non ho finito …
e portate pazienza per le cose che ancora non funzionano.

I motivi della migrazione: di Typo non potevo lamentarmi, mi ci sono sempre trovato bene, ma nel caso di phigate non sono riuscito a risolvere un problema con la gestione della sidebar, che è sempre stata “ingestibile”. Stranamente, perché ho altri blog Typo sullo stesso server e nessuno di questi creava gli stessi problemi. Dopo ennemila tentativi di sistemare la cosa, ci ho rinnunciato e ho deciso a passare a Wordpress. La cosa, non è indolore, come credo si veda anche dallo stato attuale del sito, ma apparentemente non avevo scelta.

Come ho migrato: in modo relativamente semplice, ho creato una nuova installazione di wordpress; dal vecchio database ho salvato alcune tabelle, con un mysqldump -u username -p name_of_typo_db articles_tags tags categorizations categories contents feedback > dumpster.sql. Dopodiché l’ho dato in pasto al nuovo database wordpress, seguito da questo file sql:

/* clear up the existing posts, comments and categories */
DELETE FROM wp_posts;
DELETE FROM wp_comments;
DELETE FROM wp_post2cat;

/* insert categories from typo */
INSERT INTO wp_terms (name,slug)
SELECT categories.name, categories.permalink FROM categories;

INSERT INTO wp_term_taxonomy (term_id,taxonomy)
SELECT wp_terms.term_id, 'category' from wp_terms,categories where wp_terms.name = categories.name;

INSERT INTO wp_posts (post_author,post_title,post_content, post_name, post_date,
post_date_gmt,post_modified,post_modified_gmt,
post_status,
ping_status,
comment_status)
SELECT 1, title, concat(ifnull(body, ''), ifnull(extended,''))
/*concat(CASE body WHEN '' THEN IFNULL(body,'')
END, CASE extended WHEN '' THEN IFNULL(extended,'')
END),*/
, permalink,
created_at, created_at, updated_at, updated_at,
CASE published WHEN 0 then 'draft' ELSE 'publish' END,
CASE allow_pings WHEN 0 then 'closed' ELSE 'open' END,
CASE allow_comments WHEN 0 then 'closed' ELSE 'open' END
FROM contents
WHERE contents.type = 'Article';

/* insert pages from typo */
INSERT INTO wp_posts (post_author,post_title,post_content,post_name,post_date,
post_date_gmt,post_modified,post_modified_gmt,
post_status,
ping_status,
comment_status,
post_type)
SELECT 1, title, concat(ifnull(body,''), IFNULL(extended,'')),
name, created_at, created_at, updated_at, updated_at,
'static',
'closed',
'closed',
'page'
FROM contents
WHERE contents.type = 'Page';
/* associate categories and posts */
INSERT INTO wp_term_relationships (object_id,term_taxonomy_id)
SELECT wp_posts.ID, wp_term_taxonomy.term_taxonomy_id FROM wp_posts
INNER JOIN contents ON wp_posts.post_name = contents.permalink
INNER JOIN categorizations ON categorizations.article_id = contents.id
INNER JOIN categories ON categorizations.category_id = categories.id
INNER JOIN wp_terms ON wp_terms.slug = categories.permalink
INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id;

/* update the permalink structure for posts */
UPDATE wp_options
SET option_value = '/articles/%year%/%monthnum%/%day%/%postname%/'
WHERE option_name = 'permalink_structure';

/* update the permalink structure for categories */
UPDATE wp_options
SET option_value = '/articles/category/'
WHERE option_name = 'category_base';

/* update each category with post count */
UPDATE wp_term_taxonomy
SET count = (SELECT COUNT(*) FROM wp_term_relationships WHERE wp_term_relationships.term_taxonomy_id  = wp_term_taxonomy.term_taxonomy_id);

/* insert comments from typo */
delete from feedback where state like '%Spam' ;
INSERT INTO wp_comments (comment_author,comment_content,comment_date,comment_date_gmt,comment_post_id,comment_author_email,comment_author_url,comment_author_IP,comment_approved)
SELECT f.author, IFNULL(f.body,''), f.created_at, f.created_at, wp_posts.ID, f.email, f.url, f.ip, 1
FROM feedback f
INNER JOIN contents ON f.article_id = contents.id
INNER JOIN wp_posts ON wp_posts.post_name = contents.permalink;

/* update each post with comment count */
UPDATE wp_posts
SET comment_count = (SELECT COUNT(*) FROM wp_comments WHERE comment_post_id = id);

/* insert tags from typo */
INSERT INTO wp_terms (name,slug)
SELECT distinct tags.display_name, tags.name FROM tags,categories where tags.name NOT IN(Select categories.name from categories);

INSERT INTO wp_term_taxonomy (term_id,taxonomy)
SELECT distinct wp_terms.term_id, 'post_tag' from wp_terms,tags where wp_terms.name = tags.name and  tags.name NOT IN(Select categories.name from categories);

/* associate tags with posts */
delete from tags where tags.name IN (select categories.permalink from categories);

INSERT INTO wp_term_relationships (object_id,term_taxonomy_id)
SELECT wp_posts.ID, wp_term_taxonomy.term_taxonomy_id FROM wp_posts
INNER JOIN contents ON wp_posts.post_name = contents.permalink
INNER JOIN articles_tags ON articles_tags.article_id = contents.id
INNER JOIN tags ON articles_tags.tag_id = tags.id
INNER JOIN wp_terms ON wp_terms.slug = tags.name
INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id;

/* update permalink for tags */
UPDATE wp_options
SET option_value = '/tags/'
WHERE option_name = 'utw_base_url';

/* turn on pretty URLS for tags */
UPDATE wp_options
SET option_value = 'yes'
WHERE option_name = 'utw_use_pretty_urls';

/* clean up */
DROP TABLE categorizations;
DROP TABLE articles_tags;
DROP TABLE categories;
DROP TABLE contents;
DROP TABLE tags;

Quasi tutto è andato a buon fine, tranne il fatto che mi sono perso le risorse che avevo inserito nel blog (alcune immagini), alcuni tags non sono associati agli articoli e che le accentate sono andate a quel paese. Al momento non trovo altri errori, il che mi pare accettabile.

No comments yet.
TOP