Add rake task for updating static pages
This commit is contained in:
parent
98898ff4b3
commit
802ad0dc61
|
@ -64,3 +64,36 @@ task "topics:apply_autoclose" => :environment do
|
|||
|
||||
puts "", "Done"
|
||||
end
|
||||
|
||||
def update_static_page_topic(locale, site_setting_key, title_key, body_key, params = {})
|
||||
topic = Topic.find(SiteSetting.send(site_setting_key))
|
||||
|
||||
if (topic && post = topic.first_post)
|
||||
post.revise(Discourse.system_user,
|
||||
title: I18n.t(title_key, locale: locale),
|
||||
raw: I18n.t(body_key, params.merge(locale: locale)))
|
||||
|
||||
puts "", "Topic for #{site_setting_key} updated"
|
||||
else
|
||||
puts "", "Topic for #{site_setting_key} not found"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Update static topics (ToS, Privacy, Guidelines) with latest translated content"
|
||||
task "topics:update_static", [:locale] => [:environment] do |_, args|
|
||||
locale = args[:locale]&.to_sym
|
||||
|
||||
if locale.blank? || !I18n.locale_available?(locale)
|
||||
puts "ERROR: Expecting rake topics:update_static[locale]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
update_static_page_topic(locale, "tos_topic_id", "tos_topic.title", "tos_topic.body",
|
||||
company_domain: SiteSetting.company_domain.presence || "company_domain",
|
||||
company_full_name: SiteSetting.company_full_name.presence || "company_full_name",
|
||||
company_name: SiteSetting.company_short_name.presence || "company_short_name")
|
||||
|
||||
update_static_page_topic(locale, "guidelines_topic_id", "guidelines_topic.title", "guidelines_topic.body")
|
||||
|
||||
update_static_page_topic(locale, "privacy_topic_id", "privacy_topic.title", "privacy_topic.body")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue