2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-05 17:17:03 -04:00
|
|
|
require 'mysql2'
|
|
|
|
|
|
|
|
module ImportScripts::PhpBB3
|
|
|
|
class Database
|
|
|
|
# @param database_settings [ImportScripts::PhpBB3::DatabaseSettings]
|
|
|
|
def self.create(database_settings)
|
|
|
|
Database.new(database_settings).create_database
|
|
|
|
end
|
|
|
|
|
|
|
|
# @param database_settings [ImportScripts::PhpBB3::DatabaseSettings]
|
|
|
|
def initialize(database_settings)
|
|
|
|
@database_settings = database_settings
|
|
|
|
@database_client = create_database_client
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [ImportScripts::PhpBB3::Database_3_0 | ImportScripts::PhpBB3::Database_3_1]
|
|
|
|
def create_database
|
|
|
|
version = get_phpbb_version
|
|
|
|
|
|
|
|
if version.start_with?('3.0')
|
|
|
|
require_relative 'database_3_0'
|
|
|
|
Database_3_0.new(@database_client, @database_settings)
|
2022-07-25 16:07:03 -04:00
|
|
|
elsif version.start_with?('3.1') || version.start_with?('3.2') || version.start_with?('3.3')
|
2015-07-05 17:17:03 -04:00
|
|
|
require_relative 'database_3_1'
|
|
|
|
Database_3_1.new(@database_client, @database_settings)
|
|
|
|
else
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
raise UnsupportedVersionError, <<~TEXT
|
2019-05-30 16:20:57 -04:00
|
|
|
Unsupported version (#{version}) of phpBB detected.
|
2022-07-25 16:07:03 -04:00
|
|
|
Currently only version 3.0, 3.1, 3.2 and 3.3 are supported by this importer.
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
TEXT
|
2015-07-05 17:17:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def create_database_client
|
|
|
|
Mysql2::Client.new(
|
|
|
|
host: @database_settings.host,
|
2016-03-29 14:45:23 -04:00
|
|
|
port: @database_settings.port,
|
2015-07-05 17:17:03 -04:00
|
|
|
username: @database_settings.username,
|
|
|
|
password: @database_settings.password,
|
2016-07-11 17:59:15 -04:00
|
|
|
database: @database_settings.schema,
|
|
|
|
reconnect: true
|
2015-07-05 17:17:03 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_phpbb_version
|
|
|
|
table_prefix = @database_settings.table_prefix
|
|
|
|
|
|
|
|
@database_client.query(<<-SQL, cache_rows: false, symbolize_keys: true).first[:config_value]
|
|
|
|
SELECT config_value
|
2016-07-11 17:59:15 -04:00
|
|
|
FROM #{table_prefix}config
|
2015-07-05 17:17:03 -04:00
|
|
|
WHERE config_name = 'version'
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-03 22:48:13 -05:00
|
|
|
class UnsupportedVersionError < RuntimeError
|
2015-07-05 17:17:03 -04:00
|
|
|
end
|
|
|
|
end
|