summaryrefslogtreecommitdiff
path: root/src/Migrating_from_Drupal_7_to_Habari_.8.adoc
blob: 1d2e5cfea4f63eb20f1f0d6cdca4b216f7d4c951 (plain)
    1 Migrating from Drupal 7 to Habari .8
    2 ====================================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 
    7 == {doctitle}
    8 
    9 Lately I've been trying out the latest release of
   10 http://habariproject.org/[Habari] and I really like it. They have created a
   11 very simple, yet functional and very clean interface with which to blog (not to
   12 mention its code implements the newest of just about everthing). With that,
   13 bitnode used to be run on Drupal, so converting from elenty billion 'articles'
   14 (that's the technical number) to posts in Habari was not looking too easy.
   15 After some searching, I found that the best way to convert without having to
   16 write some sql statements would be to migrate from Drupal 7 to Drupal 6, then
   17 from Drupal 6 to Wordpress 2.3; then from Wordpress 2.3 to Habari .8.
   18 
   19 What?
   20 
   21 So it seemed that manually copying the data from column to column with sql
   22 statements would be my best route. After some time (and so so many browser
   23 tabs), I finally came up with some queries that would migrate you from Drupal 7
   24 to Habari .8. Please keep in mind that these will not migrate all of your data.
   25 These are only for migrating your posts and their related comments.
   26 
   27 Assumptions:
   28 
   29 * Habari instance table prefix is habari_
   30 * Drupal instance table prefix is drupal_
   31 * Our author user id is 2
   32 
   33 
   34 ----
   35 - Move our posts over using the drupal ids so we can relate our comments later
   36 insert into `habari_posts` (id, title, slug, content, user_id, status, pubdate, updated) select nid,title,title,body_value, 2, status,  created, changed from drupal_node join drupal_field_data_body on drupal_node.nid=drupal_field_data_body.entity_id;
   37 ----
   38 
   39 Here we are doing a simple insert into habari_posts from another table.
   40 However, due to Drupal's robust database structure (not sure if it's 3NF), we
   41 have to query another table for our remaining post data as the meta-data (post
   42 subject, various dates, status, etc) is stored in the drupal_node table and the
   43 actual post is stored in the drupal_field_data_body table.
   44 
   45 Once again, in this query I have statically defined user id 2. You will need to
   46 change this to your user's ID in Habari who you want to show up as posting
   47 everything. If you need to import multiple user's posts, you will need to query
   48 for the Drupal user IDs and change the Habari user IDs to match the posts
   49 (that's the easiest way).
   50 
   51 ----
   52 - update our drupal published status to the habari version
   53 update habari_posts set status=2 where status=1;
   54 - update our drupal draft status to the habari version
   55 update habari_posts set status=1 where status=0;
   56 ----
   57 
   58 Here we are just converting our post statuses from
   59 Drupal values to Habari values. In Habari, status 1 is published and
   60 status 0 is draft (as of 2011.12.30).
   61 
   62 ----
   63 -Now we migrate our comments
   64 insert into habari_comments (post_id, name, email, url, ip, content, status, date) select nid, name, mail, homepage, hostname, comment_body_value, status, created from drupal_comment join drupal_field_data_comment_body on drupal_comment.cid=drupal_field_data_comment_body.entity_id;
   65 ----
   66 
   67 Here we are grabbing the comments for each of the posts. Since we pulled in all
   68 the post IDs from the Drupal tables in our first query, we can do the same here
   69 and everything should line up perfectly. Once again, like with the posts,
   70 Drupal stores comment data in more than one table. In Drupal, the comment
   71 meta-data is stored in the drupal_comment table and the actual comment data is
   72 stored in the drupal_field_data_comment_body table.
   73 
   74 And that should be it. You've just migrated all of your post and comment data
   75 to Habari .8. If you have any images used in your posts, you will also need to
   76 copy Drupal's *sites/default/files/* directory to the root directory of your
   77 Habari instance.
   78 
   79 If anyone tries this out, please let me know how it worked for you. It worked
   80 fine for me (evidenced by the fact that bitnode is still viewable), but I'd
   81 like some input on how to better write these queries in case there are any
   82 additional fields I may have missed that people would be interested in. Thank's
   83 for reading!
   84 
   85 
   86 Category:Drupal
   87 Category:Habari
   88 Category:Blogging
   89 
   90 
   91 // vim: set syntax=asciidoc:

Generated by cgit