1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-25 12:33:29 +01:00

[ticket/14462] Refactor tasks to be more modular

PHPBB3-14462
This commit is contained in:
Mate Bartus 2016-02-12 14:20:04 +01:00
parent 955b9ede33
commit 68091561ab
12 changed files with 874 additions and 182 deletions

View File

@ -23,6 +23,7 @@ services:
installer.install_data.add_modules: installer.install_data.add_modules:
class: phpbb\install\module\install_data\task\add_modules class: phpbb\install\module\install_data\task\add_modules
arguments: arguments:
- '@installer.helper.config'
- '@installer.helper.iohandler' - '@installer.helper.iohandler'
- '@installer.helper.container_factory' - '@installer.helper.container_factory'
tags: tags:

View File

@ -1,15 +1,35 @@
services: services:
installer.install_database.create_schema: installer.install_database.create_schema_file:
class: phpbb\install\module\install_database\task\create_schema class: phpbb\install\module\install_database\task\create_schema_file
arguments:
- '@installer.helper.config'
- '@installer.helper.database'
- '@filesystem'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: install_database_install, order: 10 }
installer.install_database.set_up_database:
class: phpbb\install\module\install_database\task\set_up_database
arguments: arguments:
- '@installer.helper.config' - '@installer.helper.config'
- '@installer.helper.database' - '@installer.helper.database'
- '@filesystem' - '@filesystem'
- '@installer.helper.iohandler' - '@installer.helper.iohandler'
- '%core.root_path%' - '%core.root_path%'
- '%core.php_ext%'
tags: tags:
- { name: install_database_install, order: 10 } - { name: install_database_install, order: 13 }
installer.install_database.add_tables:
class: phpbb\install\module\install_database\task\add_tables
arguments:
- '@installer.helper.config'
- '@installer.helper.database'
- '@filesystem'
- '%core.root_path%'
tags:
- { name: install_database_install, order: 17 }
installer.install_database.add_default_data: installer.install_database.add_default_data:
class: phpbb\install\module\install_database\task\add_default_data class: phpbb\install\module\install_database\task\add_default_data

View File

@ -2,6 +2,7 @@ services:
installer.install_finish.populate_migrations: installer.install_finish.populate_migrations:
class: phpbb\install\module\install_finish\task\populate_migrations class: phpbb\install\module\install_finish\task\populate_migrations
arguments: arguments:
- '@installer.helper.config'
- '@installer.helper.container_factory' - '@installer.helper.container_factory'
tags: tags:
- { name: install_finish, order: 10 } - { name: install_finish, order: 10 }

View File

