Fixes formatting to satisfy stree requirements

This commit is contained in:
pgcd 2024-11-05 06:06:54 +01:00
parent 94703182b3
commit 7c2406e9e0

View File

@ -12,7 +12,7 @@ require "open3"
class ImportScripts::Smf2 < ImportScripts::Base class ImportScripts::Smf2 < ImportScripts::Base
BATCH_SIZE ||= 5000 BATCH_SIZE ||= 5000
def self.run def self.run
options = Options.new options = Options.new
begin begin
@ -291,12 +291,12 @@ class ImportScripts::Smf2 < ImportScripts::Base
.order(:id) .order(:id)
.pluck( .pluck(
"string_agg(topic_allowed_users.user_id::text, ',' ORDER BY topic_allowed_users.user_id), title, topics.id", "string_agg(topic_allowed_users.user_id::text, ',' ORDER BY topic_allowed_users.user_id), title, topics.id",
) )
.each do |users, title, topic_id| .each do |users, title, topic_id|
@pm_mapping[users] ||= {} @pm_mapping[users] ||= {}
@pm_mapping[users][title] ||= [] @pm_mapping[users][title] ||= []
@pm_mapping[users][title] << topic_id @pm_mapping[users][title] << topic_id
end end
puts "", "Importing personal posts..." puts "", "Importing personal posts..."
@ -304,7 +304,8 @@ class ImportScripts::Smf2 < ImportScripts::Base
total = total =
query( query(
"SELECT COUNT(*) count FROM smf_personal_messages WHERE deleted_by_sender = 0", "SELECT COUNT(*) count FROM smf_personal_messages WHERE deleted_by_sender = 0",
as: :single) as: :single,
)
batches(BATCH_SIZE) do |offset| batches(BATCH_SIZE) do |offset|
posts = query(<<~SQL, as: :array) posts = query(<<~SQL, as: :array)
@ -339,18 +340,13 @@ class ImportScripts::Smf2 < ImportScripts::Base
puts id puts id
next if post_id_from_imported_post_id(id) next if post_id_from_imported_post_id(id)
post = { post = { id: id, created_at: Time.at(p[:msgtime]), user_id: user_id }
id: id,
created_at: Time.at(p[:msgtime]),
user_id: user_id,
}
begin begin
post[:raw] = convert_message_body(p[:body]) post[:raw] = convert_message_body(p[:body])
rescue StandardError rescue StandardError
post[:raw] = "-- MESSAGE SKIPPED --" post[:raw] = "-- MESSAGE SKIPPED --"
end end
users = (recipients + [user_id]).sort.uniq.join(",") users = (recipients + [user_id]).sort.uniq.join(",")
title = decode_entities(p[:subject]) title = decode_entities(p[:subject])
@ -383,7 +379,6 @@ class ImportScripts::Smf2 < ImportScripts::Base
@pm_mapping[users][title][-1] @pm_mapping[users][title][-1]
end end
def import_attachment(post, attachment) def import_attachment(post, attachment)
path = path =
find_smf_attachment_path( find_smf_attachment_path(