mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:34:31 +08:00
Adds a rake task for refreshing posts received via email
This is useful when the email_reply_trimmer gem was updated and you want to apply those changes to existing posts.
This commit is contained in:
@ -238,3 +238,27 @@ task 'posts:defer_all_flags' => :environment do
|
||||
|
||||
puts "", "#{flags_deferred} flags deferred!", ""
|
||||
end
|
||||
|
||||
desc 'Refreshes each post that was received via email'
|
||||
task 'posts:refresh_emails', [:topic_id] => [:environment] do |_, args|
|
||||
posts = Post.where.not(raw_email: nil).where(via_email: true)
|
||||
posts = posts.where(topic_id: args[:topic_id]) if args[:topic_id]
|
||||
|
||||
updated = 0
|
||||
total = posts.count
|
||||
|
||||
posts.find_each do |post|
|
||||
receiver = Email::Receiver.new(post.raw_email)
|
||||
|
||||
body, elided = receiver.select_body
|
||||
body = receiver.add_attachments(body || '', post.user_id)
|
||||
body << Email::Receiver.elided_html(elided) if elided.present?
|
||||
|
||||
post.revise(Discourse.system_user, { raw: body }, skip_revision: true, skip_validations: true)
|
||||
updated += 1
|
||||
|
||||
print_status(updated, total)
|
||||
end
|
||||
|
||||
puts "", "Done. #{updated} posts updated.", ""
|
||||
end
|
||||
|
Reference in New Issue
Block a user