2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-26 15:29:36 -05:00
|
|
|
require "import_export/importer"
|
2019-10-01 23:50:54 -05:00
|
|
|
require "import_export/base_exporter"
|
2017-10-26 15:29:36 -05:00
|
|
|
require "import_export/category_structure_exporter"
|
2016-01-25 12:37:43 -06:00
|
|
|
require "import_export/category_exporter"
|
|
|
|
require "import_export/topic_exporter"
|
2020-04-17 16:59:54 -05:00
|
|
|
require "import_export/group_exporter"
|
2016-01-25 12:37:43 -06:00
|
|
|
require "json"
|
|
|
|
|
|
|
|
module ImportExport
|
|
|
|
|
2017-10-26 15:29:36 -05: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 12:37:43 -06:00
|
|
|
end
|
|
|
|
|
2017-11-11 07:22:22 -06:00
|
|
|
def self.export_category_structure(include_users, filename = nil)
|
2017-10-26 15:29:36 -05:00
|
|
|
ImportExport::CategoryStructureExporter.new(include_users).perform.save_to_file(filename)
|
2016-01-25 12:37:43 -06:00
|
|
|
end
|
|
|
|
|
2017-11-11 07:22:22 -06:00
|
|
|
def self.export_categories(category_ids, filename = nil)
|
|
|
|
ImportExport::CategoryExporter.new(category_ids).perform.save_to_file(filename)
|
2016-01-25 12:37:43 -06:00
|
|
|
end
|
|
|
|
|
2017-10-26 15:29:36 -05:00
|
|
|
def self.export_topics(topic_ids, filename = nil)
|
|
|
|
ImportExport::TopicExporter.new(topic_ids).perform.save_to_file(filename)
|
2016-01-25 12:37:43 -06:00
|
|
|
end
|
2017-10-26 15:29:36 -05:00
|
|
|
|
2020-04-17 16:59:54 -05:00
|
|
|
def self.export_groups(include_users, filename = nil)
|
|
|
|
ImportExport::GroupExporter.new(include_users).perform.save_to_file(filename)
|
|
|
|
end
|
|
|
|
|
2016-01-25 12:37:43 -06:00
|
|
|
end
|