I got a comment the other day asking how I converted to WordPress from Mephisto while keeping my comments and everything intact. If you are familiar with Ruby on Rails, this response will make sense. If you are not, I recommend learning it…then this response will make sense.

In a nutshell, I used Mephisto for the conversion. First I spent about a week mapping Mephisto’s DB to WordPress’ DB. I went straight into the Mephisto Rails project and created a new model that pointed to my newly created WordPress database. I then created a controller in Mephisto that looked exactly like this:

(note: if this is a pain to read, you can also view it here)

  1. class MephistoController < ApplicationController
  2.     def index
  3.         start_time = Time.now
  4.         logger.info 'querying mephisto articles'
  5.         @articles = Content.find(:all, :conditions=>"article_id IS NULL")
  6.                 logger.info 'querying mephisto comments'
  7.                 @comments = Content.find(
  8.             :all, :conditions=>"article_id IS NOT NULL")
  9.         logger.info 'querying mephisto taggings'
  10.         @taggings = Tagging.find(:all)
  11.         logger.info 'querying mephisto tags'
  12.         @tags = Tag.find(:all)
  13.         logger.info 'processing terms'
  14.         for tag in @tags
  15.             @wp_term = WpTerm.new
  16.             @wp_term.term_id = tag.id
  17.             @wp_term.name = tag.name
  18.             @wp_term.slug = tag.name.downcase.gsub(" ","_")
  19.             @wp_term.term_group = 0
  20.             @wp_term.save
  21.         end
  22.         logger.info 'processing term relationships'
  23.         for tagging in @taggings
  24.             @wp_tr = WpTermRelationships.new
  25.             @wp_tr.term_taxonomy_id = tagging.tag_id
  26.             @wp_tr.object_id = tagging.taggable_id
  27.             @wp_tr.save
  28.         end
  29.         logger.info 'processing term taxonomy'
  30.         for tag in @tags
  31.             c = Tagging.count(:all, :conditions=>"tag_id = #{tag.id}")
  32.             @wp_tt = WpTermTaxonomy.new
  33.             @wp_tt.term_taxonomy_id = tag.id
  34.             @wp_tt.term_id = tag.id
  35.             @wp_tt.taxonomy = "post_tag"
  36.             @wp_tt.parent = 0
  37.             @wp_tt.count = c
  38.             @wp_tt.save
  39.         end
  40.         logger.info 'processing posts'
  41.         for article in @articles
  42.             c = Content.count(:all, :conditions=>"article_id = #{article.id}")
  43.             @wp_post = WpPost.new
  44.             @wp_post.ID = article.id
  45.             @wp_post.post_author = 1
  46.             @wp_post.post_date = article.published_at-7.hours
  47.             @wp_post.post_date_gmt = article.published_at
  48.             @wp_post.post_content = article.body
  49.             @wp_post.post_title = article.title
  50.             @wp_post.post_category = 39
  51.             @wp_post.post_status = "publish"
  52.             @wp_post.post_status = "open"
  53.             @wp_post.ping_status = "closed"
  54.             @wp_post.post_name = article.permalink
  55.             @wp_post.post_modified = article.updated_at-7.hours
  56.             @wp_post.post_modified_gmt = article.updated_at
  57.             @wp_post.post_parent = 0
  58.             @wp_post.guid = article.published_at.strftime("http://blog.gillumiante.com/%Y/%m/%d/")+article.permalink
  59.             @wp_post.menu_order = 0
  60.             @wp_post.post_type = "post"
  61.             @wp_post.comment_count = c
  62.             @wp_post.save
  63.         end
  64.         logger.info 'processing comments'
  65.                 for comment in @comments
  66.             @wp_com = WpComment.new
  67.             @wp_com.comment_ID = comment.id
  68.             @wp_com.comment_post_ID = comment.article_id
  69.             @wp_com.comment_author = comment.author
  70.             @wp_com.comment_author_email = comment.author_email
  71.             if comment.author_url == nil
  72.                 comment.author_url = ""
  73.             end
  74.             @wp_com.comment_author_url = comment.author_url
  75.             @wp_com.comment_author_IP = comment.author_ip
  76.             @wp_com.comment_date = comment.published_at-7.hours
  77.             @wp_com.comment_date_gmt = comment.published_at
  78.             @wp_com.comment_content = comment.body
  79.             @wp_com.comment_karma = 0
  80.             @wp_com.comment_approved = '1'
  81.             @wp_com.comment_parent = 0
  82.             @wp_com.user_id = 0
  83.             @wp_com.save
  84.                 end
  85.         logger.info 'finished!'
  86.         end_time = Time.now
  87.         @lapsed = end_time-start_time
  88.         render :layout=>false
  89.     end
  90. end
