mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
REFACTOR: upload workflow creation into UploadCreator
- Automatically convert large-ish PNG/BMP to JPEG - Updated fast_image to latest version
This commit is contained in:
@ -9,7 +9,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
|
||||
# CHANGE THESE BEFORE RUNNING THE IMPORTER
|
||||
DATABASE = "yourforum"
|
||||
TIMEZONE = "America/Los_Angeles"
|
||||
TIMEZONE = "America/Los_Angeles"
|
||||
ATTACHMENT_DIR = '/home/discourse/yourforum/customattachments/'
|
||||
AVATAR_DIR = '/home/discourse/yourforum/avatars/'
|
||||
|
||||
@ -25,7 +25,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
@client = Mysql2::Client.new(
|
||||
host: "localhost",
|
||||
username: "root",
|
||||
database: DATABASE,
|
||||
database: DATABASE,
|
||||
password: "password"
|
||||
)
|
||||
|
||||
@ -123,7 +123,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
file = Tempfile.new("profile-picture")
|
||||
file.write(picture["filedata"].encode("ASCII-8BIT").force_encoding("UTF-8"))
|
||||
file.rewind
|
||||
upload = Upload.create_for(imported_user.id, file, picture["filename"], file.size)
|
||||
upload = UploadCreator.new(file, picture["filename"]).create_for(imported_user.id)
|
||||
else
|
||||
filename = File.join(AVATAR_DIR, picture['filename'])
|
||||
unless File.exists?(filename)
|
||||
@ -160,7 +160,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
file.write(background["filedata"].encode("ASCII-8BIT").force_encoding("UTF-8"))
|
||||
file.rewind
|
||||
|
||||
upload = Upload.create_for(imported_user.id, file, background["filename"], file.size)
|
||||
upload = UploadCreator.new(file, background["filename"]).create_for(imported_user.id)
|
||||
|
||||
return if !upload.persisted?
|
||||
|
||||
@ -173,13 +173,13 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
def import_categories
|
||||
puts "", "importing top level categories..."
|
||||
|
||||
categories = mysql_query("SELECT nodeid AS forumid, title, description, displayorder, parentid
|
||||
FROM #{DBPREFIX}node
|
||||
WHERE parentid=#{ROOT_NODE}
|
||||
UNION
|
||||
SELECT nodeid, title, description, displayorder, parentid
|
||||
FROM #{DBPREFIX}node
|
||||
WHERE contenttypeid = 23
|
||||
categories = mysql_query("SELECT nodeid AS forumid, title, description, displayorder, parentid
|
||||
FROM #{DBPREFIX}node
|
||||
WHERE parentid=#{ROOT_NODE}
|
||||
UNION
|
||||
SELECT nodeid, title, description, displayorder, parentid
|
||||
FROM #{DBPREFIX}node
|
||||
WHERE contenttypeid = 23
|
||||
AND parentid IN (SELECT nodeid FROM #{DBPREFIX}node WHERE parentid=#{ROOT_NODE})").to_a
|
||||
|
||||
top_level_categories = categories.select { |c| c["parentid"] == ROOT_NODE }
|
||||
@ -222,17 +222,17 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
# keep track of closed topics
|
||||
@closed_topic_ids = []
|
||||
|
||||
topic_count = mysql_query("select count(nodeid) cnt from #{DBPREFIX}node where parentid in (
|
||||
topic_count = mysql_query("select count(nodeid) cnt from #{DBPREFIX}node where parentid in (
|
||||
select nodeid from #{DBPREFIX}node where contenttypeid=23 ) and contenttypeid=22;").first["cnt"]
|
||||
|
||||
batches(BATCH_SIZE) do |offset|
|
||||
topics = mysql_query <<-SQL
|
||||
SELECT t.nodeid AS threadid, t.title, t.parentid AS forumid,t.open,t.userid AS postuserid,t.publishdate AS dateline,
|
||||
nv.count views, 1 AS visible, t.sticky,
|
||||
nv.count views, 1 AS visible, t.sticky,
|
||||
CONVERT(CAST(rawtext AS BINARY)USING utf8) AS raw
|
||||
FROM #{DBPREFIX}node t
|
||||
LEFT JOIN #{DBPREFIX}nodeview nv ON nv.nodeid=t.nodeid
|
||||
LEFT JOIN #{DBPREFIX}text txt ON txt.nodeid=t.nodeid
|
||||
FROM #{DBPREFIX}node t
|
||||
LEFT JOIN #{DBPREFIX}nodeview nv ON nv.nodeid=t.nodeid
|
||||
LEFT JOIN #{DBPREFIX}text txt ON txt.nodeid=t.nodeid
|
||||
WHERE t.parentid in ( select nodeid from #{DBPREFIX}node where contenttypeid=23 )
|
||||
AND t.contenttypeid = 22
|
||||
ORDER BY t.nodeid
|
||||
@ -275,17 +275,17 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
rescue
|
||||
end
|
||||
|
||||
post_count = mysql_query("SELECT COUNT(nodeid) cnt FROM #{DBPREFIX}node WHERE parentid NOT IN (
|
||||
post_count = mysql_query("SELECT COUNT(nodeid) cnt FROM #{DBPREFIX}node WHERE parentid NOT IN (
|
||||
SELECT nodeid FROM #{DBPREFIX}node WHERE contenttypeid=23 ) AND contenttypeid=22;").first["cnt"]
|
||||
|
||||
batches(BATCH_SIZE) do |offset|
|
||||
posts = mysql_query <<-SQL
|
||||
SELECT p.nodeid AS postid, p.userid AS userid, p.parentid AS threadid,
|
||||
SELECT p.nodeid AS postid, p.userid AS userid, p.parentid AS threadid,
|
||||
CONVERT(CAST(rawtext AS BINARY)USING utf8) AS raw, p.publishdate AS dateline,
|
||||
1 AS visible, p.parentid AS parentid
|
||||
FROM #{DBPREFIX}node p
|
||||
LEFT JOIN #{DBPREFIX}nodeview nv ON nv.nodeid=p.nodeid
|
||||
LEFT JOIN #{DBPREFIX}text txt ON txt.nodeid=p.nodeid
|
||||
FROM #{DBPREFIX}node p
|
||||
LEFT JOIN #{DBPREFIX}nodeview nv ON nv.nodeid=p.nodeid
|
||||
LEFT JOIN #{DBPREFIX}text txt ON txt.nodeid=p.nodeid
|
||||
WHERE p.parentid NOT IN ( select nodeid from #{DBPREFIX}node where contenttypeid=23 )
|
||||
AND p.contenttypeid = 22
|
||||
ORDER BY postid
|
||||
@ -299,7 +299,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
# next if all_records_exist? :posts, posts.map {|p| p["postid"] }
|
||||
|
||||
create_posts(posts, total: post_count, offset: offset) do |post|
|
||||
raw = preprocess_post_raw(post["raw"])
|
||||
raw = preprocess_post_raw(post["raw"])
|
||||
next if raw.blank?
|
||||
next unless topic = topic_lookup_from_imported_post_id("thread-#{post["threadid"]}")
|
||||
p = {
|
||||
@ -336,7 +336,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
|
||||
real_filename.prepend SecureRandom.hex if real_filename[0] == '.'
|
||||
|
||||
unless File.exists?(filename)
|
||||
if row['dbsize'].to_i == 0
|
||||
if row['dbsize'].to_i == 0
|
||||
puts "Attachment file #{row['filedataid']} doesn't exist"
|
||||
return nil
|
||||
end
|
||||
|
Reference in New Issue
Block a user