mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 15:49:55 +08:00
DEV: Apply code format to import script (#25063)
This commit is contained in:
parent
050a285f40
commit
d7601388e5
|
@ -1,5 +1,4 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# (c) 2023 Intevation GmbH
|
|
||||||
|
|
||||||
require "pg"
|
require "pg"
|
||||||
|
|
||||||
|
@ -33,7 +32,9 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
def import_users
|
def import_users
|
||||||
puts "", "creating users"
|
puts "", "creating users"
|
||||||
|
|
||||||
total_count = @client.exec("
|
total_count =
|
||||||
|
@client.exec(
|
||||||
|
"
|
||||||
WITH relevant_posts AS (
|
WITH relevant_posts AS (
|
||||||
SELECT DISTINCT posted_by FROM forum
|
SELECT DISTINCT posted_by FROM forum
|
||||||
)
|
)
|
||||||
|
@ -41,7 +42,10 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
COUNT(DISTINCT user_id) AS count
|
COUNT(DISTINCT user_id) AS count
|
||||||
FROM users u
|
FROM users u
|
||||||
JOIN relevant_posts f on u.user_id = f.posted_by
|
JOIN relevant_posts f on u.user_id = f.posted_by
|
||||||
").first["count"]
|
",
|
||||||
|
).first[
|
||||||
|
"count"
|
||||||
|
]
|
||||||
|
|
||||||
batches(BATCH_SIZE) do |offset|
|
batches(BATCH_SIZE) do |offset|
|
||||||
results =
|
results =
|
||||||
|
@ -56,7 +60,7 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
JOIN relevant_posts f on u.user_id = f.posted_by
|
JOIN relevant_posts f on u.user_id = f.posted_by
|
||||||
LIMIT #{BATCH_SIZE}
|
LIMIT #{BATCH_SIZE}
|
||||||
OFFSET #{offset};",
|
OFFSET #{offset};",
|
||||||
)
|
)
|
||||||
|
|
||||||
break if results.ntuples < 1
|
break if results.ntuples < 1
|
||||||
|
|
||||||
|
@ -69,13 +73,13 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
email: user["email"],
|
email: user["email"],
|
||||||
username: user["user_name"],
|
username: user["user_name"],
|
||||||
name: user["name"],
|
name: user["name"],
|
||||||
active: user["status"] == 'A' && user["unix_pw"] != 'deleted',
|
active: user["status"] == "A" && user["unix_pw"] != "deleted",
|
||||||
created_at: Time.zone.at(user["add_date"].to_i),
|
created_at: Time.zone.at(user["add_date"].to_i),
|
||||||
last_emailed_at: nil, # default is "now", which is not true
|
last_emailed_at: nil, # default is "now", which is not true
|
||||||
approved: true,
|
approved: true,
|
||||||
# for https://github.com/communiteq/discourse-migratepassword/
|
# for https://github.com/communiteq/discourse-migratepassword/
|
||||||
# this field results in custom_fields['import_pass']. This also activates the accounts, see base.rb on `u.activate`.
|
# this field results in custom_fields['import_pass']. This also activates the accounts, see base.rb on `u.activate`.
|
||||||
password: user["unix_pw"] != 'deleted' ? user["unix_pw"] : nil,
|
password: user["unix_pw"] != "deleted" ? user["unix_pw"] : nil,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -94,7 +98,9 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
",
|
",
|
||||||
).to_a
|
).to_a
|
||||||
|
|
||||||
create_categories(categories) { |category| { id: category["group_id"], name: category["group_name"] } }
|
create_categories(categories) do |category|
|
||||||
|
{ id: category["group_id"], name: category["group_name"] }
|
||||||
|
end
|
||||||
|
|
||||||
puts "", "importing forums..."
|
puts "", "importing forums..."
|
||||||
|
|
||||||
|
@ -174,11 +180,14 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
def import_attachments
|
def import_attachments
|
||||||
puts "", "importing attachments..."
|
puts "", "importing attachments..."
|
||||||
|
|
||||||
uploads = @client.exec("
|
uploads =
|
||||||
|
@client.exec(
|
||||||
|
"
|
||||||
SELECT msg_id, filename, attachmentid
|
SELECT msg_id, filename, attachmentid
|
||||||
FROM forum_attachment
|
FROM forum_attachment
|
||||||
order by msg_id
|
order by msg_id
|
||||||
").to_a
|
",
|
||||||
|
).to_a
|
||||||
|
|
||||||
current_count = 0
|
current_count = 0
|
||||||
total_count = uploads.count
|
total_count = uploads.count
|
||||||
|
@ -198,13 +207,9 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
|
|
||||||
file_hex = sprintf("%x", upload["attachmentid"])
|
file_hex = sprintf("%x", upload["attachmentid"])
|
||||||
prefix = file_hex[-2..-1]
|
prefix = file_hex[-2..-1]
|
||||||
if not prefix
|
prefix = file_hex if not prefix
|
||||||
prefix = file_hex
|
|
||||||
end
|
|
||||||
postfix = file_hex[0..-3].to_s
|
postfix = file_hex[0..-3].to_s
|
||||||
if postfix == ''
|
postfix = "0" if postfix == ""
|
||||||
postfix = '0'
|
|
||||||
end
|
|
||||||
filename = File.join("/tmp/var/lib/fusionforge/forum/", prefix, "/", postfix)
|
filename = File.join("/tmp/var/lib/fusionforge/forum/", prefix, "/", postfix)
|
||||||
|
|
||||||
upl_obj = create_upload(post.user.id, filename, real_filename)
|
upl_obj = create_upload(post.user.id, filename, real_filename)
|
||||||
|
@ -231,7 +236,6 @@ class ImportScripts::FusionForge < ImportScripts::Base
|
||||||
print_status(current_count, total_count)
|
print_status(current_count, total_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ImportScripts::FusionForge.new.perform
|
ImportScripts::FusionForge.new.perform
|
||||||
|
|
Loading…
Reference in New Issue
Block a user