use table prefix in bbpress import script

This commit is contained in:
Arpit Jalan 2017-01-10 16:07:13 +05:30
parent b60bc47a4c
commit 6506c0d900
1 changed files with 10 additions and 8 deletions

View File

@ -16,6 +16,8 @@ class ImportScripts::Bbpress < ImportScripts::Base
BATCH_SIZE ||= 1000
BB_PRESS_PW ||= ENV['BBPRESS_PW'] || ""
BB_PRESS_USER ||= ENV['BBPRESS_USER'] || "root"
BB_PRESS_PREFIX ||= ENV['BBPRESS_PREFIX'] || "wp_"
def initialize
super
@ -37,12 +39,12 @@ class ImportScripts::Bbpress < ImportScripts::Base
puts "", "importing users..."
last_user_id = -1
total_users = bbpress_query("SELECT COUNT(*) count FROM wp_users WHERE user_email LIKE '%@%'").first["count"]
total_users = bbpress_query("SELECT COUNT(*) count FROM #{BB_PRESS_PREFIX}users WHERE user_email LIKE '%@%'").first["count"]
batches(BATCH_SIZE) do |offset|
users = bbpress_query(<<-SQL
SELECT id, user_nicename, display_name, user_email, user_registered, user_url
FROM wp_users
FROM #{BB_PRESS_PREFIX}users
WHERE user_email LIKE '%@%'
AND id > #{last_user_id}
ORDER BY id
@ -62,7 +64,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
users_description = {}
bbpress_query(<<-SQL
SELECT user_id, meta_value description
FROM wp_usermeta
FROM #{BB_PRESS_PREFIX}usermeta
WHERE user_id IN (#{user_ids_sql})
AND meta_key = 'description'
SQL
@ -71,7 +73,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
users_last_activity = {}
bbpress_query(<<-SQL
SELECT user_id, meta_value last_activity
FROM wp_usermeta
FROM #{BB_PRESS_PREFIX}usermeta
WHERE user_id IN (#{user_ids_sql})
AND meta_key = 'last_activity'
SQL
@ -97,7 +99,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
categories = bbpress_query(<<-SQL
SELECT id, post_name, post_parent
FROM wp_posts
FROM #{BB_PRESS_PREFIX}posts
WHERE post_type = 'forum'
AND LENGTH(COALESCE(post_name, '')) > 0
ORDER BY post_parent, id
@ -119,7 +121,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
last_post_id = -1
total_posts = bbpress_query(<<-SQL
SELECT COUNT(*) count
FROM wp_posts
FROM #{BB_PRESS_PREFIX}posts
WHERE post_status <> 'spam'
AND post_type IN ('topic', 'reply')
SQL
@ -134,7 +136,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
post_title,
post_type,
post_parent
FROM wp_posts
FROM #{BB_PRESS_PREFIX}posts
WHERE post_status <> 'spam'
AND post_type IN ('topic', 'reply')
AND id > #{last_post_id}
@ -155,7 +157,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
posts_likes = {}
bbpress_query(<<-SQL
SELECT post_id, meta_value likes
FROM wp_postmeta
FROM #{BB_PRESS_PREFIX}postmeta
WHERE post_id IN (#{post_ids_sql})
AND meta_key = 'Likes'
SQL