From 42f63f919f26dad617e48e43c072cf8bfae60a00 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sun, 23 Jan 2011 15:19:26 -0700 Subject: [PATCH 1/4] Add Jekyll::WordPress.TABLE_PREFIX and inclusion in QUERY --- lib/jekyll/migrators/wordpress.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/migrators/wordpress.rb b/lib/jekyll/migrators/wordpress.rb index 11b4f49a..ee3b0add 100644 --- a/lib/jekyll/migrators/wordpress.rb +++ b/lib/jekyll/migrators/wordpress.rb @@ -11,12 +11,14 @@ require 'yaml' module Jekyll module WordPress + + TABLE_PREFIX = 'wp_xh2g8g_' # Reads a MySQL database via Sequel and creates a post file for each # post in wp_posts that has post_status = 'publish'. # This restriction is made because 'draft' posts are not guaranteed to # have valid dates. - QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from wp_posts where post_status = 'publish' and post_type = 'post'" + QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from #{TABLE_PREFIX}posts where post_status = 'publish' and post_type = 'post'" def self.process(dbname, user, pass, host = 'localhost') db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') From e902bb9c30344e50d20d0f618c68c5a5dfd3caa1 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sun, 23 Jan 2011 15:21:29 -0700 Subject: [PATCH 2/4] Change TABLE_PREFIX back to default --- lib/jekyll/migrators/wordpress.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/migrators/wordpress.rb b/lib/jekyll/migrators/wordpress.rb index ee3b0add..abeb68f6 100644 --- a/lib/jekyll/migrators/wordpress.rb +++ b/lib/jekyll/migrators/wordpress.rb @@ -12,7 +12,7 @@ require 'yaml' module Jekyll module WordPress - TABLE_PREFIX = 'wp_xh2g8g_' + TABLE_PREFIX = 'wp_' # Reads a MySQL database via Sequel and creates a post file for each # post in wp_posts that has post_status = 'publish'. From bc3771aa22b61b8681353e4658efd4f2ccffd2d4 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sun, 23 Jan 2011 15:25:33 -0700 Subject: [PATCH 3/4] Change TABLE_PREFIX from class member to 4th parameter of process method (now lowercase) Move QUERY into process method --- lib/jekyll/migrators/wordpress.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/migrators/wordpress.rb b/lib/jekyll/migrators/wordpress.rb index abeb68f6..3704d3cb 100644 --- a/lib/jekyll/migrators/wordpress.rb +++ b/lib/jekyll/migrators/wordpress.rb @@ -11,19 +11,17 @@ require 'yaml' module Jekyll module WordPress - - TABLE_PREFIX = 'wp_' - # Reads a MySQL database via Sequel and creates a post file for each - # post in wp_posts that has post_status = 'publish'. - # This restriction is made because 'draft' posts are not guaranteed to - # have valid dates. - QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from #{TABLE_PREFIX}posts where post_status = 'publish' and post_type = 'post'" - - def self.process(dbname, user, pass, host = 'localhost') + def self.process(dbname, user, pass, host = 'localhost', table_prefix = 'wp_') db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') FileUtils.mkdir_p "_posts" + + # Reads a MySQL database via Sequel and creates a post file for each + # post in wp_posts that has post_status = 'publish'. + # This restriction is made because 'draft' posts are not guaranteed to + # have valid dates. + QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from #{table_prefix}posts where post_status = 'publish' and post_type = 'post'" db[QUERY].each do |post| # Get required fields and construct Jekyll compatible name From d61c1e930a3531036db51af10dde6a99aeb8d5ea Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sun, 23 Jan 2011 15:30:41 -0700 Subject: [PATCH 4/4] Fix compile error by making QUERY lowercase (local instead of const) --- lib/jekyll/migrators/wordpress.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/migrators/wordpress.rb b/lib/jekyll/migrators/wordpress.rb index 3704d3cb..3b05a5ea 100644 --- a/lib/jekyll/migrators/wordpress.rb +++ b/lib/jekyll/migrators/wordpress.rb @@ -21,9 +21,9 @@ module Jekyll # post in wp_posts that has post_status = 'publish'. # This restriction is made because 'draft' posts are not guaranteed to # have valid dates. - QUERY = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from #{table_prefix}posts where post_status = 'publish' and post_type = 'post'" + query = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from #{table_prefix}posts where post_status = 'publish' and post_type = 'post'" - db[QUERY].each do |post| + db[query].each do |post| # Get required fields and construct Jekyll compatible name title = post[:post_title] slug = post[:post_name]