Migration Dotclear1.x vers Drupal

Tagged:

Bon j'ai pris un peu de temps pour migrer tout ça, je vous fait part des quelques SQL et autres trucs que j'ai du utiliser pour migrer à peu près correctement mon blog de Dotclear version 1.x (c'était même une 1.1 ou quelque chose comme ça) vers un drupal 6.17.

Tout d'abord j'ai installé un drupal et j'ai comparé les DB. Assez différentes mais au final le mapping se fait encore bien. J'ai rapatrié ma DB de prod en local, et j'ai appliqué ce script :

  1. --
  2. -- récupération des noeuds
  3. --
  4. CREATE TABLE `node` (
  5. `vid` int(10) unsigned NOT NULL default '0',
  6. `type` varchar(32) NOT NULL default '',
  7. `language` varchar(12) NOT NULL default '',
  8. `title` varchar(255) NOT NULL default '',
  9. `uid` int(11) NOT NULL default '0',
  10. `status` int(11) NOT NULL default '1',
  11. `created` int(11) NOT NULL default '0',
  12. `changed` int(11) NOT NULL default '0',
  13. `comment` int(11) NOT NULL default '0',
  14. `promote` int(11) NOT NULL default '0',
  15. `moderate` int(11) NOT NULL default '0',
  16. `sticky` int(11) NOT NULL default '0',
  17. `tnid` int(10) unsigned NOT NULL default '0',
  18. `translate` int(11) NOT NULL default '0',
  19. PRIMARY KEY (`nid`),
  20. UNIQUE KEY `vid` (`vid`),
  21. KEY `node_changed` (`changed`),
  22. KEY `node_created` (`created`),
  23. KEY `node_moderate` (`moderate`),
  24. KEY `node_promote_status` (`promote`,`status`),
  25. KEY `node_status_type` (`status`,`type`,`nid`),
  26. KEY `node_title_type` (`title`,`type`(4)),
  27. KEY `node_type` (`type`(4)),
  28. KEY `uid` (`uid`),
  29. KEY `tnid` (`tnid`),
  30. KEY `translate` (`translate`)
  31. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  32.  
  33. -- autoincrement dynamique
  34. set @autoincrement := 0;
  35. select @autoincrement := max(post_id) from dc_post;
  36. SET @s = CONCAT("alter table node auto_increment=",@autoincrement);
  37. PREPARE stmt FROM @s;
  38. EXECUTE stmt;
  39. DEALLOCATE PREPARE stmt;
  40.  
  41. set @revision := 0;
  42. select post_id as nid, @revision:=@revision+1 as vid, 'story' as type, 'fr' as language, post_titre as title, 1 as uid, 1 as status,
  43. UNIX_TIMESTAMP(post_creadt) as created, UNIX_TIMESTAMP(post_upddt) as changed, 1 as comment, 1 as promote, 0 as moderate, 0 as sticky, 0 as tnid, 0 as translate
  44. from dc_post
  45. order by post_id;
  46.  
  47. --
  48. -- récupération des urls d'accès aux noeuds
  49. --
  50. drop table if exists `url_alias`;
  51. CREATE TABLE `url_alias` (
  52. `src` varchar(128) NOT NULL default '',
  53. `dst` varchar(128) NOT NULL default '',
  54. `language` varchar(12) NOT NULL default '',
  55. PRIMARY KEY (`pid`),
  56. UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),
  57. KEY `src_language_pid` (`src`,`language`,`pid`)
  58. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  59. insert into url_alias (src, dst, language)
  60. select concat('node/', post_id) as src, concat('fr/n', post_id, '/', post_titre_url) as dst, 'fr' as language
  61. from dc_post
  62. order by post_id;
  63.  
  64. --
  65. -- récupération du contenu associé aux noeuds
  66. --
  67. drop table if exists `node_revisions`;
  68. CREATE TABLE `node_revisions` (
  69. `nid` int(10) unsigned NOT NULL default '0',
  70. `uid` int(11) NOT NULL default '0',
  71. `title` varchar(255) NOT NULL default '',
  72. `body` longtext NOT NULL,
  73. `teaser` longtext NOT NULL,
  74. `log` longtext NOT NULL,
  75. `timestamp` int(11) NOT NULL default '0',
  76. `format` int(11) NOT NULL default '0',
  77. PRIMARY KEY (`vid`),
  78. KEY `nid` (`nid`),
  79. KEY `uid` (`uid`)
  80. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  81.  
  82. set @autoincrement := 0;
  83. select @autoincrement := count(*) from dc_post;
  84. SET @s = CONCAT("alter table node_revisions auto_increment=",@autoincrement);
  85. PREPARE stmt FROM @s;
  86. EXECUTE stmt;
  87. DEALLOCATE PREPARE stmt;
  88.  
  89. set @revision := 0;
  90. insert into node_revisions
  91. select post_id as nid, @revision:=@revision+1 as vid, 1 as uid, post_titre as title, post_content as body, post_chapo as teaser, '' as log, UNIX_TIMESTAMP(post_dt) as timestamp, 2 as format
  92. from dc_post
  93. order by post_id;
  94.  
  95. --
  96. -- récupération des commentaires
  97. --
  98. drop table if exists comments;
  99. CREATE TABLE `comments` (
  100. `pid` int(11) NOT NULL default '0',
  101. `nid` int(11) NOT NULL default '0',
  102. `uid` int(11) NOT NULL default '0',
  103. `subject` varchar(64) NOT NULL default '',
  104. `comment` longtext NOT NULL,
  105. `hostname` varchar(128) NOT NULL default '',
  106. `timestamp` int(11) NOT NULL default '0',
  107. `status` tinyint(3) unsigned NOT NULL default '0',
  108. `format` smallint(6) NOT NULL default '0',
  109. `thread` varchar(255) NOT NULL,
  110. `name` varchar(60) default NULL,
  111. `mail` varchar(64) default NULL,
  112. `homepage` varchar(255) default NULL,
  113. PRIMARY KEY (`cid`),
  114. KEY `pid` (`pid`),
  115. KEY `nid` (`nid`),
  116. KEY `status` (`status`)
  117. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  118.  
  119. set @autoincrement := 0;
  120. select @autoincrement := max(comment_id) from dc_comment;
  121. SET @s = CONCAT("alter table comments auto_increment=",@autoincrement);
  122. PREPARE stmt FROM @s;
  123. EXECUTE stmt;
  124. DEALLOCATE PREPARE stmt;
  125.  
  126. insert into comments
  127. select comment_id as cid, 0 as pid, post_id as nid, 0 as uid, '' as subject, comment_content as comment, comment_ip as hostname, UNIX_TIMESTAMP(comment_upddt) as timestamp, 0 as status, 1 as format, '01/' as thread, comment_auteur as name, comment_email as mail, comment_site as homepage
  128. from dc_comment
  129. order by comment_id;
  130.  
  131. --
  132. -- récupération des catégories
  133. --
  134. drop table if exists term_data;
  135. CREATE TABLE `term_data` (
  136. `vid` int(10) unsigned NOT NULL default '0',
  137. `name` varchar(255) NOT NULL default '',
  138. `description` longtext,
  139. `weight` tinyint(4) NOT NULL default '0',
  140. PRIMARY KEY (`tid`),
  141. KEY `taxonomy_tree` (`vid`,`weight`,`name`),
  142. KEY `vid_name` (`vid`,`name`)
  143. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  144.  
  145. set @autoincrement := 0;
  146. select @autoincrement := max(cat_id) from dc_categorie;
  147. SET @s = CONCAT("alter table term_data auto_increment=",@autoincrement);
  148. PREPARE stmt FROM @s;
  149. EXECUTE stmt;
  150. DEALLOCATE PREPARE stmt;
  151.  
  152. insert into `term_data`
  153. select cat_id as tid, 1 as vid, cat_libelle as name, '' as description, 0 as weight
  154. from dc_categorie
  155. order by cat_id;
  156.  
  157. drop table if exists term_hierarchy;
  158. CREATE TABLE `term_hierarchy` (
  159. `tid` int(10) unsigned NOT NULL default '0',
  160. `parent` int(10) unsigned NOT NULL default '0',
  161. PRIMARY KEY (`tid`,`parent`),
  162. KEY `parent` (`parent`)
  163. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  164.  
  165. insert into term_hierarchy
  166. select tid, 0
  167. from term_data;
  168.  
  169. --
  170. -- liens catégories <-> noeuds
  171. --
  172. drop table if exists term_node;
  173. CREATE TABLE `term_node` (
  174. `nid` int(10) unsigned NOT NULL default '0',
  175. `vid` int(10) unsigned NOT NULL default '0',
  176. `tid` int(10) unsigned NOT NULL default '0',
  177. PRIMARY KEY (`tid`,`vid`),
  178. KEY `vid` (`vid`),
  179. KEY `nid` (`nid`)
  180. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  181.  
  182. set @revision := 0;
  183. insert into term_node
  184. select post_id as nid, @revision:=@revision+1 as vid, cat_id as tid
  185. from dc_post
  186. order by post_id;

Ensuite il reste plus qu'a exporter ces données pour les importer dans la base drupal (S'il vous plait faites ça sur un serveur de test ... on sait jamais !)

Après ça il a pas fallu grand chose, juste une url rewrite qui me passe
* mes anciennes URL : blognote-info.com/index.php?2009/05/21/647-poc-design-website-accelere-par-tokyocabinet-part-2
* vers mes nouvelles : blognotes-info.com/fr/n647/poc-design-website-accelere-par-tokyocabinet-part-2

plus classe non ?

C'est fait avec ça :

  1. RewriteCond %{QUERY_STRING} ^[0-9]{4}/[0-9]{2}/[0-9]{2}/([0-9]+)-(.*).*$
  2. RewriteRule .* /fr/n%1/%2? [L,R]

Voila un peu prétentieux comme rewrite mais ça passe.

Ensuite dans drupal j'ai installé plein de modules:
* Locale (oui j'ai l'intention d'avoir du contenu anglais sur mon site !)
* PHP Filter qui m'a permis d'avoir la liste des catégories basée sur la taxonomy drupal (voir plus bas)
* Search (ben ça peut être pratique ;-))
* GeshiFilter pour le code
* Token, Pathauto et GlobalRedirect pour SEO et nice URL (à utiliser conjointement avec les URL alias à activer)

La liste des catégories est basée sur la taxonomie (comme dit précédemment) et est assez simple au final:
* On crée un nouveau block
* Input method : php
* Et voila le code php a y insérer ($vid correspond à l'id du vocabulaire utilisé pour les catégories):

  1. <?php
  2. $vid = 1;
  3. $items = array();
  4. $terms = taxonomy_get_tree($vid);
  5. foreach ( $terms as $term ) {
  6. $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));
  7. $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
  8. }
  9. if ( count($items) ) { print theme('item_list', $items);}
  10. ?>

J'ai encore pas mal d'autres modules en test, et d'autres à installer. J'y vais au fur et a mesure pour bien décortiquer les trucs, mais je dois dire que jusque là ça se passe plutôt bien !

La suite au prochain épisode !