aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/module/install_database/task
diff options
context:
space:
mode:
authorMaat <maat-pub@mageia.biz>2020-05-08 21:52:11 +0200
committerMaat <maat-pub@mageia.biz>2020-05-08 21:52:11 +0200
commit8ea437e30605e0f66b5220bf904a61d7c1d11ddd (patch)
treee0db2bb4a012d5b06a633160b19f62f4868ecd28 /phpBB/phpbb/install/module/install_database/task
parent36bc1870f21fac04736a1049c1d5b8e127d729f4 (diff)
parent2fdd46b36431ae0f58bb2e78e42553168db9a0ff (diff)
downloadforums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar
forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.gz
forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.bz2
forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.xz
forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.zip
Merge remote-tracking branch 'upstream/prep-release-3.2.9'
Diffstat (limited to 'phpBB/phpbb/install/module/install_database/task')
-rw-r--r--phpBB/phpbb/install/module/install_database/task/add_config_settings.php368
-rw-r--r--phpBB/phpbb/install/module/install_database/task/add_default_data.php184
-rw-r--r--phpBB/phpbb/install/module/install_database/task/add_tables.php151
-rw-r--r--phpBB/phpbb/install/module/install_database/task/create_schema.php234
-rw-r--r--phpBB/phpbb/install/module/install_database/task/create_schema_file.php164
-rw-r--r--phpBB/phpbb/install/module/install_database/task/set_up_database.php164
6 files changed, 1265 insertions, 0 deletions
diff --git a/phpBB/phpbb/install/module/install_database/task/add_config_settings.php b/phpBB/phpbb/install/module/install_database/task/add_config_settings.php
new file mode 100644
index 0000000000..ba439609ff
--- /dev/null
+++ b/phpBB/phpbb/install/module/install_database/task/add_config_settings.php
@@ -0,0 +1,368 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\module\install_database\task;
+
+use phpbb\install\exception\resource_limit_reached_exception;
+
+/**
+ * Create database schema
+ */
+class add_config_settings extends \phpbb\install\task_base
+{
+ /**
+ * @var \phpbb\db\driver\driver_interface
+ */
+ protected $db;
+
+ /**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
+ * @var \phpbb\install\helper\config
+ */
+ protected $install_config;
+
+ /**
+ * @var \phpbb\install\helper\iohandler\iohandler_interface
+ */
+ protected $iohandler;
+
+ /**
+ * @var \phpbb\language\language
+ */
+ protected $language;
+
+ /**
+ * @var \phpbb\passwords\manager
+ */
+ protected $password_manager;
+
+ /**
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * @var string
+ */
+ protected $config_table;
+
+ /**
+ * @var string
+ */
+ protected $user_table;
+
+ /**
+ * @var string
+ */
+ protected $topics_table;
+
+ /**
+ * @var string
+ */
+ protected $forums_table;
+
+ /**
+ * @var string
+ */
+ protected $posts_table;
+
+ /**
+ * @var string
+ */
+ protected $moderator_cache_table;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service
+ * @param \phpbb\install\helper\config $install_config Installer's config helper
+ * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
+ * @param \phpbb\install\helper\container_factory $container Installer's DI container
+ * @param \phpbb\language\language $language Language service
+ * @param string $phpbb_root_path Path to phpBB's root
+ */
+ public function __construct(\phpbb\filesystem\filesystem_interface $filesystem,
+ \phpbb\install\helper\config $install_config,
+ \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
+ \phpbb\install\helper\container_factory $container,
+ \phpbb\language\language $language,
+ $phpbb_root_path)
+ {
+ $this->db = $container->get('dbal.conn');
+ $this->filesystem = $filesystem;
+ $this->install_config = $install_config;
+ $this->iohandler = $iohandler;
+ $this->language = $language;
+ $this->password_manager = $container->get('passwords.manager');
+ $this->phpbb_root_path = $phpbb_root_path;
+
+ // Table names
+ $this->config_table = $container->get_parameter('tables.config');
+ $this->forums_table = $container->get_parameter('tables.forums');
+ $this->topics_table = $container->get_parameter('tables.topics');
+ $this->user_table = $container->get_parameter('tables.users');
+ $this->moderator_cache_table = $container->get_parameter('tables.moderator_cache');
+ $this->posts_table = $container->get_parameter('tables.posts');
+
+ parent::__construct(true);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function run()
+ {
+ $this->db->sql_return_on_error(true);
+
+ $server_name = $this->install_config->get('server_name');
+ $current_time = time();
+ $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
+ $user_ip = ($user_ip === false) ? '' : $user_ip;
+ $referer = $this->iohandler->get_server_variable('REFERER');
+
+ // Calculate cookie domain
+ $cookie_domain = $server_name;
+
+ if (strpos($cookie_domain, 'www.') === 0)
+ {
+ $cookie_domain = substr($cookie_domain, 3);
+ }
+
+ // Set default config and post data, this applies to all DB's
+ $sql_ary = array(
+ 'INSERT INTO ' . $this->config_table . " (config_name, config_value)
+ VALUES ('board_startdate', '$current_time')",
+
+ 'INSERT INTO ' . $this->config_table . " (config_name, config_value)
+ VALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'
+ WHERE config_name = 'server_name'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'
+ WHERE config_name = 'server_port'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
+ WHERE config_name = 'board_email'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
+ WHERE config_name = 'board_contact'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($cookie_domain) . "'
+ WHERE config_name = 'cookie_domain'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'
+ WHERE config_name = 'default_dateformat'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'
+ WHERE config_name = 'email_enable'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'
+ WHERE config_name = 'smtp_delivery'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'
+ WHERE config_name = 'smtp_host'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'
+ WHERE config_name = 'smtp_port'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'
+ WHERE config_name = 'smtp_auth_method'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'
+ WHERE config_name = 'smtp_username'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'
+ WHERE config_name = 'smtp_password'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'
+ WHERE config_name = 'cookie_secure'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'
+ WHERE config_name = 'force_server_vars'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'
+ WHERE config_name = 'script_path'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'
+ WHERE config_name = 'server_protocol'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
+ WHERE config_name = 'newest_username'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . md5(mt_rand()) . "'
+ WHERE config_name = 'avatar_salt'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . md5(mt_rand()) . "'
+ WHERE config_name = 'plupload_salt'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'
+ WHERE config_name = 'sitename'",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'
+ WHERE config_name = 'site_desc'",
+
+ 'UPDATE ' . $this->user_table . "
+ SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
+ user_password='" . $this->password_manager->hash($this->install_config->get('admin_passwd')) . "',
+ user_ip = '" . $this->db->sql_escape($user_ip) . "',
+ user_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',
+ user_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',
+ user_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',
+ user_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",
+ username_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'
+ WHERE username = 'Admin'",
+
+ 'UPDATE ' . $this->moderator_cache_table . "
+ SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
+ WHERE username = 'Admin'",
+
+ 'UPDATE ' . $this->forums_table . "
+ SET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
+ WHERE forum_last_poster_name = 'Admin'",
+
+ 'UPDATE ' . $this->topics_table . "
+ SET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
+ topic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
+ WHERE topic_first_poster_name = 'Admin'
+ OR topic_last_poster_name = 'Admin'",
+
+ 'UPDATE ' . $this->user_table . "
+ SET user_regdate = $current_time",
+
+ 'UPDATE ' . $this->posts_table . "
+ SET post_time = $current_time, poster_ip = '" . $this->db->sql_escape($user_ip) . "'",
+
+ 'UPDATE ' . $this->topics_table . "
+ SET topic_time = $current_time, topic_last_post_time = $current_time",
+
+ 'UPDATE ' . $this->forums_table . "
+ SET forum_last_post_time = $current_time",
+
+ 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'
+ WHERE config_name = 'dbms_version'",
+ );
+
+ if (@extension_loaded('gd'))
+ {
+ $sql_ary[] = 'UPDATE ' . $this->config_table . "
+ SET config_value = 'core.captcha.plugins.gd'
+ WHERE config_name = 'captcha_plugin'";
+
+ $sql_ary[] = 'UPDATE ' . $this->config_table . "
+ SET config_value = '1'
+ WHERE config_name = 'captcha_gd'";
+ }
+
+ $ref = substr($referer, strpos($referer, '://') + 3);
+ if (!(stripos($ref, $server_name) === 0))
+ {
+ $sql_ary[] = 'UPDATE ' . $this->config_table . "
+ SET config_value = '0'
+ WHERE config_name = 'referer_validation'";
+ }
+
+ // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
+ $cookie_name = 'phpbb3_';
+ $rand_str = md5(mt_rand());
+ $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
+ $rand_str = substr($rand_str, 0, 5);
+ $cookie_name .= strtolower($rand_str);
+
+ $sql_ary[] = 'UPDATE ' . $this->config_table . "
+ SET config_value = '" . $this->db->sql_escape($cookie_name) . "'
+ WHERE config_name = 'cookie_name'";
+
+ // Disable avatars if upload directory is not writable
+ if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/'))
+ {
+ $sql_ary[] = 'UPDATE ' . $this->config_table . "
+ SET config_value = '0'
+ WHERE config_name = 'allow_avatar'";
+
+ $sql_ary[] = 'UPDATE ' . $this->config_table . "
+ SET config_value = '0'
+ WHERE config_name = 'allow_avatar_upload'";
+ }
+
+ $i = $this->install_config->get('add_config_settings_index', 0);
+ $total = count($sql_ary);
+ $sql_ary = array_slice($sql_ary, $i);
+
+ foreach ($sql_ary as $sql)
+ {
+ if (!$this->db->sql_query($sql))
+ {
+ $error = $this->db->sql_error($this->db->get_sql_error_sql());
+ $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
+ }
+
+ $i++;
+
+ // Stop execution if resource limit is reached
+ if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
+ {
+ break;
+ }
+ }
+
+ if ($i < $total)
+ {
+ $this->install_config->set('add_config_settings_index', $i);
+ throw new resource_limit_reached_exception();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function get_step_count()
+ {
+ return 1;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_task_lang_name()
+ {
+ return 'TASK_ADD_CONFIG_SETTINGS';
+ }
+}
diff --git a/phpBB/phpbb/install/module/install_database/task/add_default_data.php b/phpBB/phpbb/install/module/install_database/task/add_default_data.php
new file mode 100644
index 0000000000..c05e5321fb
--- /dev/null
+++ b/phpBB/phpbb/install/module/install_database/task/add_default_data.php
@@ -0,0 +1,184 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\module\install_database\task;
+
+use phpbb\install\exception\resource_limit_reached_exception;
+
+/**
+ * Create database schema
+ */
+class add_default_data extends \phpbb\install\task_base
+{
+ /**
+ * @var \phpbb\db\driver\driver_interface
+ */
+ protected $db;
+
+ /**
+ * @var \phpbb\install\helper\database
+ */
+ protected $database_helper;
+
+ /**
+ * @var \phpbb\install\helper\config
+ */
+ protected $config;
+
+ /**
+ * @var \phpbb\install\helper\iohandler\iohandler_interface
+ */
+ protected $iohandler;
+
+ /**
+ * @var \phpbb\language\language
+ */
+ protected $language;
+
+ /**
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\install\helper\database $db_helper Installer's database helper
+ * @param \phpbb\install\helper\config $config Installer config
+ * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
+ * @param \phpbb\install\helper\container_factory $container Installer's DI container
+ * @param \phpbb\language\language $language Language service
+ * @param string $root_path Root path of phpBB
+ */
+ public function __construct(\phpbb\install\helper\database $db_helper,
+ \phpbb\install\helper\config $config,
+ \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
+ \phpbb\install\helper\container_factory $container,
+ \phpbb\language\language $language,
+ $root_path)
+ {
+ $this->db = $container->get('dbal.conn.driver');
+ $this->database_helper = $db_helper;
+ $this->config = $config;
+ $this->iohandler = $iohandler;
+ $this->language = $language;
+ $this->phpbb_root_path = $root_path;
+
+ parent::__construct(true);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function run()
+ {
+ $this->db->sql_return_on_error(true);
+
+ $table_prefix = $this->config->get('table_prefix');
+ $dbms = $this->config->get('dbms');
+ $dbms_info = $this->database_helper->get_available_dbms($dbms);
+
+ // Get schema data from file
+ $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql');
+
+ // Clean up SQL
+ $sql_query = $this->replace_dbms_specific_sql($sql_query);
+ $sql_query = preg_replace('# phpbb_([^\s]*) #i', ' ' . $table_prefix . '\1 ', $sql_query);
+ $sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', array($this, 'lang_replace_callback'), $sql_query);
+ $sql_query = $this->database_helper->remove_comments($sql_query);
+ $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
+
+ $i = $this->config->get('add_default_data_index', 0);
+ $total = count($sql_query);
+ $sql_query = array_slice($sql_query, $i);
+
+ foreach ($sql_query as $sql)
+ {
+ if (!$this->db->sql_query($sql))
+ {
+ $error = $this->db->sql_error($this->db->get_sql_error_sql());
+ $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
+ }
+
+ $i++;
+
+ // Stop execution if resource limit is reached
+ if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
+ {
+ break;
+ }
+ }
+
+ $this->config->set('add_default_data_index', $i);
+
+ if ($i < $total)
+ {
+ throw new resource_limit_reached_exception();
+ }
+ }
+
+ /**
+ * Process DB specific SQL
+ *
+ * @return string
+ */
+ protected function replace_dbms_specific_sql($query)
+ {
+ if ($this->db instanceof \phpbb\db\driver\mssql_base)
+ {
+ $query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $query);
+ }
+ else if ($this->db instanceof \phpbb\db\driver\postgres)
+ {
+ $query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $query);
+ }
+ else if ($this->db instanceof \phpbb\db\driver\mysql_base)
+ {
+ $query = str_replace('\\', '\\\\', $query);
+ }
+
+ return $query;
+ }
+
+ /**
+ * Callback function for language replacing
+ *
+ * @param array $matches
+ * @return string
+ */
+ public function lang_replace_callback($matches)
+ {
+ if (!empty($matches[1]))
+ {
+ return $this->db->sql_escape($this->language->lang($matches[1]));
+ }
+
+ return '';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function get_step_count()
+ {
+ return 1;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_task_lang_name()
+ {
+ return 'TASK_ADD_DEFAULT_DATA';
+ }
+}
diff --git a/phpBB/phpbb/install/module/install_database/task/add_tables.php b/phpBB/phpbb/install/module/install_database/task/add_tables.php
new file mode 100644
index 0000000000..dc814f36ef
--- /dev/null
+++ b/phpBB/phpbb/install/module/install_database/task/add_tables.php
@@ -0,0 +1,151 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\module\install_database\task;
+
+use phpbb\install\exception\resource_limit_reached_exception;
+
+/**
+ * Create tables
+ */
+class add_tables extends \phpbb\install\task_base
+{
+ /**
+ * @var \phpbb\install\helper\config
+ */
+ protected $config;
+
+ /**
+ * @var \phpbb\db\driver\driver_interface
+ */
+ protected $db;
+
+ /**
+ * @var \phpbb\db\tools\tools_interface
+ */
+ protected $db_tools;
+
+ /**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
+ * @var string
+ */
+ protected $schema_file_path;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\install\helper\config $config
+ * @param \phpbb\install\helper\database $db_helper
+ * @param \phpbb\filesystem\filesystem_interface $filesystem
+ * @param string $phpbb_root_path
+ */
+ public function __construct(\phpbb\install\helper\config $config,
+ \phpbb\install\helper\database $db_helper,
+ \phpbb\filesystem\filesystem_interface $filesystem,
+ $phpbb_root_path)
+ {
+ $dbms = $db_helper->get_available_dbms($config->get('dbms'));
+ $dbms = $dbms[$config->get('dbms')]['DRIVER'];
+ $factory = new \phpbb\db\tools\factory();
+
+ $this->db = new $dbms();
+ $this->db->sql_connect(
+ $config->get('dbhost'),
+ $config->get('dbuser'),
+ $config->get('dbpasswd'),
+ $config->get('dbname'),
+ $config->get('dbport'),
+ false,
+ false
+ );
+
+ $this->config = $config;
+ $this->db_tools = $factory->get($this->db);
+ $this->filesystem = $filesystem;
+ $this->schema_file_path = $phpbb_root_path . 'store/schema.json';
+
+ parent::__construct(true);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function run()
+ {
+ $this->db->sql_return_on_error(true);
+
+ $table_prefix = $this->config->get('table_prefix');
+ $change_prefix = $this->config->get('change_table_prefix', true);
+
+ if (!defined('CONFIG_TABLE'))
+ {
+ // CONFIG_TABLE is required by sql_create_index() to check the
+ // length of index names. However table_prefix is not defined
+ // here yet, so we need to create the constant ourselves.
+ define('CONFIG_TABLE', $table_prefix . 'config');
+ }
+
+ $db_table_schema = @file_get_contents($this->schema_file_path);
+ $db_table_schema = json_decode($db_table_schema, true);
+ $total = count($db_table_schema);
+ $i = $this->config->get('add_table_index', 0);
+ $db_table_schema = array_slice($db_table_schema, $i);
+
+ foreach ($db_table_schema as $table_name => $table_data)
+ {
+ $i++;
+
+ $this->db_tools->sql_create_table(
+ ( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ),
+ $table_data
+ );
+
+ // Stop execution if resource limit is reached
+ if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
+ {
+ break;
+ }
+ }
+
+ $this->config->set('add_table_index', $i);
+
+ if ($i < $total)
+ {
+ throw new resource_limit_reached_exception();
+ }
+ else
+ {
+ @unlink($this->schema_file_path);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function get_step_count()
+ {
+ return 1;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_task_lang_name()
+ {
+ return 'TASK_CREATE_TABLES';
+ }
+}
diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema.php b/phpBB/phpbb/install/module/install_database/task/create_schema.php
new file mode 100644
index 0000000000..a5635d5dbe
--- /dev/null
+++ b/phpBB/phpbb/install/module/install_database/task/create_schema.php
@@ -0,0 +1,234 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\module\install_database\task;
+
+use phpbb\install\exception\resource_limit_reached_exception;
+
+/**
+ * Create database schema
+ */
+class create_schema extends \phpbb\install\task_base
+{
+ /**
+ * @var \phpbb\install\helper\config
+ */
+ protected $config;
+
+ /**
+ * @var \phpbb\db\driver\driver_interface
+ */
+ protected $db;
+
+ /**
+ * @var \phpbb\db\tools\tools_interface
+ */
+ protected $db_tools;
+
+ /**
+ * @var \phpbb\install\helper\database
+ */
+ protected $database_helper;
+
+ /**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
+ * @var \phpbb\install\helper\iohandler\iohandler_interface
+ */
+ protected $iohandler;
+
+ /**
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * @var string
+ */
+ protected $php_ext;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\install\helper\config $config Installer's config provider
+ * @param \phpbb\install\helper\database $db_helper Installer's database helper
+ * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service
+ * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
+ * @param string $phpbb_root_path Path phpBB's root
+ * @param string $php_ext Extension of PHP files
+ */
+ public function __construct(\phpbb\install\helper\config $config,
+ \phpbb\install\helper\database $db_helper,
+ \phpbb\filesystem\filesystem_interface $filesystem,
+ \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
+ $phpbb_root_path,
+ $php_ext)
+ {
+ $dbms = $db_helper->get_available_dbms($config->get('dbms'));
+ $dbms = $dbms[$config->get('dbms')]['DRIVER'];
+ $factory = new \phpbb\db\tools\factory();
+
+ $this->db = new $dbms();
+ $this->db->sql_connect(
+ $config->get('dbhost'),
+ $config->get('dbuser'),
+ $config->get('dbpasswd'),
+ $config->get('dbname'),
+ $config->get('dbport'),
+ false,
+ false
+ );
+
+ $this->config = $config;
+ $this->db_tools = $factory->get($this->db);
+ $this->database_helper = $db_helper;
+ $this->filesystem = $filesystem;
+ $this->iohandler = $iohandler;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+
+ parent::__construct(true);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function run()
+ {
+ // As this task may take a large amount of time to complete refreshing the page might be necessary for some
+ // server configurations with limited resources
+ if (!$this->config->get('pre_schema_forced_refresh'))
+ {
+ if ($this->config->get_time_remaining() < 5)
+ {
+ $this->config->set('pre_schema_forced_refresh', true);
+ throw new resource_limit_reached_exception();
+ }
+ }
+
+ $this->db->sql_return_on_error(true);
+
+ $dbms = $this->config->get('dbms');
+ $dbms_info = $this->database_helper->get_available_dbms($dbms);
+ $schema_name = $dbms_info[$dbms]['SCHEMA'];
+ $delimiter = $dbms_info[$dbms]['DELIM'];
+ $table_prefix = $this->config->get('table_prefix');
+
+ if ($dbms === 'mysql')
+ {
+ if (version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
+ {
+ $schema_name .= '_41';
+ }
+ else
+ {
+ $schema_name .= '_40';
+ }
+ }
+
+ $db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
+
+ // Load database vendor specific code if there is any
+ if ($this->filesystem->exists($db_schema_path))
+ {
+ $sql_query = @file_get_contents($db_schema_path);
+ $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
+ $sql_query = $this->database_helper->remove_comments($sql_query);
+ $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
+
+ foreach ($sql_query as $sql)
+ {
+ if (!$this->db->sql_query($sql))
+ {
+ $error = $this->db->sql_error($this->db->get_sql_error_sql());
+ $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
+ }
+ }
+
+ unset($sql_query);
+ }
+
+ $change_prefix = false;
+
+ // Generate database schema
+ if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json'))
+ {
+ $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
+ $db_table_schema = json_decode($db_table_schema, true);
+ $change_prefix = true;
+ }
+ else
+ {
+ global $table_prefix;
+
+ $table_prefix = $this->config->get('table_prefix');
+
+ if (!defined('CONFIG_TABLE'))
+ {
+ // We need to include the constants file for the table constants
+ // when we generate the schema from the migration files.
+ include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext);
+ }
+
+ $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
+ $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
+ $factory = new \phpbb\db\tools\factory();
+ $db_tools = $factory->get($this->db, true);
+ $schema_generator = new \phpbb\db\migration\schema_generator(
+ $migrator_classes,
+ new \phpbb\config\config(array()),
+ $this->db,
+ $db_tools,
+ $this->phpbb_root_path,
+ $this->php_ext,
+ $table_prefix
+ );
+ $db_table_schema = $schema_generator->get_schema();
+ }
+
+ if (!defined('CONFIG_TABLE'))
+ {
+ // CONFIG_TABLE is required by sql_create_index() to check the
+ // length of index names. However table_prefix is not defined
+ // here yet, so we need to create the constant ourselves.
+ define('CONFIG_TABLE', $table_prefix . 'config');
+ }
+
+ foreach ($db_table_schema as $table_name => $table_data)
+ {
+ $this->db_tools->sql_create_table(
+ ( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ),
+ $table_data
+ );
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function get_step_count()
+ {
+ return 1;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_task_lang_name()
+ {
+ return 'TASK_CREATE_DATABASE_SCHEMA';
+ }
+}
diff --git a/phpBB/phpbb/install/module/install_database/task/create_schema_file.php b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php
new file mode 100644
index 0000000000..b6d6ece17f
--- /dev/null
+++ b/phpBB/phpbb/install/module/install_database/task/create_schema_file.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\module\install_database\task;
+
+use phpbb\install\exception\resource_limit_reached_exception;
+
+/**
+ * Create database schema
+ */
+class create_schema_file extends \phpbb\install\task_base
+{
+ /**
+ * @var \phpbb\install\helper\config
+ */
+ protected $config;
+
+ /**
+ * @var \phpbb\db\driver\driver_interface
+ */
+ protected $db;
+
+ /**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * @var string
+ */
+ protected $php_ext;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\install\helper\config $config Installer's config provider
+ * @param \phpbb\install\helper\database $db_helper Installer's database helper
+ * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service
+ * @param string $phpbb_root_path Path phpBB's root
+ * @param string $php_ext Extension of PHP files
+ */
+ public function __construct(\phpbb\install\helper\config $config,
+ \phpbb\install\helper\database $db_helper,
+ \phpbb\filesystem\filesystem_interface $filesystem,
+ $phpbb_root_path,
+ $php_ext)
+ {
+ $dbms = $db_helper->get_available_dbms($config->get('dbms'));
+ $dbms = $dbms[$config->get('dbms')]['DRIVER'];
+
+ $this->db = new $dbms();
+ $this->db->sql_connect(
+ $config->get('dbhost'),
+ $config->get('dbuser'),
+ $config->get('dbpasswd'),
+ $config->get('dbname'),
+ $config->get('dbport'),
+ false,
+ false
+ );
+
+ $this->config = $config;
+ $this->filesystem = $filesystem;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+
+ parent::__construct(true);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function run()
+ {
+ // Generate database schema
+ if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json'))
+ {
+ $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
+ $this->config->set('change_table_prefix', true);
+ }
+ else
+ {
+ global $table_prefix;
+
+ // As this task may take a large amount of time to complete refreshing the page might be necessary for some
+ // server configurations with limited resources
+ if (!$this->config->get('pre_schema_forced_refresh', false))
+ {
+ if ($this->config->get_time_remaining() < 5)
+ {
+ $this->config->set('pre_schema_forced_refresh', true);
+ throw new resource_limit_reached_exception();
+ }
+ }
+
+ $table_prefix = $this->config->get('table_prefix');
+
+ if (!defined('CONFIG_TABLE'))
+ {
+ // We need to include the constants file for the table constants
+ // when we generate the schema from the migration files.
+ include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext);
+ }
+
+ $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
+ $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
+ $factory = new \phpbb\db\tools\factory();
+ $db_tools = $factory->get($this->db, true);
+ $schema_generator = new \phpbb\db\migration\schema_generator(
+ $migrator_classes,
+ new \phpbb\config\config(array()),
+ $this->db,
+ $db_tools,
+ $this->phpbb_root_path,
+ $this->php_ext,
+ $table_prefix
+ );
+ $db_table_schema = $schema_generator->get_schema();
+ $db_table_schema = json_encode($db_table_schema, JSON_PRETTY_PRINT);
+
+ $this->config->set('change_table_prefix', false);
+ }
+
+ $fp = @fopen($this->phpbb_root_path . 'store/schema.json', 'wb');
+ if (!$fp)
+ {
+ throw new \Exception('INST_SCHEMA_FILE_NOT_WRITABLE');
+ }
+
+ fwrite($fp, $db_table_schema);
+ fclose($fp);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function get_step_count()
+ {
+ return 1;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_task_lang_name()
+ {
+ return 'TASK_CREATE_DATABASE_SCHEMA_FILE';
+ }
+}
diff --git a/phpBB/phpbb/install/module/install_database/task/set_up_database.php b/phpBB/phpbb/install/module/install_database/task/set_up_database.php
new file mode 100644
index 0000000000..49c8ea23ad
--- /dev/null
+++ b/phpBB/phpbb/install/module/install_database/task/set_up_database.php
@@ -0,0 +1,164 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\install\module\install_database\task;
+
+/**
+ * Set up database for table generation
+ */
+class set_up_database extends \phpbb\install\task_base
+{
+ /**
+ * @var \phpbb\install\helper\config
+ */
+ protected $config;
+
+ /**
+ * @var \phpbb\db\driver\driver_interface
+ */
+ protected $db;
+
+ /**
+ * @var \phpbb\install\helper\database
+ */
+ protected $database_helper;
+
+ /**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
+ * @var \phpbb\install\helper\iohandler\iohandler_interface
+ */
+ protected $iohandler;
+
+ /**
+ * @var string
+ */
+ protected $schema_file_path;
+
+ /**
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * Constructor
+ *
+ * @param \phpbb\install\helper\config $config
+ * @param \phpbb\install\helper\database $db_helper
+ * @param \phpbb\filesystem\filesystem_interface $filesystem
+ * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler
+ * @param string $phpbb_root_path
+ */
+ public function __construct(\phpbb\install\helper\config $config,
+ \phpbb\install\helper\database $db_helper,
+ \phpbb\filesystem\filesystem_interface $filesystem,
+ \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
+ $phpbb_root_path)
+ {
+ $dbms = $db_helper->get_available_dbms($config->get('dbms'));
+ $dbms = $dbms[$config->get('dbms')]['DRIVER'];
+
+ $this->db = new $dbms();
+ $this->db->sql_connect(
+ $config->get('dbhost'),
+ $config->get('dbuser'),
+ $config->get('dbpasswd'),
+ $config->get('dbname'),
+ $config->get('dbport'),
+ false,
+ false
+ );
+
+ $this->config = $config;
+ $this->database_helper = $db_helper;
+ $this->filesystem = $filesystem;
+ $this->iohandler = $iohandler;
+ $this->phpbb_root_path = $phpbb_root_path;
+
+ parent::__construct(false);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function check_requirements()
+ {
+ $dbms = $this->config->get('dbms');
+ $dbms_info = $this->database_helper->get_available_dbms($dbms);
+ $schema_name = $dbms_info[$dbms]['SCHEMA'];
+
+ if ($dbms === 'mysql')
+ {
+ if (version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
+ {
+ $schema_name .= '_41';
+ }
+ else
+ {
+ $schema_name .= '_40';
+ }
+ }
+
+ $this->schema_file_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
+
+ return $this->filesystem->exists($this->schema_file_path);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function run()
+ {
+ $this->db->sql_return_on_error(true);
+
+ $dbms = $this->config->get('dbms');
+ $dbms_info = $this->database_helper->get_available_dbms($dbms);
+ $delimiter = $dbms_info[$dbms]['DELIM'];
+ $table_prefix = $this->config->get('table_prefix');
+
+ $sql_query = @file_get_contents($this->schema_file_path);
+ $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
+ $sql_query = $this->database_helper->remove_comments($sql_query);
+ $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
+
+ foreach ($sql_query as $sql)
+ {
+ if (!$this->db->sql_query($sql))
+ {
+ $error = $this->db->sql_error($this->db->get_sql_error_sql());
+ $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
+ }
+ }
+
+ unset($sql_query);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function get_step_count()
+ {
+ return 1;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_task_lang_name()
+ {
+ return 'TASK_SETUP_DATABASE';
+ }
+}