2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-14 14:44:43 -05:00
|
|
|
require 'csv'
|
2015-07-05 17:17:03 -04:00
|
|
|
require 'yaml'
|
2021-01-14 14:44:43 -05:00
|
|
|
require_relative '../../base'
|
2015-07-05 17:17:03 -04:00
|
|
|
|
|
|
|
module ImportScripts::PhpBB3
|
|
|
|
class Settings
|
|
|
|
def self.load(filename)
|
|
|
|
yaml = YAML::load_file(filename)
|
2021-01-14 14:44:43 -05:00
|
|
|
Settings.new(yaml.deep_stringify_keys.with_indifferent_access)
|
2015-07-05 17:17:03 -04:00
|
|
|
end
|
|
|
|
|
2021-01-14 14:44:43 -05:00
|
|
|
attr_reader :site_name
|
|
|
|
|
|
|
|
attr_reader :new_categories
|
|
|
|
attr_reader :category_mappings
|
|
|
|
attr_reader :tag_mappings
|
|
|
|
attr_reader :rank_mapping
|
|
|
|
|
2015-07-05 17:17:03 -04:00
|
|
|
attr_reader :import_anonymous_users
|
|
|
|
attr_reader :import_attachments
|
|
|
|
attr_reader :import_private_messages
|
|
|
|
attr_reader :import_polls
|
|
|
|
attr_reader :import_bookmarks
|
2015-08-20 16:15:57 -04:00
|
|
|
attr_reader :import_passwords
|
2015-07-05 17:17:03 -04:00
|
|
|
|
|
|
|
attr_reader :import_uploaded_avatars
|
|
|
|
attr_reader :import_remote_avatars
|
|
|
|
attr_reader :import_gallery_avatars
|
|
|
|
|
|
|
|
attr_reader :use_bbcode_to_md
|
|
|
|
|
|
|
|
attr_reader :original_site_prefix
|
|
|
|
attr_reader :new_site_prefix
|
|
|
|
attr_reader :base_dir
|
2016-04-09 16:36:45 -04:00
|
|
|
attr_reader :permalinks
|
2015-07-05 17:17:03 -04:00
|
|
|
|
|
|
|
attr_reader :username_as_name
|
|
|
|
attr_reader :emojis
|
|
|
|
|
|
|
|
attr_reader :database
|
|
|
|
|
|
|
|
def initialize(yaml)
|
|
|
|
import_settings = yaml['import']
|
2021-01-14 14:44:43 -05:00
|
|
|
|
|
|
|
@site_name = import_settings['site_name']
|
|
|
|
|
|
|
|
@new_categories = import_settings['new_categories']
|
|
|
|
@category_mappings = import_settings['category_mappings']
|
|
|
|
@tag_mappings = import_settings['tag_mappings']
|
|
|
|
@rank_mapping = import_settings['rank_mapping']
|
|
|
|
|
2015-07-05 17:17:03 -04:00
|
|
|
@import_anonymous_users = import_settings['anonymous_users']
|
|
|
|
@import_attachments = import_settings['attachments']
|
|
|
|
@import_private_messages = import_settings['private_messages']
|
|
|
|
@import_polls = import_settings['polls']
|
|
|
|
@import_bookmarks = import_settings['bookmarks']
|
2015-08-20 16:15:57 -04:00
|
|
|
@import_passwords = import_settings['passwords']
|
2015-07-05 17:17:03 -04:00
|
|
|
|
|
|
|
avatar_settings = import_settings['avatars']
|
|
|
|
@import_uploaded_avatars = avatar_settings['uploaded']
|
|
|
|
@import_remote_avatars = avatar_settings['remote']
|
|
|
|
@import_gallery_avatars = avatar_settings['gallery']
|
|
|
|
|
|
|
|
@use_bbcode_to_md = import_settings['use_bbcode_to_md']
|
|
|
|
|
|
|
|
@original_site_prefix = import_settings['site_prefix']['original']
|
|
|
|
@new_site_prefix = import_settings['site_prefix']['new']
|
|
|
|
@base_dir = import_settings['phpbb_base_dir']
|
2016-04-09 16:36:45 -04:00
|
|
|
@permalinks = PermalinkSettings.new(import_settings['permalinks'])
|
2015-07-05 17:17:03 -04:00
|
|
|
|
|
|
|
@username_as_name = import_settings['username_as_name']
|
|
|
|
@emojis = import_settings.fetch('emojis', [])
|
|
|
|
|
|
|
|
@database = DatabaseSettings.new(yaml['database'])
|
|
|
|
end
|
2021-01-14 14:44:43 -05:00
|
|
|
|
|
|
|
def prefix(val)
|
|
|
|
@site_name.present? && val.present? ? "#{@site_name}:#{val}" : val
|
|
|
|
end
|
|
|
|
|
|
|
|
def trust_level_for_posts(rank, trust_level: 0)
|
|
|
|
if @rank_mapping.present?
|
|
|
|
@rank_mapping.each do |key, value|
|
|
|
|
trust_level = [trust_level, key.gsub('trust_level_', '').to_i].max if rank >= value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trust_level
|
|
|
|
end
|
2015-07-05 17:17:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class DatabaseSettings
|
|
|
|
attr_reader :type
|
|
|
|
attr_reader :host
|
2016-03-29 14:45:23 -04:00
|
|
|
attr_reader :port
|
2015-07-05 17:17:03 -04:00
|
|
|
attr_reader :username
|
|
|
|
attr_reader :password
|
|
|
|
attr_reader :schema
|
|
|
|
attr_reader :table_prefix
|
|
|
|
attr_reader :batch_size
|
|
|
|
|
|
|
|
def initialize(yaml)
|
|
|
|
@type = yaml['type']
|
|
|
|
@host = yaml['host']
|
2016-03-29 14:45:23 -04:00
|
|
|
@port = yaml['port']
|
2015-07-05 17:17:03 -04:00
|
|
|
@username = yaml['username']
|
|
|
|
@password = yaml['password']
|
|
|
|
@schema = yaml['schema']
|
|
|
|
@table_prefix = yaml['table_prefix']
|
|
|
|
@batch_size = yaml['batch_size']
|
|
|
|
end
|
|
|
|
end
|
2016-04-09 16:36:45 -04:00
|
|
|
|
|
|
|
class PermalinkSettings
|
|
|
|
attr_reader :create_category_links
|
|
|
|
attr_reader :create_topic_links
|
|
|
|
attr_reader :create_post_links
|
2019-02-17 17:20:20 -05:00
|
|
|
attr_reader :normalization_prefix
|
2016-04-09 16:36:45 -04:00
|
|
|
|
|
|
|
def initialize(yaml)
|
|
|
|
@create_category_links = yaml['categories']
|
|
|
|
@create_topic_links = yaml['topics']
|
|
|
|
@create_post_links = yaml['posts']
|
2019-02-17 17:20:20 -05:00
|
|
|
@normalization_prefix = yaml['prefix']
|
2016-04-09 16:36:45 -04:00
|
|
|
end
|
|
|
|
end
|
2015-07-05 17:17:03 -04:00
|
|
|
end
|