mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-04-29 15:45:23 +08:00
When localizing a pinned topic, the excerpt shown in the topic list wasn't updating - only the title would change when switching languages. This was because the `TopicLocalization.excerpt` field was not being updated. The excerpt needs to be set in two scenarios depending on which gets created first: - When a post localization is created/updated for the first post, update the topic localization's excerpt - When a topic localization is created and a post localization already exists, populate the excerpt from it Meta: https://meta.discourse.org/t/localizing-topic-does-not-seem-to-localize-excerpt-pinned-on-topic-list/392232
31 lines
776 B
Ruby
31 lines
776 B
Ruby
# frozen_string_literal: true
|
|
|
|
class TopicLocalizationCreator
|
|
def self.create(topic:, locale:, title:, user:)
|
|
Guardian.new(user).ensure_can_localize_topic!(topic)
|
|
|
|
excerpt = nil
|
|
first_post = topic.first_post
|
|
if first_post
|
|
post_localization = first_post.localizations.find_by(locale:)
|
|
if post_localization
|
|
excerpt =
|
|
Post.excerpt(
|
|
post_localization.cooked,
|
|
SiteSetting.topic_excerpt_maxlength,
|
|
strip_links: true,
|
|
strip_images: true,
|
|
)
|
|
end
|
|
end
|
|
|
|
TopicLocalization.create!(
|
|
topic_id: topic.id,
|
|
locale: locale,
|
|
title: title,
|
|
fancy_title: Topic.fancy_title(title),
|
|
localizer_user_id: user.id,
|
|
excerpt: excerpt,
|
|
)
|
|
end
|
|
end
|