A platform for community discussion. Free, open, simple.
Improve base import script
Gerhard Schlager2834705bd167
diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rbindex 594579eafe9..56a7272a147 100644--- a/script/import_scripts/base.rb+++ b/script/import_scripts/base.rb@@ -48,6 +48,7 @@ class ImportScripts::Baseputs ""unless @skip_updates+ update_topic_statusupdate_bumped_atupdate_last_posted_atupdate_last_seen_at@@ -436,7 +437,6 @@ class ImportScripts::Basename: opts[:name],user_id: opts[:user_id] || opts[:user].try(:id) || Discourse::SYSTEM_USER_ID,position: opts[:position],- description: opts[:description],parent_category_id: opts[:parent_category_id],color: opts[:color] || "AB9364",text_color: opts[:text_color] || "FFF",@@ -446,6 +446,12 @@ class ImportScripts::Basenew_category.custom_fields["import_id"] = import_id if import_idnew_category.save!+ if opts[:description].present?+ changes = { raw: opts[:description] }+ opts = { skip_revision: true, skip_validations: true, bypass_bump: true }+ new_category.topic.first_post.revise(Discourse.system_user, changes, opts)+ end+add_category(import_id, new_category)post_create_action.try(:call, new_category)@@ -522,6 +528,13 @@ class ImportScripts::Baseopts[:custom_fields] ||= {}opts[:custom_fields]['import_id'] = import_id+ unless opts[:topic_id]+ opts[:meta_data] = meta_data = {}+ meta_data["import_closed"] = true if opts[:closed]+ meta_data["import_archived"] = true if opts[:archived]+ meta_data["import_topic_id"] = opts[:import_topic_id] if opts[:import_topic_id]+ end+opts[:guardian] = STAFF_GUARDIANif @bbcode_to_mdopts[:raw] = opts[:raw].bbcode_to_md(false) rescue opts[:raw]@@ -594,6 +607,35 @@ class ImportScripts::Baseendend+ def update_topic_status+ puts "", "updating topic status"++ Topic.exec_sql(<<~SQL)+ UPDATE topics AS t+ SET closed = TRUE+ WHERE EXISTS(+ SELECT 1+ FROM topic_custom_fields AS f+ WHERE f.topic_id = t.id AND f.name = 'import_closed' AND f.value = 't'+ )+ SQL++ Topic.exec_sql(<<~SQL)+ UPDATE topics AS t+ SET archived = TRUE+ WHERE EXISTS(+ SELECT 1+ FROM topic_custom_fields AS f+ WHERE f.topic_id = t.id AND f.name = 'import_archived' AND f.value = 't'+ )+ SQL++ TopicCustomField.exec_sql(<<~SQL)+ DELETE FROM topic_custom_fields+ WHERE name IN ('import_closed', 'import_archived')+ SQL+ end+def update_bumped_atputs "", "updating bumped_at on topics"Post.exec_sql("update topics t set bumped_at = COALESCE((select max(created_at) from posts where topic_id = t.id and post_type = #{Post.types[:regular]}), bumped_at)")