@ -13,6 +13,8 @@
namespace phpbb\install\module\install_data\task; namespace phpbb\install\module\install_data\task;
use phpbb\install\exception\resource_limit_reached_exception;
class add_bots extends \phpbb\install\task_base class add_bots extends \phpbb\install\task_base
{ {
/** /**
@ -179,7 +181,10 @@ class add_bots extends \phpbb\install\task_base
$this->io_handler->add_error_message('NO_GROUP'); $this->io_handler->add_error_message('NO_GROUP');
} }
foreach ($this->bot_list as $bot_name => $bot_ary) $i = $this->install_config->get('add_bot_index', 0);
$bot_list = array_slice($this->bot_list, $i);
foreach ($bot_list as $bot_name => $bot_ary)
{ {
$user_row = array( $user_row = array(
'user_type' => USER_IGNORE, 'user_type' => USER_IGNORE,
@ -221,6 +226,21 @@ class add_bots extends \phpbb\install\task_base
)); ));
$this->db->sql_query($sql); $this->db->sql_query($sql);
$i++;
// Run until there are available resources
if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
{
break;
}
}
$this->install_config->set('add_bot_index', $i);
if ($i < sizeof($this->bot_list))
{
throw new resource_limit_reached_exception();
} }
} }

View File

@ -13,8 +13,18 @@
namespace phpbb\install\module\install_data\task; namespace phpbb\install\module\install_data\task;
use phpbb\install\exception\resource_limit_reached_exception;
use phpbb\install\helper\config;
use phpbb\install\helper\container_factory;
use phpbb\install\helper\iohandler\iohandler_interface;
class add_modules extends \phpbb\install\task_base class add_modules extends \phpbb\install\task_base
{ {
/**
* @var config
*/
protected $config;
/** /**
* @var \phpbb\db\driver\driver_interface * @var \phpbb\db\driver\driver_interface
*/ */
@ -136,12 +146,13 @@ class add_modules extends \phpbb\install\task_base
/** /**
* Constructor * Constructor
* *
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler * @parma config $config Installer's config
* @param \phpbb\install\helper\container_factory $container Installer's DI container * @param iohandler_interface $iohandler Installer's input-output handler
* @param container_factory $container Installer's DI container
*/ */
public function __construct(\phpbb\install\helper\iohandler\iohandler_interface $iohandler, public function __construct(config $config, iohandler_interface $iohandler, container_factory $container)
\phpbb\install\helper\container_factory $container)
{ {
$this->config = $config;
$this->db = $container->get('dbal.conn'); $this->db = $container->get('dbal.conn');
$this->extension_manager = $container->get('ext.manager'); $this->extension_manager = $container->get('ext.manager');
$this->iohandler = $iohandler; $this->iohandler = $iohandler;
@ -158,11 +169,19 @@ class add_modules extends \phpbb\install\task_base
$this->db->sql_return_on_error(true); $this->db->sql_return_on_error(true);
$module_classes = array('acp', 'mcp', 'ucp'); $module_classes = array('acp', 'mcp', 'ucp');
$total = sizeof($module_classes);
$i = $this->config->get('module_class_index', 0);
$module_classes = array_slice($module_classes, $i);
foreach ($module_classes as $module_class) foreach ($module_classes as $module_class)
{ {
$categories = array(); $categories = $this->config->get('module_categories_array', array());
foreach ($this->module_categories[$module_class] as $cat_name => $subs) $k = $this->config->get('module_categories_index', 0);
$module_categories = array_slice($this->module_categories[$module_class], $k);
$timed_out = false;
foreach ($module_categories as $cat_name => $subs)
{ {
// Check if this sub-category has a basename. If it has, use it. // Check if this sub-category has a basename. If it has, use it.
$basename = (isset($this->module_categories_basenames[$cat_name])) ? $this->module_categories_basenames[$cat_name] : ''; $basename = (isset($this->module_categories_basenames[$cat_name])) ? $this->module_categories_basenames[$cat_name] : '';
@ -221,11 +240,31 @@ class add_modules extends \phpbb\install\task_base
$categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id']; $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id'];
} }
} }
$k++;
// Run until there are available resources
if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
{
$timed_out = true;
break;
}
}
$this->config->set('module_categories_array', $categories);
$this->config->set('module_categories_index', $k);
if ($timed_out)
{
throw new resource_limit_reached_exception();
} }
// Get the modules we want to add... returned sorted by name // Get the modules we want to add... returned sorted by name
$module_info = $this->module_manager->get_module_infos($module_class); $module_info = $this->module_manager->get_module_infos($module_class);
$k = $this->config->get('module_info_index', 0);
$module_info = array_slice($module_info, $k);
foreach ($module_info as $module_basename => $fileinfo) foreach ($module_info as $module_basename => $fileinfo)
{ {
foreach ($fileinfo['modes'] as $module_mode => $row) foreach ($fileinfo['modes'] as $module_mode => $row)
@ -258,137 +297,36 @@ class add_modules extends \phpbb\install\task_base
} }
} }
} }
$k++;
// Run until there are available resources
if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
{
$timed_out = true;
break;
}
}
$this->config->set('module_info_index', $k);
// Run until there are available resources
if ($timed_out)
{
throw new resource_limit_reached_exception();
} }
// Move some of the modules around since the code above will put them in the wrong place // Move some of the modules around since the code above will put them in the wrong place
if ($module_class === 'acp') if (!$this->config->get('modules_ordered', false))
{ {
// Move main module 4 up... $this->order_modules($module_class);
$sql = 'SELECT * $this->config->set('modules_ordered', true);
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'acp_main'
AND module_class = 'acp'
AND module_mode = 'main'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 4); // Run until there are available resources
if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
// Move permissions intro screen module 4 up... {
$sql = 'SELECT * throw new resource_limit_reached_exception();
FROM ' . MODULES_TABLE . " }
WHERE module_basename = 'acp_permissions'
AND module_class = 'acp'
AND module_mode = 'intro'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
// Move manage users screen module 5 up...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'acp_users'
AND module_class = 'acp'
AND module_mode = 'overview'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 5);
// Move extension management module 1 up...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_langname = 'ACP_EXTENSION_MANAGEMENT'
AND module_class = 'acp'
AND module_mode = ''
AND module_basename = ''";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 1);
}
if ($module_class == 'mcp')
{
// Move pm report details module 3 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'mcp_pm_reports'
AND module_class = 'mcp'
AND module_mode = 'pm_report_details'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
// Move closed pm reports module 3 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'mcp_pm_reports'
AND module_class = 'mcp'
AND module_mode = 'pm_reports_closed'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
// Move open pm reports module 3 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'mcp_pm_reports'
AND module_class = 'mcp'
AND module_mode = 'pm_reports'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
}
if ($module_class == 'ucp')
{
// Move attachment module 4 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'ucp_attachments'
AND module_class = 'ucp'
AND module_mode = 'attachments'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
// Move notification options module 4 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'ucp_notifications'
AND module_class = 'ucp'
AND module_mode = 'notification_options'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
// Move OAuth module 5 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'ucp_auth_link'
AND module_class = 'ucp'
AND module_mode = 'auth_link'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'ucp', 'move_down', 5);
} }
// And now for the special ones // And now for the special ones
@ -396,51 +334,219 @@ class add_modules extends \phpbb\install\task_base
// to some for more control) // to some for more control)
if (isset($this->module_extras[$module_class])) if (isset($this->module_extras[$module_class]))
{ {
foreach ($this->module_extras[$module_class] as $cat_name => $mods) $this->add_module_extras($module_class);
{
$sql = 'SELECT module_id, left_id, right_id
FROM ' . MODULES_TABLE . "
WHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'
AND module_class = '" . $this->db->sql_escape($module_class) . "'";
$result = $this->db->sql_query_limit($sql, 1);
$row2 = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
foreach ($mods as $mod_name)
{
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'
AND module_class = '" . $this->db->sql_escape($module_class) . "'
AND module_basename <> ''";
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$module_data = array(
'module_basename' => $row['module_basename'],
'module_enabled' => (int) $row['module_enabled'],
'module_display' => (int) $row['module_display'],
'parent_id' => (int) $row2['module_id'],
'module_class' => $row['module_class'],
'module_langname' => $row['module_langname'],
'module_mode' => $row['module_mode'],
'module_auth' => $row['module_auth'],
);
$this->module_manager->update_module_data($module_data);
// Check for last sql error happened
if ($this->db->get_sql_error_triggered())
{
$error = $this->db->sql_error($this->db->get_sql_error_sql());
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
}
}
}
} }
$this->module_manager->remove_cache_file($module_class); $this->module_manager->remove_cache_file($module_class);
$i++;
$this->config->set('module_class_index', $i);
$this->config->set('module_categories_index', 0);
$this->config->set('module_info_index', 0);
$this->config->set('added_extra_modules', false);
$this->config->set('modules_ordered', false);
$this->config->set('module_categories_array', array());
// Run until there are available resources
if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
{
break;
}
}
if ($i < $total)
{
throw new resource_limit_reached_exception();
}
}
/**
* Move modules to their correct place
*
* @param string $module_class
*/
protected function order_modules($module_class)
{
if ($module_class == 'acp')
{
// Move main module 4 up...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'acp_main'
AND module_class = 'acp'
AND module_mode = 'main'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
// Move permissions intro screen module 4 up...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'acp_permissions'
AND module_class = 'acp'
AND module_mode = 'intro'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 4);
// Move manage users screen module 5 up...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'acp_users'
AND module_class = 'acp'
AND module_mode = 'overview'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 5);
// Move extension management module 1 up...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_langname = 'ACP_EXTENSION_MANAGEMENT'
AND module_class = 'acp'
AND module_mode = ''
AND module_basename = ''";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'acp', 'move_up', 1);
}
if ($module_class == 'mcp')
{
// Move pm report details module 3 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'mcp_pm_reports'
AND module_class = 'mcp'
AND module_mode = 'pm_report_details'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
// Move closed pm reports module 3 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'mcp_pm_reports'
AND module_class = 'mcp'
AND module_mode = 'pm_reports_closed'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
// Move open pm reports module 3 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'mcp_pm_reports'
AND module_class = 'mcp'
AND module_mode = 'pm_reports'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'mcp', 'move_down', 3);
}
if ($module_class == 'ucp')
{
// Move attachment module 4 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'ucp_attachments'
AND module_class = 'ucp'
AND module_mode = 'attachments'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
// Move notification options module 4 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'ucp_notifications'
AND module_class = 'ucp'
AND module_mode = 'notification_options'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'ucp', 'move_down', 4);
// Move OAuth module 5 down...
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = 'ucp_auth_link'
AND module_class = 'ucp'
AND module_mode = 'auth_link'";
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$this->module_manager->move_module_by($row, 'ucp', 'move_down', 5);
}
}
/**
* Add extra modules
*
* @param string $module_class
*/
protected function add_module_extras($module_class)
{
foreach ($this->module_extras[$module_class] as $cat_name => $mods)
{
$sql = 'SELECT module_id, left_id, right_id
FROM ' . MODULES_TABLE . "
WHERE module_langname = '" . $this->db->sql_escape($cat_name) . "'
AND module_class = '" . $this->db->sql_escape($module_class) . "'";
$result = $this->db->sql_query_limit($sql, 1);
$row2 = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
foreach ($mods as $mod_name)
{
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_langname = '" . $this->db->sql_escape($mod_name) . "'
AND module_class = '" . $this->db->sql_escape($module_class) . "'
AND module_basename <> ''";
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$module_data = array(
'module_basename' => $row['module_basename'],
'module_enabled' => (int) $row['module_enabled'],
'module_display' => (int) $row['module_display'],
'parent_id' => (int) $row2['module_id'],
'module_class' => $row['module_class'],
'module_langname' => $row['module_langname'],
'module_mode' => $row['module_mode'],
'module_auth' => $row['module_auth'],
);
$this->module_manager->update_module_data($module_data);
// Check for last sql error happened
if ($this->db->get_sql_error_triggered())
{
$error = $this->db->sql_error($this->db->get_sql_error_sql());
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
}
}
} }
} }

