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