diff --git a/script/import_scripts/bbpress.rb b/script/import_scripts/bbpress.rb index 4a1937eed..3f28d3668 100644 --- a/script/import_scripts/bbpress.rb +++ b/script/import_scripts/bbpress.rb @@ -2,12 +2,12 @@ # `createdb bbpress` # `bundle exec rake db:migrate` +require 'mysql2' require File.expand_path(File.dirname(__FILE__) + "/base.rb") -BB_PRESS_DB = "bbpress" +BB_PRESS_DB = ENV['BBPRESS_DB'] || "bbpress" DB_TABLE_PREFIX = "wp_" -require 'mysql2' class ImportScripts::Bbpress < ImportScripts::Base @@ -40,8 +40,13 @@ class ImportScripts::Bbpress < ImportScripts::Base ActiveSupport::HashWithIndifferentAccess.new(u) end - create_categories(@client.query("SELECT id, post_name from #{table_name 'posts'} WHERE post_type = 'forum' AND post_name != ''")) do |c| - {id: c['id'], name: c['post_name']} + 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| + 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 import_posts