FEATURE: export/import topics and categories from one Discourse site to another. (Early-access alpha greenlight. More to do...)

This commit is contained in:
Neil Lalonde
2016-01-25 13:37:43 -05:00
parent 0337964759
commit 58610d15a1
6 changed files with 346 additions and 0 deletions

View File

@ -134,12 +134,57 @@ class DiscourseCLI < Thor
puts 'Requests sent. Clients will refresh on next navigation.'
end
desc "export_category", "Export a category, all its topics, and all users who posted in those topics"
def export_category(category_id)
raise "Category id argument is missing!" unless category_id
load_rails
load_import_export
ImportExport.export_category(category_id)
puts "", "Done", ""
end
desc "import_category", "Import a category, its topics and the users from the output of the export_category command"
def import_category(filename)
raise "File name argument missing!" unless filename
puts "Starting import from #{filename}..."
load_rails
load_import_export
ImportExport.import_category(filename)
puts "", "Done", ""
end
desc "export_topics", "Export topics and all users who posted in that topic. Accepts multiple topic id's"
def export_topics(*topic_ids)
puts "Starting export of topics...", ""
load_rails
load_import_export
ImportExport.export_topics(topic_ids)
puts "", "Done", ""
end
desc "import_topics", "Import topics and their users from the output of the export_topic command"
def import_topics(filename)
raise "File name argument missing!" unless filename
puts "Starting import from #{filename}..."
load_rails
load_import_export
ImportExport.import_topics(filename)
puts "", "Done", ""
end
private
def load_rails
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
end
def load_import_export
require File.expand_path(File.dirname(__FILE__) + "/../lib/import_export/import_export")
end
def do_remap(from, to)
sql = "SELECT table_name, column_name
FROM information_schema.columns