diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml
index 6577a44195..cab82a5d9c 100644
--- a/phpBB/config/default/container/services.yml
+++ b/phpBB/config/default/container/services.yml
@@ -10,7 +10,9 @@ imports:
- { resource: services_feed.yml }
- { resource: services_help.yml }
- { resource: services_language.yml }
+ - { resource: services_migrator.yml }
- { resource: services_mimetype_guesser.yml }
+ - { resource: services_module.yml }
- { resource: services_notification.yml }
- { resource: services_password.yml }
- { resource: services_profilefield.yml }
diff --git a/phpBB/config/default/container/services_db.yml b/phpBB/config/default/container/services_db.yml
index ae2707b9a5..ed3f88c704 100644
--- a/phpBB/config/default/container/services_db.yml
+++ b/phpBB/config/default/container/services_db.yml
@@ -79,66 +79,3 @@ services:
- %core.root_path%
- @request
- @dbal.conn.driver
-
-# ----- Migrator -----
- migrator:
- class: phpbb\db\migrator
- arguments:
- - @service_container
- - @config
- - @dbal.conn
- - @dbal.tools
- - %tables.migrations%
- - %core.root_path%
- - %core.php_ext%
- - %core.table_prefix%
- - @migrator.tool_collection
- - @migrator.helper
-
- migrator.helper:
- class: phpbb\db\migration\helper
-
-# ----- Migrator's tools -----
- migrator.tool_collection:
- class: phpbb\di\service_collection
- arguments:
- - @service_container
- tags:
- - { name: service_collection, tag: migrator.tool }
-
- migrator.tool.config:
- class: phpbb\db\migration\tool\config
- arguments:
- - @config
- tags:
- - { name: migrator.tool }
-
- migrator.tool.config_text:
- class: phpbb\db\migration\tool\config_text
- arguments:
- - @config_text
- tags:
- - { name: migrator.tool }
-
- migrator.tool.module:
- class: phpbb\db\migration\tool\module
- arguments:
- - @dbal.conn
- - @cache
- - @user
- - %core.root_path%
- - %core.php_ext%
- - %tables.modules%
- tags:
- - { name: migrator.tool }
-
- migrator.tool.permission:
- class: phpbb\db\migration\tool\permission
- arguments:
- - @dbal.conn
- - @cache
- - @auth
- - %core.root_path%
- - %core.php_ext%
- tags:
- - { name: migrator.tool }
diff --git a/phpBB/config/default/container/services_migrator.yml b/phpBB/config/default/container/services_migrator.yml
index cd04eea5c2..01bd7d3a11 100644
--- a/phpBB/config/default/container/services_migrator.yml
+++ b/phpBB/config/default/container/services_migrator.yml
@@ -1,7 +1,9 @@
services:
+# ----- Migrator -----
migrator:
class: phpbb\db\migrator
arguments:
+ - @service_container
- @config
- @dbal.conn
- @dbal.tools
@@ -15,6 +17,7 @@ services:
migrator.helper:
class: phpbb\db\migration\helper
+# ----- Migrator's tools -----
migrator.tool_collection:
class: phpbb\di\service_collection
arguments:
@@ -42,6 +45,7 @@ services:
- @dbal.conn
- @cache
- @user
+ - @module.manager
- %core.root_path%
- %core.php_ext%
- %tables.modules%
diff --git a/phpBB/config/default/container/services_module.yml b/phpBB/config/default/container/services_module.yml
new file mode 100644
index 0000000000..513b71553a
--- /dev/null
+++ b/phpBB/config/default/container/services_module.yml
@@ -0,0 +1,10 @@
+services:
+ module.manager:
+ class: phpbb\module\module_manager
+ arguments:
+ - @cache.driver
+ - @dbal.conn
+ - @ext.manager
+ - %tables.modules%
+ - %core.root_path%
+ - %core.php_ext%
diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php
index 4fca366868..c2407f15b4 100644
--- a/phpBB/includes/acp/acp_modules.php
+++ b/phpBB/includes/acp/acp_modules.php
@@ -19,6 +19,8 @@ if (!defined('IN_PHPBB'))
exit;
}
+use phpbb\module\exception\module_exception;
+
/**
* - Able to check for new module versions (modes changed/adjusted/added/removed)
* Icons for:
@@ -37,8 +39,10 @@ class acp_modules
function main($id, $mode)
{
- global $db, $user, $auth, $template, $module, $request, $phpbb_log;
- global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
+ global $db, $user, $template, $module, $request, $phpbb_log, $phpbb_container;
+
+ /** @var \phpbb\module\module_manager $module_manager */
+ $module_manager = $phpbb_container->get('module.manager');
// Set a global define for modules we might include (the author is able to prevent execution of code by checking this constant)
define('MODULE_INCLUDE', true);
@@ -91,13 +95,20 @@ class acp_modules
$db->sql_freeresult($result);
}
- $errors = $this->delete_module($module_id);
-
- if (!sizeof($errors))
+ try
{
- $this->remove_cache_file();
- trigger_error($user->lang['MODULE_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
+ $row = $module_manager->get_module_row($module_id, $this->module_class);
+ $module_manager->delete_module($module_id, $this->module_class);
+ $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_REMOVED', false, array($user->lang($row['module_langname'])));
}
+ catch (module_exception $e)
+ {
+ $msg = $user->lang($e->getMessage());
+ trigger_error($msg . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
+ }
+
+ $module_manager->remove_cache_file($this->module_class);
+ trigger_error($user->lang['MODULE_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
}
else
{
@@ -138,8 +149,8 @@ class acp_modules
AND module_id = $module_id";
$db->sql_query($sql);
- $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_' . strtoupper($action), false, array($this->lang_name($row['module_langname'])));
- $this->remove_cache_file();
+ $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_' . strtoupper($action), false, array($user->lang($row['module_langname'])));
+ $module_manager->remove_cache_file($this->module_class);
break;
@@ -163,12 +174,16 @@ class acp_modules
trigger_error($user->lang['NO_MODULE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
}
- $move_module_name = $this->move_module_by($row, $action, 1);
-
- if ($move_module_name !== false)
+ try
{
- $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_' . strtoupper($action), false, array($this->lang_name($row['module_langname']), $move_module_name));
- $this->remove_cache_file();
+ $move_module_name = $module_manager->move_module_by($row, $this->module_class, $action, 1);
+
+ $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_' . strtoupper($action), false, array($user->lang($row['module_langname']), $move_module_name));
+ $module_manager->remove_cache_file($this->module_class);
+ }
+ catch (module_exception $e)
+ {
+ // Do nothing
}
if ($request->is_ajax())
@@ -194,7 +209,7 @@ class acp_modules
list($module_basename, $module_mode) = explode('::', $quick_install);
// Check if module name and mode exist...
- $fileinfo = $this->get_module_infos($module_basename);
+ $fileinfo = $module_manager->get_module_infos($this->module_class, $module_basename);
$fileinfo = $fileinfo[$module_basename];
if (isset($fileinfo['modes'][$module_mode]))
@@ -210,11 +225,20 @@ class acp_modules
'module_auth' => $fileinfo['modes'][$module_mode]['auth'],
);
- $errors = $this->update_module_data($module_data);
+ try
+ {
+ $module_manager->update_module_data($module_data);
+ $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_ADD', false, array($user->lang($module_data['module_langname'])));
+ }
+ catch (\phpbb\module\exception\module_exception $e)
+ {
+ $msg = $user->lang($e->getMessage());
+ trigger_error($msg . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
+ }
if (!sizeof($errors))
{
- $this->remove_cache_file();
+ $module_manager->remove_cache_file($this->module_class);
trigger_error($user->lang['MODULE_ADDED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
}
@@ -240,7 +264,15 @@ class acp_modules
trigger_error($user->lang['NO_MODULE_ID'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
}
- $module_row = $this->get_module_row($module_id);
+ try
+ {
+ $module_row = $module_manager->get_module_row($module_id, $this->module_class);
+ }
+ catch (\phpbb\module\exception\module_not_found_exception $e)
+ {
+ $msg = $user->lang($e->getMessage());
+ trigger_error($msg . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
+ }
// no break
@@ -294,15 +326,29 @@ class acp_modules
// Adjust auth row
if ($module_data['module_basename'] && $module_data['module_mode'])
{
- $fileinfo = $this->get_module_infos($module_data['module_basename']);
+ $fileinfo = $module_manager->get_module_infos($this->module_class, $module_data['module_basename']);
$module_data['module_auth'] = $fileinfo[$module_data['module_basename']]['modes'][$module_data['module_mode']]['auth'];
}
- $errors = $this->update_module_data($module_data);
+ try
+ {
+ $module_manager->update_module_data($module_data);
+ $phpbb_log->add('admin',
+ $user->data['user_id'],
+ $user->ip,
+ ($action === 'edit') ? 'LOG_MODULE_EDIT' : 'LOG_MODULE_ADD',
+ false,
+ array($user->lang($module_data['module_langname']))
+ ); }
+ catch (\phpbb\module\exception\module_exception $e)
+ {
+ $msg = $user->lang($e->getMessage());
+ trigger_error($msg . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
+ }
if (!sizeof($errors))
{
- $this->remove_cache_file();
+ $module_manager->remove_cache_file($this->module_class);
trigger_error((($action == 'add') ? $user->lang['MODULE_ADDED'] : $user->lang['MODULE_EDITED']) . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
}
@@ -312,7 +358,7 @@ class acp_modules
$is_cat = (!$module_data['module_basename']) ? true : false;
// Get module information
- $module_infos = $this->get_module_infos();
+ $module_infos = $module_manager->get_module_infos($this->module_class);
// Build name options
$s_name_options = $s_mode_options = '';
@@ -324,7 +370,7 @@ class acp_modules
}
// Name options
- $s_name_options .= '';
+ $s_name_options .= '';
$template->assign_block_vars('m_names', array('NAME' => $option, 'A_NAME' => addslashes($option)));
@@ -333,14 +379,14 @@ class acp_modules
{
if ($option == $module_data['module_basename'])
{
- $s_mode_options .= '';
+ $s_mode_options .= '';
}
$template->assign_block_vars('m_names.modes', array(
'OPTION' => $m_mode,
- 'VALUE' => $this->lang_name($m_values['title']),
+ 'VALUE' => $user->lang($m_values['title']),
'A_OPTION' => addslashes($m_mode),
- 'A_VALUE' => addslashes($this->lang_name($m_values['title'])))
+ 'A_VALUE' => addslashes($user->lang($m_values['title'])))
);
}
}
@@ -358,7 +404,7 @@ class acp_modules
'L_TITLE' => $user->lang[strtoupper($action) . '_MODULE'],
- 'MODULENAME' => $this->lang_name($module_data['module_langname']),
+ 'MODULENAME' => $user->lang($module_data['module_langname']),
'ACTION' => $action,
'MODULE_ID' => $module_id,
@@ -406,11 +452,11 @@ class acp_modules
{
$navigation = '' . strtoupper($this->module_class) . '';
- $modules_nav = $this->get_module_branch($this->parent_id, 'parents', 'descending');
+ $modules_nav = $module_manager->get_module_branch($this->parent_id, $this->module_class, 'parents');
foreach ($modules_nav as $row)
{
- $langname = $this->lang_name($row['module_langname']);
+ $langname = $user->lang($row['module_langname']);
if ($row['module_id'] == $this->parent_id)
{
@@ -437,7 +483,7 @@ class acp_modules
{
do
{
- $langname = $this->lang_name($row['module_langname']);
+ $langname = $user->lang($row['module_langname']);
if (!$row['module_enabled'])
{
@@ -472,7 +518,15 @@ class acp_modules
}
else if ($this->parent_id)
{
- $row = $this->get_module_row($this->parent_id);
+ try
+ {
+ $row = $module_manager->get_module_row($this->parent_id, $this->module_class);
+ }
+ catch (\phpbb\module\exception\module_not_found_exception $e)
+ {
+ $msg = $user->lang($e->getMessage());
+ trigger_error($msg . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
+ }
$url = $this->u_action . '&parent_id=' . $this->parent_id . '&m=' . $row['module_id'];
@@ -491,19 +545,19 @@ class acp_modules
$db->sql_freeresult($result);
// Quick adding module
- $module_infos = $this->get_module_infos();
+ $module_infos = $module_manager->get_module_infos($this->module_class);
// Build quick options
$s_install_options = '';
foreach ($module_infos as $option => $values)
{
// Name options
- $s_install_options .= '