mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 23:31:18 +08:00
FIX: Wizard tries harder to find existing Welcome Topic
The wizard searches for: * a topic that with the "is_welcome_topic" custom field * a topic with the correct slug for the current default locale * a topic with the correct slug for the English locale * the oldest globally pinned topic It gives up if it didn't find any of the above.
This commit is contained in:
@ -22,25 +22,47 @@ class IntroductionUpdater
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def summary_from_post(post)
|
||||
return post ? post.raw.split("\n").first : nil
|
||||
end
|
||||
|
||||
def find_welcome_post
|
||||
topic_id = TopicCustomField.where(name: "is_welcome_topic").where(value: "true").pluck(:topic_id)
|
||||
unless topic_id.present?
|
||||
topic_id = Topic.listable_topics.where(slug: 'welcome-to-discourse').pluck(:id)
|
||||
topic_id = TopicCustomField
|
||||
.where(name: "is_welcome_topic", value: "true")
|
||||
.pluck(:topic_id)
|
||||
|
||||
if topic_id.blank?
|
||||
title = I18n.t("discourse_welcome_topic.title")
|
||||
topic_id = find_topic_id(title)
|
||||
end
|
||||
|
||||
if topic_id.blank?
|
||||
title = I18n.t("discourse_welcome_topic.title", locale: :en)
|
||||
topic_id = find_topic_id(title)
|
||||
end
|
||||
|
||||
if topic_id.blank?
|
||||
topic_id = Topic.listable_topics
|
||||
.where(pinned_globally: true)
|
||||
.order(:created_at)
|
||||
.limit(1)
|
||||
.pluck(:id)
|
||||
end
|
||||
|
||||
welcome_topic = Topic.where(id: topic_id).first
|
||||
return nil unless welcome_topic.present?
|
||||
return nil if welcome_topic.blank?
|
||||
|
||||
post = welcome_topic.posts.where(post_number: 1).first
|
||||
return nil unless post.present?
|
||||
|
||||
post
|
||||
welcome_topic.first_post
|
||||
end
|
||||
|
||||
def find_topic_id(topic_title)
|
||||
slug = Slug.for(topic_title, nil)
|
||||
return nil if slug.blank?
|
||||
|
||||
Topic.listable_topics
|
||||
.where(slug: slug)
|
||||
.pluck(:id)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user