Merge pull request #3166 from fantasticfears/bbpress
add table prefix constant to bbpress import script & fix user imports
This commit is contained in:
commit
a55a6fb703
|
@ -5,6 +5,7 @@
|
||||||
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 = "bbpress"
|
||||||
|
DB_TABLE_PREFIX = "wp_"
|
||||||
|
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
|
|
||||||
|
@ -21,23 +22,25 @@ class ImportScripts::Bbpress < ImportScripts::Base
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def table_name(name)
|
||||||
|
DB_TABLE_PREFIX + name
|
||||||
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
users_results = @client.query("
|
users_results = @client.query("
|
||||||
select id,
|
SELECT id,
|
||||||
user_login username,
|
user_login username,
|
||||||
display_name name,
|
display_name name,
|
||||||
user_url website,
|
user_url website,
|
||||||
user_email email,
|
user_email email,
|
||||||
user_registered created_at
|
user_registered created_at
|
||||||
from wp_users
|
FROM #{table_name 'users'}", cache_rows: false)
|
||||||
where spam = 0
|
|
||||||
and deleted = 0 limit 50", cache_rows: false)
|
|
||||||
|
|
||||||
create_users(users_results) do |u|
|
create_users(users_results) do |u|
|
||||||
ActiveSupport::HashWithIndifferentAccess.new(u)
|
ActiveSupport::HashWithIndifferentAccess.new(u)
|
||||||
end
|
end
|
||||||
|
|
||||||
create_categories(@client.query("select id, post_name from wp_posts where post_type = 'forum' and post_name != ''")) do |c|
|
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']}
|
{id: c['id'], name: c['post_name']}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,28 +51,28 @@ class ImportScripts::Bbpress < ImportScripts::Base
|
||||||
puts '', "creating topics and posts"
|
puts '', "creating topics and posts"
|
||||||
|
|
||||||
total_count = @client.query("
|
total_count = @client.query("
|
||||||
select count(*) count
|
SELECT count(*) count
|
||||||
from wp_posts
|
FROM #{table_name 'posts'}
|
||||||
where post_status <> 'spam'
|
WHERE post_status <> 'spam'
|
||||||
and post_type in ('topic', 'reply')").first['count']
|
AND post_type IN ('topic', 'reply')").first['count']
|
||||||
|
|
||||||
batch_size = 1000
|
batch_size = 1000
|
||||||
|
|
||||||
batches(batch_size) do |offset|
|
batches(batch_size) do |offset|
|
||||||
results = @client.query("
|
results = @client.query("
|
||||||
select id,
|
SELECT id,
|
||||||
post_author,
|
post_author,
|
||||||
post_date,
|
post_date,
|
||||||
post_content,
|
post_content,
|
||||||
post_title,
|
post_title,
|
||||||
post_type,
|
post_type,
|
||||||
post_parent
|
post_parent
|
||||||
from wp_posts
|
FROM #{table_name 'posts'}
|
||||||
where post_status <> 'spam'
|
WHERE post_status <> 'spam'
|
||||||
and post_type in ('topic', 'reply')
|
AND post_type IN ('topic', 'reply')
|
||||||
order by id
|
ORDER BY id
|
||||||
limit #{batch_size}
|
LIMIT #{batch_size}
|
||||||
offset #{offset}", cache_rows: false)
|
OFFSET #{offset}", cache_rows: false)
|
||||||
|
|
||||||
break if results.size < 1
|
break if results.size < 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue