2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-26 16:29:36 -04:00
|
|
|
require "import_export/importer"
|
|
|
|
require "import_export/category_structure_exporter"
|
2016-01-25 13:37:43 -05:00
|
|
|
require "import_export/category_exporter"
|
|
|
|
require "import_export/topic_exporter"
|
|
|
|
require "json"
|
|
|
|
|
|
|
|
module ImportExport
|
|
|
|
|
2017-10-26 16:29:36 -04:00
|
|
|
def self.import(filename)
|
|
|
|
data = ActiveSupport::HashWithIndifferentAccess.new(File.open(filename, "r:UTF-8") { |f| JSON.parse(f.read) })
|
|
|
|
ImportExport::Importer.new(data).perform
|
2016-01-25 13:37:43 -05:00
|
|
|
end
|
|
|
|
|
2017-11-11 08:22:22 -05:00
|
|
|
def self.export_category_structure(include_users, filename = nil)
|
2017-10-26 16:29:36 -04:00
|
|
|
ImportExport::CategoryStructureExporter.new(include_users).perform.save_to_file(filename)
|
2016-01-25 13:37:43 -05:00
|
|
|
end
|
|
|
|
|
2017-11-11 08:22:22 -05:00
|
|
|
def self.export_categories(category_ids, filename = nil)
|
|
|
|
ImportExport::CategoryExporter.new(category_ids).perform.save_to_file(filename)
|
2016-01-25 13:37:43 -05:00
|
|
|
end
|
|
|
|
|
2017-10-26 16:29:36 -04:00
|
|
|
def self.export_topics(topic_ids, filename = nil)
|
|
|
|
ImportExport::TopicExporter.new(topic_ids).perform.save_to_file(filename)
|
2016-01-25 13:37:43 -05:00
|
|
|
end
|
2017-10-26 16:29:36 -04:00
|
|
|
|
2016-01-25 13:37:43 -05:00
|
|
|
end
|