1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-26 03:22:37 +02:00

[ticket/13777] Use module manager in phpBB core files

PHPBB3-13777
This commit is contained in:
MateBartus
2015-05-31 13:21:45 +02:00
parent e877a752be
commit 77ee0e62ca
4 changed files with 47 additions and 71 deletions

View File

@@ -1552,9 +1552,14 @@ class install_install extends module
$phpbb_extension_manager = $phpbb_container->get('ext.manager'); $phpbb_extension_manager = $phpbb_container->get('ext.manager');
} }
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); $_module = new \phpbb\module\module_manager(
new \phpbb\cache\driver\dummy(),
$_module = new acp_modules(); $db,
$phpbb_extension_manager,
MODULES_TABLE,
$phpbb_root_path,
$phpEx
);
$module_classes = array('acp', 'mcp', 'ucp'); $module_classes = array('acp', 'mcp', 'ucp');
// Add categories // Add categories
@@ -1585,7 +1590,7 @@ class install_install extends module
); );
// Add category // Add category
$_module->update_module_data($module_data, true); $_module->update_module_data($module_data);
// Check for last sql error happened // Check for last sql error happened
if ($db->get_sql_error_triggered()) if ($db->get_sql_error_triggered())
@@ -1619,7 +1624,7 @@ class install_install extends module
'module_auth' => '', 'module_auth' => '',
); );
$_module->update_module_data($module_data, true); $_module->update_module_data($module_data);
// Check for last sql error happened // Check for last sql error happened
if ($db->get_sql_error_triggered()) if ($db->get_sql_error_triggered())
@@ -1659,7 +1664,7 @@ class install_install extends module
'module_auth' => $row['auth'], 'module_auth' => $row['auth'],
); );
$_module->update_module_data($module_data, true); $_module->update_module_data($module_data);
// Check for last sql error happened // Check for last sql error happened
if ($db->get_sql_error_triggered()) if ($db->get_sql_error_triggered())
@@ -1684,7 +1689,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_up', 4); $_module->move_module_by($row, 'acp', 'move_up', 4);
// Move permissions intro screen module 4 up... // Move permissions intro screen module 4 up...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1696,7 +1701,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_up', 4); $_module->move_module_by($row, 'acp', 'move_up', 4);
// Move manage users screen module 5 up... // Move manage users screen module 5 up...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1708,7 +1713,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_up', 5); $_module->move_module_by($row, 'acp', 'move_up', 5);
// Move extension management module 1 up... // Move extension management module 1 up...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1721,7 +1726,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_up', 1); $_module->move_module_by($row, 'acp', 'move_up', 1);
} }
if ($module_class == 'mcp') if ($module_class == 'mcp')
@@ -1736,7 +1741,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_down', 3); $_module->move_module_by($row, 'mcp', 'move_down', 3);
// Move closed pm reports module 3 down... // Move closed pm reports module 3 down...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1748,7 +1753,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_down', 3); $_module->move_module_by($row, 'mcp', 'move_down', 3);
// Move open pm reports module 3 down... // Move open pm reports module 3 down...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1760,7 +1765,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_down', 3); $_module->move_module_by($row, 'mcp', 'move_down', 3);
} }
if ($module_class == 'ucp') if ($module_class == 'ucp')
@@ -1775,7 +1780,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_down', 4); $_module->move_module_by($row, 'ucp', 'move_down', 4);
// Move notification options module 4 down... // Move notification options module 4 down...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1787,7 +1792,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_down', 4); $_module->move_module_by($row, 'ucp', 'move_down', 4);
// Move OAuth module 5 down... // Move OAuth module 5 down...
$sql = 'SELECT * $sql = 'SELECT *
@@ -1799,7 +1804,7 @@ class install_install extends module
$row = $db->sql_fetchrow($result); $row = $db->sql_fetchrow($result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
$_module->move_module_by($row, 'move_down', 5); $_module->move_module_by($row, 'ucp', 'move_down', 5);
} }
// And now for the special ones // And now for the special ones
@@ -1838,7 +1843,7 @@ class install_install extends module
'module_auth' => $row['module_auth'], 'module_auth' => $row['module_auth'],
); );
$_module->update_module_data($module_data, true); $_module->update_module_data($module_data);
// Check for last sql error happened // Check for last sql error happened
if ($db->get_sql_error_triggered()) if ($db->get_sql_error_triggered())
@@ -1850,7 +1855,7 @@ class install_install extends module
} }
} }
$_module->remove_cache_file(); $_module->remove_cache_file($module_class);
} }
} }

View File

@@ -13,7 +13,7 @@
namespace phpbb\db\migration\data\v310; namespace phpbb\db\migration\data\v310;
class acp_prune_users_module extends \phpbb\db\migration\migration class acp_prune_users_module extends \phpbb\db\migration\container_aware_migration
{ {
public function effectively_installed() public function effectively_installed()
{ {
@@ -70,12 +70,7 @@ class acp_prune_users_module extends \phpbb\db\migration\migration
$acp_cat_users_id = (int) $this->db->sql_fetchfield('module_id'); $acp_cat_users_id = (int) $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!class_exists('\acp_modules')) $module_manager = $this->container->get('module.manager');
{ $module_manager->move_module($acp_prune_users_id, $acp_cat_users_id, 'acp');
include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);
}
$module_manager = new \acp_modules();
$module_manager->module_class = 'acp';
$module_manager->move_module($acp_prune_users_id, $acp_cat_users_id);
} }
} }

View File

