mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
made postprocessing of posts with delay quotes conversion resumable
This commit is contained in:
parent
7b5e6ff744
commit
f40510b93e
@ -61,6 +61,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
|||||||
import_users
|
import_users
|
||||||
import_categories
|
import_categories
|
||||||
import_posts
|
import_posts
|
||||||
|
postprocess_posts
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_groups
|
def import_groups
|
||||||
@ -224,7 +225,6 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
|||||||
print "\r#{spinner.next}"
|
print "\r#{spinner.next}"
|
||||||
end
|
end
|
||||||
|
|
||||||
postprocess = []
|
|
||||||
create_posts(query(<<-SQL), total: total) do |message|
|
create_posts(query(<<-SQL), total: total) do |message|
|
||||||
SELECT m.id_msg, m.id_topic, m.id_member, m.poster_time, m.body, o.ignore_quotes,
|
SELECT m.id_msg, m.id_topic, m.id_member, m.poster_time, m.body, o.ignore_quotes,
|
||||||
m.subject, t.id_board, t.id_first_msg
|
m.subject, t.id_board, t.id_first_msg
|
||||||
@ -234,12 +234,16 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
|||||||
ORDER BY o.message_order ASC
|
ORDER BY o.message_order ASC
|
||||||
SQL
|
SQL
|
||||||
skip = false
|
skip = false
|
||||||
|
ignore_quotes = (message[:ignore_quotes] == 1)
|
||||||
post = {
|
post = {
|
||||||
id: message[:id_msg],
|
id: message[:id_msg],
|
||||||
user_id: user_id_from_imported_user_id(message[:id_member]) || -1,
|
user_id: user_id_from_imported_user_id(message[:id_member]) || -1,
|
||||||
raw: convert_message_body(message[:body], ignore_quotes: message[:ignore_quotes] == 1),
|
raw: convert_message_body(message[:body], ignore_quotes: ignore_quotes),
|
||||||
created_at: Time.zone.at(message[:poster_time]),
|
created_at: Time.zone.at(message[:poster_time]),
|
||||||
post_create_action: proc {|post| postprocess << post }
|
post_create_action: ignore_quotes && proc do |post|
|
||||||
|
post.custom_fields['import_rebake'] = 't'
|
||||||
|
post.save
|
||||||
|
end
|
||||||
}
|
}
|
||||||
if message[:id_msg] == message[:id_first_msg]
|
if message[:id_msg] == message[:id_first_msg]
|
||||||
post[:category] = category_from_imported_category_id(message[:id_board]).try(:name)
|
post[:category] = category_from_imported_category_id(message[:id_board]).try(:name)
|
||||||
@ -255,11 +259,24 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
|||||||
end
|
end
|
||||||
skip ? nil : post
|
skip ? nil : post
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
postprocess.each do |post|
|
def postprocess_posts
|
||||||
|
puts '', 'rebaking posts'
|
||||||
|
|
||||||
|
tags = PostCustomField.where(name: 'import_rebake', value: 't')
|
||||||
|
tags_total = tags.count
|
||||||
|
tags_done = 0
|
||||||
|
|
||||||
|
tags.each do |tag|
|
||||||
|
post = tag.post
|
||||||
|
Post.transaction do
|
||||||
post.raw = convert_quotes(post.raw)
|
post.raw = convert_quotes(post.raw)
|
||||||
post.rebake!
|
post.rebake!
|
||||||
post.save!(validate: false)
|
post.save
|
||||||
|
tag.destroy!
|
||||||
|
end
|
||||||
|
print_status(tags_done += 1, tags_total)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user