From 802ad0dc617b26b4c8b5cb329d629bb3d5c68f0b Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 16 Aug 2018 19:51:06 +0200 Subject: [PATCH] Add rake task for updating static pages --- lib/tasks/topics.rake | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/tasks/topics.rake b/lib/tasks/topics.rake index bbbf56ac79..e9720e76f6 100644 --- a/lib/tasks/topics.rake +++ b/lib/tasks/topics.rake @@ -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