@@ -13,7 +13,7 @@
namespace phpbb\db\migration\data\v310; namespace phpbb\db\migration\data\v310;
class dev extends \phpbb\db\migration\migration class dev extends \phpbb\db\migration\container_aware_migration
{ {
public function effectively_installed() public function effectively_installed()
{ {
@@ -204,18 +204,13 @@ class dev extends \phpbb\db\migration\migration
$language_management_module_id = $this->db->sql_fetchfield('module_id'); $language_management_module_id = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!class_exists('acp_modules'))
{
include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);
}
// acp_modules calls adm_back_link, which is undefined at this point // acp_modules calls adm_back_link, which is undefined at this point
if (!function_exists('adm_back_link')) if (!function_exists('adm_back_link'))
{ {
include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext);
} }
$module_manager = new \acp_modules(); $module_manager = $this->container->get('module.manager');
$module_manager->module_class = 'acp'; $module_manager->move_module($language_module_id, $language_management_module_id, 'acp');
$module_manager->move_module($language_module_id, $language_management_module_id);
} }
public function update_ucp_pm_basename() public function update_ucp_pm_basename()

View File

@@ -13,6 +13,8 @@
namespace phpbb\db\migration\tool; namespace phpbb\db\migration\tool;
use phpbb\module\exception\module_exception;
/** /**
* Migration module management tool * Migration module management tool
*/ */
@@ -27,6 +29,9 @@ class module implements \phpbb\db\migration\tool\tool_interface
/** @var \phpbb\user */ /** @var \phpbb\user */
protected $user; protected $user;
/** @var \phpbb\module\module_manager */
protected $module_manager;
/** @var string */ /** @var string */
protected $phpbb_root_path; protected $phpbb_root_path;
@@ -42,15 +47,17 @@ class module implements \phpbb\db\migration\tool\tool_interface
* @param \phpbb\db\driver\driver_interface $db * @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache * @param \phpbb\cache\service $cache
* @param \phpbb\user $user * @param \phpbb\user $user
* @param \phpbb\module\module_manager $module_manager
* @param string $phpbb_root_path * @param string $phpbb_root_path
* @param string $php_ext * @param string $php_ext
* @param string $modules_table * @param string $modules_table
*/ */
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\user $user, $phpbb_root_path, $php_ext, $modules_table) public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\user $user, \phpbb\module\module_manager $module_manager, $phpbb_root_path, $php_ext, $modules_table)
{ {
$this->db = $db; $this->db = $db;
$this->cache = $cache; $this->cache = $cache;
$this->user = $user; $this->user = $user;
$this->module_manager = $module_manager;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
$this->modules_table = $modules_table; $this->modules_table = $modules_table;
@@ -188,7 +195,6 @@ class module implements \phpbb\db\migration\tool\tool_interface
$basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; $basename = (isset($data['module_basename'])) ? $data['module_basename'] : '';
$module = $this->get_module_info($class, $basename); $module = $this->get_module_info($class, $basename);
$result = '';
foreach ($module['modes'] as $mode => $module_info) foreach ($module['modes'] as $mode => $module_info)
{ {
if (!isset($data['modes']) || in_array($mode, $data['modes'])) if (!isset($data['modes']) || in_array($mode, $data['modes']))
@@ -239,13 +245,6 @@ class module implements \phpbb\db\migration\tool\tool_interface
return; return;
} }
if (!class_exists('acp_modules'))
{
include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);
$this->user->add_lang('acp/modules');
}
$acp_modules = new \acp_modules();
$module_data = array( $module_data = array(
'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,
'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1,
@@ -256,16 +255,11 @@ class module implements \phpbb\db\migration\tool\tool_interface
'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '',
'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
); );
$result = $acp_modules->update_module_data($module_data, true);
// update_module_data can either return a string or an empty array... try
if (is_string($result))
{
// Error
throw new \phpbb\db\migration\exception('MODULE_ERROR', $result);
}
else
{ {
$this->module_manager->update_module_data($module_data);
// Success // Success
$module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']); $module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']);
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_ADD', false, array($module_log_name)); $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODULE_ADD', false, array($module_log_name));
@@ -318,6 +312,11 @@ class module implements \phpbb\db\migration\tool\tool_interface
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
} }
catch (module_exception $e)
{
// Error
throw new \phpbb\db\migration\exception('MODULE_ERROR', $e->getMessage());
}
// Clear the Modules Cache // Clear the Modules Cache
$this->cache->destroy("_modules_$class"); $this->cache->destroy("_modules_$class");
@@ -417,21 +416,9 @@ class module implements \phpbb\db\migration\tool\tool_interface
$module_ids[] = (int) $module; $module_ids[] = (int) $module;
} }
if (!class_exists('acp_modules'))
{
include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);
$this->user->add_lang('acp/modules');
}
$acp_modules = new \acp_modules();
$acp_modules->module_class = $class;
foreach ($module_ids as $module_id) foreach ($module_ids as $module_id)
{ {
$result = $acp_modules->delete_module($module_id); $this->module_manager->delete_module($module_id, $class);
if (!empty($result))
{
return;
}
} }
$this->cache->destroy("_modules_$class"); $this->cache->destroy("_modules_$class");
@@ -474,13 +461,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
*/ */
protected function get_module_info($class, $basename) protected function get_module_info($class, $basename)
{ {
if (!class_exists('acp_modules')) $module = $this->module_manager->get_module_infos($basename, $class, true);
{
include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext);
$this->user->add_lang('acp/modules');
}
$acp_modules = new \acp_modules();
$module = $acp_modules->get_module_infos($basename, $class, true);
if (empty($module)) if (empty($module))
{ {