A platform for community discussion. Free, open, simple.
Add rake task for updating static pages
Gerhard Schlager802ad0dc617b
diff --git a/lib/tasks/topics.rake b/lib/tasks/topics.rakeindex bbbf56ac797..e9720e76f64 100644--- a/lib/tasks/topics.rake+++ b/lib/tasks/topics.rake@@ -64,3 +64,36 @@ task "topics:apply_autoclose" => :environment doputs "", "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