mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-19 15:17:16 +01:00
Merge pull request #4971 from Elsensee/ticket/15339
[ticket/15339] Use manual method when adding modules
This commit is contained in:
commit
d90680d685
@ -153,7 +153,10 @@ class release_3_0_6_rc1 extends \phpbb\db\migration\migration
|
||||
'ACP_BOARD_CONFIGURATION',
|
||||
array(
|
||||
'module_basename' => 'acp_board',
|
||||
'modes' => array('feed'),
|
||||
'module_langname' => 'ACP_FEED_SETTINGS',
|
||||
'module_mode' => 'feed',
|
||||
'module_auth' => 'acl_a_board',
|
||||
'after' => array('signature', 'ACP_SIGNATURE_SETTINGS'),
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -161,7 +164,11 @@ class release_3_0_6_rc1 extends \phpbb\db\migration\migration
|
||||
'ACP_CAT_USERS',
|
||||
array(
|
||||
'module_basename' => 'acp_users',
|
||||
'modes' => array('warnings'),
|
||||
'module_langname' => 'ACP_USER_WARNINGS',
|
||||
'module_mode' => 'warnings',
|
||||
'module_auth' => 'acl_a_user',
|
||||
'module_display' => false,
|
||||
'after' => array('feedback', 'ACP_USER_FEEDBACK'),
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -169,7 +176,9 @@ class release_3_0_6_rc1 extends \phpbb\db\migration\migration
|
||||
'ACP_SERVER_CONFIGURATION',
|
||||
array(
|
||||
'module_basename' => 'acp_send_statistics',
|
||||
'modes' => array('send_statistics'),
|
||||
'module_langname' => 'ACP_SEND_STATISTICS',
|
||||
'module_mode' => 'send_statistics',
|
||||
'module_auth' => 'acl_a_server',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -177,7 +186,10 @@ class release_3_0_6_rc1 extends \phpbb\db\migration\migration
|
||||
'ACP_FORUM_BASED_PERMISSIONS',
|
||||
array(
|
||||
'module_basename' => 'acp_permissions',
|
||||
'modes' => array('setting_forum_copy'),
|
||||
'module_langname' => 'ACP_FORUM_PERMISSIONS_COPY',
|
||||
'module_mode' => 'setting_forum_copy',
|
||||
'module_auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
|
||||
'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS'),
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -185,7 +197,29 @@ class release_3_0_6_rc1 extends \phpbb\db\migration\migration
|
||||
'MCP_REPORTS',
|
||||
array(
|
||||
'module_basename' => 'mcp_pm_reports',
|
||||
'modes' => array('pm_reports','pm_reports_closed','pm_report_details'),
|
||||
'module_langname' => 'MCP_PM_REPORTS_OPEN',
|
||||
'module_mode' => 'pm_reports',
|
||||
'module_auth' => 'acl_m_pm_report',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
'mcp',
|
||||
'MCP_REPORTS',
|
||||
array(
|
||||
'module_basename' => 'mcp_pm_reports',
|
||||
'module_langname' => 'MCP_PM_REPORTS_CLOSED',
|
||||
'module_mode' => 'pm_reports_closed',
|
||||
'module_auth' => 'acl_m_pm_report',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
'mcp',
|
||||
'MCP_REPORTS',
|
||||
array(
|
||||
'module_basename' => 'mcp_pm_reports',
|
||||
'module_langname' => 'MCP_PM_REPORT_DETAILS',
|
||||
'module_mode' => 'pm_report_details',
|
||||
'module_auth' => 'acl_m_pm_report',
|
||||
),
|
||||
)),
|
||||
array('custom', array(array(&$this, 'add_newly_registered_group'))),
|
||||
|
@ -36,7 +36,10 @@ class release_3_0_8_rc1 extends \phpbb\db\migration\migration
|
||||
'ACP_MESSAGES',
|
||||
array(
|
||||
'module_basename' => 'acp_board',
|
||||
'modes' => array('post'),
|
||||
'module_langname' => 'ACP_POST_SETTINGS',
|
||||
'module_mode' => 'post',
|
||||
'module_auth' => 'acl_a_board',
|
||||
'after' => array('message', 'ACP_MESSAGE_SETTINGS'),
|
||||
),
|
||||
)),
|
||||
array('config.add', array('load_unreads_search', 1)),
|
||||
|
@ -69,7 +69,9 @@ class auth_provider_oauth extends \phpbb\db\migration\migration
|
||||
'UCP_PROFILE',
|
||||
array(
|
||||
'module_basename' => 'ucp_auth_link',
|
||||
'modes' => array('auth_link'),
|
||||
'module_langname' => 'UCP_AUTH_LINK_MANAGE',
|
||||
'module_mode' => 'auth_link',
|
||||
'module_auth' => 'authmethod_oauth',
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
@ -23,7 +23,9 @@ class contact_admin_acp_module extends \phpbb\db\migration\migration
|
||||
'ACP_BOARD_CONFIGURATION',
|
||||
array(
|
||||
'module_basename' => 'acp_contact',
|
||||
'modes' => array('contact'),
|
||||
'module_langname' => 'ACP_CONTACT_SETTINGS',
|
||||
'module_mode' => 'contact',
|
||||
'module_auth' => 'acl_a_board',
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
@ -125,7 +125,9 @@ class dev extends \phpbb\db\migration\container_aware_migration
|
||||
'ACP_GROUPS',
|
||||
array(
|
||||
'module_basename' => 'acp_groups',
|
||||
'modes' => array('position'),
|
||||
'module_langname' => 'ACP_GROUPS_POSITION',
|
||||
'module_mode' => 'position',
|
||||
'module_auth' => 'acl_a_group',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -133,7 +135,9 @@ class dev extends \phpbb\db\migration\container_aware_migration
|
||||
'ACP_ATTACHMENTS',
|
||||
array(
|
||||
'module_basename' => 'acp_attachments',
|
||||
'modes' => array('manage'),
|
||||
'module_langname' => 'ACP_MANAGE_ATTACHMENTS',
|
||||
'module_mode' => 'manage',
|
||||
'module_auth' => 'acl_a_attach',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -141,7 +145,19 @@ class dev extends \phpbb\db\migration\container_aware_migration
|
||||
'ACP_STYLE_MANAGEMENT',
|
||||
array(
|
||||
'module_basename' => 'acp_styles',
|
||||
'modes' => array('install', 'cache'),
|
||||
'module_langname' => 'ACP_STYLES_INSTALL',
|
||||
'module_mode' => 'install',
|
||||
'module_auth' => 'acl_a_styles',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
'acp',
|
||||
'ACP_STYLE_MANAGEMENT',
|
||||
array(
|
||||
'module_basename' => 'acp_styles',
|
||||
'module_langname' => 'ACP_STYLES_CACHE',
|
||||
'module_mode' => 'cache',
|
||||
'module_auth' => 'acl_a_styles',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -149,7 +165,8 @@ class dev extends \phpbb\db\migration\container_aware_migration
|
||||
'UCP_PROFILE',
|
||||
array(
|
||||
'module_basename' => 'ucp_profile',
|
||||
'modes' => array('autologin_keys'),
|
||||
'module_langname' => 'UCP_PROFILE_AUTOLOGIN_KEYS',
|
||||
'module_mode' => 'autologin_keys',
|
||||
),
|
||||
)),
|
||||
// Module will be renamed later
|
||||
|
@ -66,7 +66,9 @@ class extensions extends \phpbb\db\migration\migration
|
||||
'ACP_EXTENSION_MANAGEMENT',
|
||||
array(
|
||||
'module_basename' => 'acp_extensions',
|
||||
'modes' => array('main'),
|
||||
'module_langname' => 'ACP_EXTENSIONS',
|
||||
'module_mode' => 'main',
|
||||
'module_auth' => 'acl_a_extensions',
|
||||
),
|
||||
)),
|
||||
array('permission.add', array('a_extensions', true, 'a_styles')),
|
||||
|
@ -85,7 +85,9 @@ class notifications extends \phpbb\db\migration\migration
|
||||
'UCP_MAIN',
|
||||
array(
|
||||
'module_basename' => 'ucp_notifications',
|
||||
'modes' => array('notification_list'),
|
||||
'module_langname' => 'UCP_NOTIFICATION_LIST',
|
||||
'module_mode' => 'notification_list',
|
||||
'module_auth' => 'cfg_allow_board_notifications',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -93,7 +95,8 @@ class notifications extends \phpbb\db\migration\migration
|
||||
'UCP_PREFS',
|
||||
array(
|
||||
'module_basename' => 'ucp_notifications',
|
||||
'modes' => array('notification_options'),
|
||||
'module_langname' => 'UCP_NOTIFICATION_OPTIONS',
|
||||
'module_mode' => 'notification_options',
|
||||
),
|
||||
)),
|
||||
array('config.add', array('load_notifications', 1)),
|
||||
|
@ -45,7 +45,9 @@ class softdelete_mcp_modules extends \phpbb\db\migration\migration
|
||||
'MCP_QUEUE',
|
||||
array(
|
||||
'module_basename' => 'mcp_queue',
|
||||
'modes' => array('deleted_topics'),
|
||||
'module_langname' => 'MCP_QUEUE_DELETED_TOPICS',
|
||||
'module_mode' => 'deleted_topics',
|
||||
'module_auth' => 'aclf_m_approve',
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
@ -53,7 +55,9 @@ class softdelete_mcp_modules extends \phpbb\db\migration\migration
|
||||
'MCP_QUEUE',
|
||||
array(
|
||||
'module_basename' => 'mcp_queue',
|
||||
'modes' => array('deleted_posts'),
|
||||
'module_langname' => 'MCP_QUEUE_DELETED_POSTS',
|
||||
'module_mode' => 'deleted_posts',
|
||||
'module_auth' => 'aclf_m_approve',
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
@ -41,7 +41,9 @@ class add_help_phpbb extends \phpbb\db\migration\migration
|
||||
'ACP_SERVER_CONFIGURATION',
|
||||
array(
|
||||
'module_basename' => 'acp_help_phpbb',
|
||||
'modes' => array('help_phpbb'),
|
||||
'module_langname' => 'ACP_HELP_PHPBB',
|
||||
'module_mode' => 'help_phpbb',
|
||||
'module_auth' => 'acl_a_server',
|
||||
),
|
||||
)),
|
||||
);
|
||||
|
@ -84,9 +84,11 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
* Use false to ignore the parent check and check class wide.
|
||||
* @param int|string $module The module_id|module_langname you would like to
|
||||
* check for to see if it exists
|
||||
* @return bool true/false if module exists
|
||||
* @param bool $lazy Checks lazily if the module exists. Returns true if it exists in at
|
||||
* least one given parent.
|
||||
* @return bool true if module exists in *all* given parents, false if not
|
||||
*/
|
||||
public function exists($class, $parent, $module)
|
||||
public function exists($class, $parent, $module, $lazy = false)
|
||||
{
|
||||
// the main root directory should return true
|
||||
if (!$module)
|
||||
@ -94,33 +96,44 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
return true;
|
||||
}
|
||||
|
||||
$parent_sql = '';
|
||||
$parent_sqls = [];
|
||||
if ($parent !== false)
|
||||
{
|
||||
$parent = $this->get_parent_module_id($parent, $module, false);
|
||||
if ($parent === false)
|
||||
$parents = $this->get_parent_module_id($parent, $module, false);
|
||||
if ($parents === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$parent_sql = 'AND parent_id = ' . (int) $parent;
|
||||
foreach ((array) $parents as $parent_id)
|
||||
{
|
||||
$parent_sqls[] = 'AND parent_id = ' . (int) $parent_id;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
$parent_sql
|
||||
AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '" . $this->db->sql_escape($module) . "'");
|
||||
$result = $this->db->sql_query($sql);
|
||||
$module_id = $this->db->sql_fetchfield('module_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($module_id)
|
||||
foreach ($parent_sqls as $parent_sql)
|
||||
{
|
||||
return true;
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
$parent_sql
|
||||
AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '" . $this->db->sql_escape($module) . "'");
|
||||
$result = $this->db->sql_query($sql);
|
||||
$module_id = $this->db->sql_fetchfield('module_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (!$lazy && !$module_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ($lazy && $module_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// Returns true, if modules exist in all parents and false otherwise
|
||||
return !$lazy;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,7 +185,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
$data = array('module_langname' => $data);
|
||||
}
|
||||
|
||||
$parent = $data['parent_id'] = $this->get_parent_module_id($parent, $data);
|
||||
$parents = (array) $this->get_parent_module_id($parent, $data);
|
||||
|
||||
if (!isset($data['module_langname']))
|
||||
{
|
||||
@ -195,95 +208,131 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
);
|
||||
|
||||
// Run the "manual" way with the data we've collected.
|
||||
$this->add($class, $parent, $new_module);
|
||||
foreach ($parents as $parent)
|
||||
{
|
||||
$this->add($class, $parent, $new_module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// The "manual" way
|
||||
if (!$this->exists($class, false, $parent))
|
||||
foreach ($parents as $parent)
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent);
|
||||
}
|
||||
$data['parent_id'] = $parent;
|
||||
|
||||
if ($this->exists($class, $parent, $data['module_langname']))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_EXISTS', $data['module_langname']);
|
||||
}
|
||||
|
||||
$module_data = array(
|
||||
'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,
|
||||
'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1,
|
||||
'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '',
|
||||
'module_class' => $class,
|
||||
'parent_id' => (int) $parent,
|
||||
'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '',
|
||||
'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '',
|
||||
'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
$this->module_manager->update_module_data($module_data);
|
||||
|
||||
// Success
|
||||
$module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']);
|
||||
$phpbb_log->add('admin', (isset($user->data['user_id'])) ? $user->data['user_id'] : ANONYMOUS, $user->ip, 'LOG_MODULE_ADD', false, array($module_log_name));
|
||||
|
||||
// Move the module if requested above/below an existing one
|
||||
if (isset($data['before']) && $data['before'])
|
||||
// The "manual" way
|
||||
if (!$this->exists($class, false, $parent))
|
||||
{
|
||||
$sql = 'SELECT left_id
|
||||
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent);
|
||||
}
|
||||
|
||||
if ($this->exists($class, $parent, $data['module_langname']))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_EXISTS', $data['module_langname']);
|
||||
}
|
||||
|
||||
$module_data = array(
|
||||
'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,
|
||||
'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1,
|
||||
'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '',
|
||||
'module_class' => $class,
|
||||
'parent_id' => (int) $parent,
|
||||
'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '',
|
||||
'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '',
|
||||
'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
$this->module_manager->update_module_data($module_data);
|
||||
|
||||
// Success
|
||||
$module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']);
|
||||
$phpbb_log->add('admin', (isset($user->data['user_id'])) ? $user->data['user_id'] : ANONYMOUS, $user->ip, 'LOG_MODULE_ADD', false, array($module_log_name));
|
||||
|
||||
// Move the module if requested above/below an existing one
|
||||
if (isset($data['before']) && $data['before'])
|
||||
{
|
||||
$before_mode = $before_langname = '';
|
||||
if (is_array($data['before']))
|
||||
{
|
||||
// Restore legacy-legacy behaviour from phpBB 3.0
|
||||
list($before_mode, $before_langname) = $data['before'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Legacy behaviour from phpBB 3.1+
|
||||
$before_langname = $data['before'];
|
||||
}
|
||||
|
||||
$sql = 'SELECT left_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND parent_id = " . (int) $parent . "
|
||||
AND module_langname = '" . $this->db->sql_escape($data['before']) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$to_left = (int) $this->db->sql_fetchfield('left_id');
|
||||
AND module_langname = '" . $this->db->sql_escape($before_langname) . "'"
|
||||
. (($before_mode) ? " AND module_mode = '" . $this->db->sql_escape($before_mode) . "'" : '');
|
||||
$result = $this->db->sql_query($sql);
|
||||
$to_left = (int) $this->db->sql_fetchfield('left_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = left_id + 2, right_id = right_id + 2
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND left_id >= $to_left
|
||||
AND left_id < {$module_data['left_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = $to_left, right_id = " . ($to_left + 1) . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND module_id = {$module_data['module_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
else if (isset($data['after']) && $data['after'])
|
||||
{
|
||||
$sql = 'SELECT right_id
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
else if (isset($data['after']) && $data['after'])
|
||||
{
|
||||
$after_mode = $after_langname = '';
|
||||
if (is_array($data['after']))
|
||||
{
|
||||
// Restore legacy-legacy behaviour from phpBB 3.0
|
||||
list($after_mode, $after_langname) = $data['after'];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Legacy behaviour from phpBB 3.1+
|
||||
$after_langname = $data['after'];
|
||||
}
|
||||
|
||||
$sql = 'SELECT right_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND parent_id = " . (int) $parent . "
|
||||
AND module_langname = '" . $this->db->sql_escape($data['after']) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$to_right = (int) $this->db->sql_fetchfield('right_id');
|
||||
AND module_langname = '" . $this->db->sql_escape($after_langname) . "'"
|
||||
. (($after_mode) ? " AND module_mode = '" . $this->db->sql_escape($after_mode) . "'" : '');
|
||||
$result = $this->db->sql_query($sql);
|
||||
$to_right = (int) $this->db->sql_fetchfield('right_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = left_id + 2, right_id = right_id + 2
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND left_id >= $to_right
|
||||
AND left_id < {$module_data['left_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . '
|
||||
$sql = 'UPDATE ' . $this->modules_table . '
|
||||
SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND module_id = {$module_data['module_id']}";
|
||||
$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());
|
||||
}
|
||||
}
|
||||
catch (module_exception $e)
|
||||
{
|
||||
// Error
|
||||
throw new \phpbb\db\migration\exception('MODULE_ERROR', $e->getMessage());
|
||||
}
|
||||
|
||||
// Clear the Modules Cache
|
||||
@ -334,7 +383,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$this->exists($class, $parent, $module))
|
||||
if (!$this->exists($class, $parent, $module, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -342,8 +391,8 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
$parent_sql = '';
|
||||
if ($parent !== false)
|
||||
{
|
||||
$parent = $this->get_parent_module_id($parent, $module);
|
||||
$parent_sql = 'AND parent_id = ' . (int) $parent;
|
||||
$parents = (array) $this->get_parent_module_id($parent, $module);
|
||||
$parent_sql = 'AND ' . $this->db->sql_in_set('parent_id', $parents);
|
||||
}
|
||||
|
||||
$module_ids = array();
|
||||
@ -457,14 +506,11 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
* @param string|int $parent_id The parent module_id|module_langname
|
||||
* @param int|string|array $data The module_id, module_langname for existance checking or module data array for adding
|
||||
* @param bool $throw_exception The flag indicating if exception should be thrown on error
|
||||
* @return mixed The int parent module_id or false
|
||||
* @return mixed The int parent module_id, an array of int parent module_id values or false
|
||||
* @throws \phpbb\db\migration\exception
|
||||
*/
|
||||
public function get_parent_module_id($parent_id, $data = '', $throw_exception = true)
|
||||
{
|
||||
// Initialize exception object placeholder
|
||||
$exception = false;
|
||||
|
||||
// Allow '' to be sent as 0
|
||||
$parent_id = $parent_id ?: 0;
|
||||
|
||||
@ -486,61 +532,26 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||
{
|
||||
// No parent with the given module_langname exist
|
||||
case 0:
|
||||
$exception = new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);
|
||||
if ($throw_exception)
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
break;
|
||||
|
||||
// Return the module id
|
||||
case 1:
|
||||
$parent_id = (int) $ids[0];
|
||||
return (int) $ids[0];
|
||||
break;
|
||||
|
||||
// Several modules with the given module_langname were found
|
||||
// Try to determine the parent_id by the neighbour module parent
|
||||
default:
|
||||
if (is_array($data) && (isset($data['before']) || isset($data['after'])))
|
||||
{
|
||||
$neighbour_module_langname = isset($data['before']) ? $data['before'] : $data['after'];
|
||||
$sql = 'SELECT parent_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_langname = '" . $this->db->sql_escape($neighbour_module_langname) . "'
|
||||
AND " . $this->db->sql_in_set('parent_id', $ids);
|
||||
$result = $this->db->sql_query($sql);
|
||||
$parent_id = (int) $this->db->sql_fetchfield('parent_id');
|
||||
if (!$parent_id)
|
||||
{
|
||||
$exception = new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']);
|
||||
}
|
||||
}
|
||||
else if (!empty($data) && !is_array($data))
|
||||
{
|
||||
// The module_langname is set, checking for the module existance
|
||||
// As more than 1 parents were found already, there's no way for null parent_id here
|
||||
$sql = 'SELECT m2.module_id as module_parent_id
|
||||
FROM ' . $this->modules_table . ' m1, ' . $this->modules_table . " m2
|
||||
WHERE " . ((is_numeric($data)) ? 'm1.module_id = ' . (int) $data : "m1.module_langname = '" . $this->db->sql_escape($data)) . "'
|
||||
AND m2.module_id = m1.parent_id
|
||||
AND " . $this->db->sql_in_set('m2.module_id', $ids);
|
||||
$result = $this->db->sql_query($sql);
|
||||
$parent_id = (int) $this->db->sql_fetchfield('module_parent_id');
|
||||
}
|
||||
else
|
||||
{
|
||||
//Unable to get the parent module id, throwing an exception
|
||||
$exception = new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id);
|
||||
}
|
||||
// This represents the old behaviour of phpBB 3.0
|
||||
return $ids;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($exception !== false)
|
||||
{
|
||||
if ($throw_exception)
|
||||
{
|
||||
throw $exception;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return $parent_id;
|
||||
}
|
||||
}
|
||||
|
@ -193,25 +193,6 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE'));
|
||||
|
||||
// Test adding module when plural parent module_langname exists
|
||||
// PHPBB3-14703
|
||||
// Adding fail
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 'ACP_FORUM_BASED_PERMISSIONS', array(
|
||||
'module_basename' => 'acp_new_permissions_module',
|
||||
'module_langname' => 'ACP_NEW_PERMISSIONS_MODULE',
|
||||
'module_mode' => 'test',
|
||||
'module_auth' => '',
|
||||
));
|
||||
$this->fail('Exception not thrown');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->assertEquals('phpbb\db\migration\exception', get_class($e));
|
||||
$this->assertEquals('MODULE_EXIST_MULTIPLE', $e->getMessage());
|
||||
}
|
||||
|
||||
// Test adding module when plural parent module_langname exists
|
||||
// PHPBB3-14703
|
||||
// Adding success
|
||||
|
Loading…
x
Reference in New Issue
Block a user