Minor fixes for the Discuz importer: making uploads import optional and removing user password import
This commit is contained in:
parent
293cb7bde2
commit
cae1e7c266
3
Gemfile
3
Gemfile
@ -250,12 +250,13 @@ gem "sanitize"
|
|||||||
if ENV["IMPORT"] == "1"
|
if ENV["IMPORT"] == "1"
|
||||||
gem "mysql2"
|
gem "mysql2"
|
||||||
gem "redcarpet"
|
gem "redcarpet"
|
||||||
|
gem "php_serialize"
|
||||||
|
gem "miro"
|
||||||
|
|
||||||
# NOTE: in import mode the version of sqlite can matter a lot, so we stick it to a specific one
|
# NOTE: in import mode the version of sqlite can matter a lot, so we stick it to a specific one
|
||||||
gem "sqlite3", "~> 1.3", ">= 1.3.13"
|
gem "sqlite3", "~> 1.3", ">= 1.3.13"
|
||||||
gem "ruby-bbcode-to-md", git: "https://github.com/nlalonde/ruby-bbcode-to-md"
|
gem "ruby-bbcode-to-md", git: "https://github.com/nlalonde/ruby-bbcode-to-md"
|
||||||
gem "reverse_markdown"
|
gem "reverse_markdown"
|
||||||
gem "tiny_tds"
|
|
||||||
gem "csv"
|
gem "csv"
|
||||||
|
|
||||||
gem "parallel", require: false
|
gem "parallel", require: false
|
||||||
|
|||||||
@ -15,7 +15,7 @@ require "mysql2"
|
|||||||
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
|
require File.expand_path(File.dirname(__FILE__) + "/base.rb")
|
||||||
|
|
||||||
class ImportScripts::DiscuzX < ImportScripts::Base
|
class ImportScripts::DiscuzX < ImportScripts::Base
|
||||||
DISCUZX_DB = "ultrax"
|
DISCUZX_DB = "db_name"
|
||||||
DB_TABLE_PREFIX = "pre_"
|
DB_TABLE_PREFIX = "pre_"
|
||||||
BATCH_SIZE = 1000
|
BATCH_SIZE = 1000
|
||||||
ORIGINAL_SITE_PREFIX = "oldsite.example.com/forums" # without http(s)://
|
ORIGINAL_SITE_PREFIX = "oldsite.example.com/forums" # without http(s)://
|
||||||
@ -26,6 +26,8 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
AVATAR_DIR = "/uc_server/data/avatar"
|
AVATAR_DIR = "/uc_server/data/avatar"
|
||||||
ATTACHMENT_DIR = "/data/attachment/forum"
|
ATTACHMENT_DIR = "/data/attachment/forum"
|
||||||
AUTHORIZED_EXTENSIONS = %w[jpg jpeg png gif zip rar pdf]
|
AUTHORIZED_EXTENSIONS = %w[jpg jpeg png gif zip rar pdf]
|
||||||
|
IMPORT_UPLOADS = false
|
||||||
|
IMPORT_PASSWORDS = false
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@ -35,6 +37,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
host: "localhost",
|
host: "localhost",
|
||||||
username: "root",
|
username: "root",
|
||||||
#password: "password",
|
#password: "password",
|
||||||
|
port: "3306",
|
||||||
database: DISCUZX_DB,
|
database: DISCUZX_DB,
|
||||||
)
|
)
|
||||||
@first_post_id_by_topic_id = {}
|
@first_post_id_by_topic_id = {}
|
||||||
@ -58,7 +61,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
import_categories
|
import_categories
|
||||||
import_posts
|
import_posts
|
||||||
import_private_messages
|
import_private_messages
|
||||||
import_attachments
|
import_attachments if IMPORT_UPLOADS
|
||||||
end
|
end
|
||||||
|
|
||||||
# add the prefix to the table name
|
# add the prefix to the table name
|
||||||
@ -115,8 +118,8 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
@duplicated_email = {}
|
@duplicated_email = {}
|
||||||
results =
|
results =
|
||||||
mysql_query(
|
mysql_query(
|
||||||
"select a.uid uid, b.uid import_id from pre_common_member a
|
"select a.uid uid, b.uid import_id from #{table_name "common_member"} a
|
||||||
join (select uid, email from pre_common_member group by email having count(email) > 1 order by uid asc) b USING(email)
|
join (select uid, email from #{table_name "common_member"} group by email having count(email) > 1 order by uid asc) b USING(email)
|
||||||
where a.uid != b.uid",
|
where a.uid != b.uid",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -176,7 +179,6 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
email: user["email"],
|
email: user["email"],
|
||||||
username: user["username"],
|
username: user["username"],
|
||||||
name: first_exists(user["realname"], user["customstatus"], user["username"]),
|
name: first_exists(user["realname"], user["customstatus"], user["username"]),
|
||||||
import_pass: user["password_hash"],
|
|
||||||
active: true,
|
active: true,
|
||||||
salt: user["salt"],
|
salt: user["salt"],
|
||||||
# TODO: title: user['customstatus'], # move custom title to name since discourse can't let user custom title https://meta.discourse.org/t/let-users-custom-their-title/37626
|
# TODO: title: user['customstatus'], # move custom title to name since discourse can't let user custom title https://meta.discourse.org/t/let-users-custom-their-title/37626
|
||||||
@ -231,7 +233,8 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
),
|
),
|
||||||
post_create_action:
|
post_create_action:
|
||||||
lambda do |newmember|
|
lambda do |newmember|
|
||||||
if user["avatar_exists"] == (1) && newmember.uploaded_avatar_id.blank?
|
if user["avatar_exists"] == (1) && newmember.uploaded_avatar_id.blank? &&
|
||||||
|
IMPORT_UPLOADS
|
||||||
path, filename = discuzx_avatar_fullpath(user["id"])
|
path, filename = discuzx_avatar_fullpath(user["id"])
|
||||||
if path
|
if path
|
||||||
begin
|
begin
|
||||||
@ -306,10 +309,6 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# we don't send email to the unconfirmed user
|
|
||||||
if newmember.email_digests
|
|
||||||
newmember.update(email_digests: user["email_confirmed"] == 1)
|
|
||||||
end
|
|
||||||
if !newmember.name.blank? && newmember.name == (newmember.username)
|
if !newmember.name.blank? && newmember.name == (newmember.username)
|
||||||
newmember.update(name: "")
|
newmember.update(name: "")
|
||||||
end
|
end
|
||||||
@ -471,7 +470,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
|||||||
WHERE tid = #{m["topic_id"]}
|
WHERE tid = #{m["topic_id"]}
|
||||||
ORDER BY displayorder",
|
ORDER BY displayorder",
|
||||||
)
|
)
|
||||||
if results.empty?
|
if results.count == 0
|
||||||
puts "WARNING: can't find poll options for topic #{m["topic_id"]}, skip poll"
|
puts "WARNING: can't find poll options for topic #{m["topic_id"]}, skip poll"
|
||||||
else
|
else
|
||||||
mapped[
|
mapped[
|
||||||
|
|||||||
Reference in New Issue
Block a user