View File

@ -13,6 +13,8 @@
namespace phpbb\install\module\install_database\task; namespace phpbb\install\module\install_database\task;
use phpbb\install\exception\resource_limit_reached_exception;
/** /**
* Create database schema * Create database schema
*/ */
@ -313,6 +315,10 @@ class add_config_settings extends \phpbb\install\task_base
WHERE config_name = 'allow_avatar_upload'"; WHERE config_name = 'allow_avatar_upload'";
} }
$i = $this->install_config->get('add_config_settings_index', 0);
$total = sizeof($sql_ary);
$sql_ary = array_slice($sql_ary, $i);
foreach ($sql_ary as $sql) foreach ($sql_ary as $sql)
{ {
if (!$this->db->sql_query($sql)) if (!$this->db->sql_query($sql))
@ -320,6 +326,20 @@ class add_config_settings extends \phpbb\install\task_base
$error = $this->db->sql_error($this->db->get_sql_error_sql()); $error = $this->db->sql_error($this->db->get_sql_error_sql());
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
} }
$i++;
// Run until there are available resources
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();
} }
} }

View File

@ -13,6 +13,8 @@
namespace phpbb\install\module\install_database\task; namespace phpbb\install\module\install_database\task;
use phpbb\install\exception\resource_limit_reached_exception;
/** /**
* Create database schema * Create database schema
*/ */
@ -96,6 +98,10 @@ class add_default_data extends \phpbb\install\task_base
$sql_query = $this->database_helper->remove_comments($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']); $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
$i = $this->config->get('add_default_data_index', 0);
$total = sizeof($sql_query);
$sql_query = array_slice($sql_query, $i);
foreach ($sql_query as $sql) foreach ($sql_query as $sql)
{ {
if (!$this->db->sql_query($sql)) if (!$this->db->sql_query($sql))
@ -103,6 +109,21 @@ class add_default_data extends \phpbb\install\task_base
$error = $this->db->sql_error($this->db->get_sql_error_sql()); $error = $this->db->sql_error($this->db->get_sql_error_sql());
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']); $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
} }
$i++;
// Run until there are available resources
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();
} }
} }