class MephistoController < ApplicationController
    def index
        start_time = Time.now
        logger.info 'querying mephisto articles'
        @articles = Content.find(:all, :conditions=>"article_id IS NULL")
                logger.info 'querying mephisto comments'
                @comments = Content.find(
			:all, :conditions=>"article_id IS NOT NULL")
        logger.info 'querying mephisto taggings'
        @taggings = Tagging.find(:all)
        logger.info 'querying mephisto tags'
        @tags = Tag.find(:all)
        logger.info 'processing terms'
        for tag in @tags
            @wp_term = WpTerm.new
            @wp_term.term_id = tag.id
            @wp_term.name = tag.name
            @wp_term.slug = tag.name.downcase.gsub(" ","_")
            @wp_term.term_group = 0
            @wp_term.save
        end
        logger.info 'processing term relationships'
        for tagging in @taggings
            @wp_tr = WpTermRelationships.new
            @wp_tr.term_taxonomy_id = tagging.tag_id
            @wp_tr.object_id = tagging.taggable_id
            @wp_tr.save
        end
        logger.info 'processing term taxonomy'
        for tag in @tags
            c = Tagging.count(:all, :conditions=>"tag_id = #{tag.id}")
            @wp_tt = WpTermTaxonomy.new
            @wp_tt.term_taxonomy_id = tag.id
            @wp_tt.term_id = tag.id
            @wp_tt.taxonomy = "post_tag"
            @wp_tt.parent = 0
            @wp_tt.count = c
            @wp_tt.save
        end
        logger.info 'processing posts'
        for article in @articles
            c = Content.count(:all, :conditions=>"article_id = #{article.id}")
            @wp_post = WpPost.new
            @wp_post.ID = article.id
            @wp_post.post_author = 1
            @wp_post.post_date = article.published_at-7.hours
            @wp_post.post_date_gmt = article.published_at
            @wp_post.post_content = article.body
            @wp_post.post_title = article.title
            @wp_post.post_category = 39
            @wp_post.post_status = "publish"
            @wp_post.post_status = "open"
            @wp_post.ping_status = "closed"
            @wp_post.post_name = article.permalink
            @wp_post.post_modified = article.updated_at-7.hours
            @wp_post.post_modified_gmt = article.updated_at
            @wp_post.post_parent = 0
            @wp_post.guid = article.published_at.strftime("http://blog.gillumiante.com/%Y/%m/%d/")+article.permalink
            @wp_post.menu_order = 0
            @wp_post.post_type = "post"
            @wp_post.comment_count = c
            @wp_post.save
        end
        logger.info 'processing comments'
                for comment in @comments
            @wp_com = WpComment.new
            @wp_com.comment_ID = comment.id
            @wp_com.comment_post_ID = comment.article_id
            @wp_com.comment_author = comment.author
            @wp_com.comment_author_email = comment.author_email
            if comment.author_url == nil
                comment.author_url = ""
            end
            @wp_com.comment_author_url = comment.author_url
            @wp_com.comment_author_IP = comment.author_ip
            @wp_com.comment_date = comment.published_at-7.hours
            @wp_com.comment_date_gmt = comment.published_at
            @wp_com.comment_content = comment.body
            @wp_com.comment_karma = 0
            @wp_com.comment_approved = '1'
            @wp_com.comment_parent = 0
            @wp_com.user_id = 0
            @wp_com.save
                end
        logger.info 'finished!'
        end_time = Time.now
        @lapsed = end_time-start_time
        render :layout=>false
    end
end

I then proceeded to visit the /mephisto/index page on my mephisto blog, which fired this baby off. It took all of about 9 seconds to complete.

I realize the irony of using Mephisto in order to abandon it. But in the end, I wasn’t switching from the Rails based app because of Rails, but because of the app. I am still in love with rails and as you can see, this project would have taken me a lot longer to accomplish had I attempted to write it in PHP, the language of WordPress.

Short URL: http://glmn8.com/zo83oK

8 Responses to “How I converted Mephisto to WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">