Obtvse is a minimalist blog, made simple and built on Rails. I like minimalism, so I wanted to test and do something with it. I worked in a rake task to just migrate my actual posts to this new platform.
To make it work there’s only a few steps needed.
In your Gemfile you need to put…
Then add an environment to your config/database.yml
wordpress: adapter: mysql encoding: utf8 database: obtvse_example username: my_user password: my_pass host: localhost
Finally you could call it from the command line…
rake wordpress:migrate_wordpress[source_db, destiny_db]
Where source_db is your Wordpress db in the database.yml file, and destiny_db is the Obtvse one.
The code is not a big deal, just a few lines. I know It could be a better implementation, but is my first rake task, I would like some feedback. :-)
# -*- coding:utf-8 -*- # Usage rake wordpress:migrate_wordpress[:src, :dst] # You will need gem "mysql" in your Gemfile namespace :wordpress do task :migrate_wordpress, [:src, :dst] => :environment do |cmd, args| args.with_defaults(:src => "wordpress", :dst => "development") config = Rails.configuration.database_configuration src_db = config[args[:src]] dst_db = config[args[:dst]] conn = ActiveRecord::Base.establish_connection src_db posts = conn.connection.execute "SELECT * FROM wp_posts where post_status='draft' or post_status='publish'" conn = ActiveRecord::Base.establish_connection dst_db posts.each do |post| title = post.force_encoding 'utf-8' content = post.force_encoding 'utf-8' created_at = post updated_at = post draft = post if draft.end_with? "draft" draft_flag = true elsif draft.end_with? "publish" draft_flag = false end p = Post.create! :title => title, :content => content, :slug => Post.acts_as_url(:title, :url_attribute => :slug), :created_at => created_at, :updated_at => updated_at, :draft => draft_flag end end end