View File

@ -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 = sizeof($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
);
// Run until there are available resources
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';
}
}

View File

@ -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';
}
}

View File

@ -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';
}
}

View File

@ -87,9 +87,13 @@ class notify_user extends \phpbb\install\task_base
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
// We need to reload config for cases when it doesn't have all values // We need to reload config for cases when it doesn't have all values
/** @var \phpbb\cache\driver\driver_interface $cache */
$cache = $container->get('cache.driver');
$cache->destroy('config');
$this->config = new db( $this->config = new db(
$container->get('dbal.conn'), $container->get('dbal.conn'),
$container->get('cache.driver'), $cache,
$container->get_parameter('tables.config') $container->get_parameter('tables.config')
); );

View File

@ -13,11 +13,20 @@
namespace phpbb\install\module\install_finish\task; namespace phpbb\install\module\install_finish\task;
use phpbb\install\exception\resource_limit_reached_exception;
use phpbb\install\helper\config;
use phpbb\install\helper\container_factory;
/** /**
* Populates migrations * Populates migrations
*/ */
class populate_migrations extends \phpbb\install\task_base class populate_migrations extends \phpbb\install\task_base
{ {
/**
* @var config
*/
protected $config;
/** /**
* @var \phpbb\extension\manager * @var \phpbb\extension\manager
*/ */
@ -31,10 +40,12 @@ class populate_migrations extends \phpbb\install\task_base
/** /**
* Constructor * Constructor
* *
* @param \phpbb\install\helper\container_factory $container phpBB's DI contianer * @param config $config Installer's config
* @param container_factory $container phpBB's DI contianer
*/ */
public function __construct(\phpbb\install\helper\container_factory $container) public function __construct(config $config, container_factory $container)
{ {
$this->config = $config;
$this->extension_manager = $container->get('ext.manager'); $this->extension_manager = $container->get('ext.manager');
$this->migrator = $container->get('migrator'); $this->migrator = $container->get('migrator');
@ -46,6 +57,15 @@ class populate_migrations extends \phpbb\install\task_base
*/ */
public function run() public function run()
{ {
if (!$this->config->get('populate_migration_refresh_before', false))
{
if ($this->config->get_time_remaining() < 1)
{
$this->config->set('populate_migration_refresh_before', true);
throw new resource_limit_reached_exception();
}
}
$finder = $this->extension_manager->get_finder(); $finder = $this->extension_manager->get_finder();
$migrations = $finder $migrations = $finder