discourse/app/jobs/regular/process_localized_cooked.rb
Natalie Tay 3f8ccda7aa
FEATURE: Allow post authors to localize their own posts (#36178)
We should allow authors to localize their own content.

This is gated behind the
`content_localization_allow_author_localization` setting, which is
enabled by default.

Meta:
https://meta.discourse.org/t/feature-request-allow-users-to-localize-only-their-own-topics/389147
2025-11-25 11:02:22 +08:00

25 lines
814 B
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class ProcessLocalizedCooked < ::Jobs::Base
def execute(args)
DistributedMutex.synchronize(
"process_localized_cook_#{args[:post_localization_id]}",
validity: 10.minutes,
) do
post_localization = PostLocalization.find_by(id: args[:post_localization_id])
return if post_localization.blank?
post = post_localization.post
return if post.blank? || post.topic.blank?
processor = LocalizedCookedPostProcessor.new(post_localization, post, {})
processor.post_process
cooked = processor.html.strip
post_localization.update_column(:cooked, cooked) if cooked.present?
MessageBus.publish("/topic/#{post.topic_id}", type: :localized, id: post.id)
end
end
end
end