Add subcategory support to BBPress import

This commit is contained in:
Robin Ward 2015-03-16 13:18:20 -04:00
parent 83a2a832b1
commit 50bf066afd

View File

@ -2,12 +2,12 @@
# `createdb bbpress` # `createdb bbpress`
# `bundle exec rake db:migrate` # `bundle exec rake db:migrate`
require 'mysql2'
require File.expand_path(File.dirname(__FILE__) + "/base.rb") require File.expand_path(File.dirname(__FILE__) + "/base.rb")
BB_PRESS_DB = "bbpress" BB_PRESS_DB = ENV['BBPRESS_DB'] || "bbpress"
DB_TABLE_PREFIX = "wp_" DB_TABLE_PREFIX = "wp_"
require 'mysql2'
class ImportScripts::Bbpress < ImportScripts::Base class ImportScripts::Bbpress < ImportScripts::Base
@ -40,8 +40,13 @@ class ImportScripts::Bbpress < ImportScripts::Base
ActiveSupport::HashWithIndifferentAccess.new(u) ActiveSupport::HashWithIndifferentAccess.new(u)
end end
create_categories(@client.query("SELECT id, post_name from #{table_name 'posts'} WHERE post_type = 'forum' AND post_name != ''")) do |c| create_categories(@client.query("SELECT id, post_name, post_parent from #{table_name 'posts'} WHERE post_type = 'forum' AND post_name != '' ORDER BY post_parent")) do |c|
{id: c['id'], name: c['post_name']} result = {id: c['id'], name: c['post_name']}
parent_id = c['post_parent'].to_i
if parent_id > 0
result[:parent_category_id] = category_id_from_imported_category_id(parent_id)
end
result
end end
import_posts import_posts