mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[feature/migrations] Migrations now somewhat works
PHPBB3-9737
This commit is contained in:
parent
826607a405
commit
5c91e2569c
44 changed files with 1375 additions and 3419 deletions
49
phpBB/config/migrator.yml
Normal file
49
phpBB/config/migrator.yml
Normal file
|
@ -0,0 +1,49 @@
|
|||
services:
|
||||
migrator:
|
||||
class: phpbb_db_migrator
|
||||
arguments:
|
||||
- @config
|
||||
- @dbal.conn
|
||||
- @dbal.tools
|
||||
- %tables.migrations%
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- %core.table_prefix%
|
||||
- @migrator.tool_collection
|
||||
|
||||
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.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 }
|
|
@ -1,6 +1,7 @@
|
|||
imports:
|
||||
- { resource: tables.yml }
|
||||
- { resource: cron_tasks.yml }
|
||||
- { resource: migrator.yml }
|
||||
|
||||
services:
|
||||
auth:
|
||||
|
@ -162,45 +163,6 @@ services:
|
|||
tags:
|
||||
- { name: kernel.event_subscriber }
|
||||
|
||||
migrator:
|
||||
class: phpbb_db_migrator
|
||||
arguments:
|
||||
- @service_container
|
||||
|
||||
migrator.tools_collection
|
||||
class: phpbb_di_service_collection
|
||||
arguments:
|
||||
- @service_container
|
||||
|
||||
migrator.tools.config:
|
||||
class: phpbb_db_migration_tools_config
|
||||
arguments:
|
||||
- @config
|
||||
tags:
|
||||
- { name: migrator:tool }
|
||||
|
||||
migrator.tools.module:
|
||||
class: phpbb_db_migration_tools_module
|
||||
arguments:
|
||||
- @db
|
||||
- @cache
|
||||
- @user
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
tags:
|
||||
- { name: migrator:tool }
|
||||
|
||||
migrator.tools.permission:
|
||||
class: phpbb_db_migration_tools_permission
|
||||
arguments:
|
||||
- @db
|
||||
- @cache
|
||||
- @auth
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
tags:
|
||||
- { name: migrator:tool }
|
||||
|
||||
request:
|
||||
class: phpbb_request
|
||||
|
||||
|
|
|
@ -2,3 +2,4 @@ parameters:
|
|||
tables.config: %core.table_prefix%config
|
||||
tables.ext: %core.table_prefix%ext
|
||||
tables.migrations: %core.table_prefix%migrations
|
||||
tables.modules: %core.table_prefix%modules
|
||||
|
|
|
@ -1258,7 +1258,7 @@ function get_schema_struct()
|
|||
),
|
||||
);
|
||||
|
||||
$schema_data['phpbb_migrations'] = array(
|
||||
$schema_data['phpbb_moderator_cache'] = array(
|
||||
'COLUMNS' => array(
|
||||
'forum_id' => array('UINT', 0),
|
||||
'user_id' => array('UINT', 0),
|
||||
|
@ -1273,7 +1273,7 @@ function get_schema_struct()
|
|||
),
|
||||
);
|
||||
|
||||
$schema_data['phpbb_moderator_cache'] = array(
|
||||
$schema_data['phpbb_migrations'] = array(
|
||||
'COLUMNS' => array(
|
||||
'migration_name' => array('VCHAR', ''),
|
||||
'migration_schema_done' => array('BOOL', 0),
|
||||
|
|
|
@ -24,6 +24,7 @@ if (!defined('IN_PHPBB'))
|
|||
class phpbb_db_driver_mysqli extends phpbb_db_driver
|
||||
{
|
||||
var $multi_insert = true;
|
||||
|
||||
var $connect_error = '';
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,7 +80,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration
|
|||
{
|
||||
$delete_pms[] = (int) $row['msg_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (!empty($delete_pms))
|
||||
{
|
||||
|
|
|
@ -9,24 +9,115 @@
|
|||
|
||||
/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/
|
||||
|
||||
/*
|
||||
class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration
|
||||
{
|
||||
function depends_on()
|
||||
public function depends_on()
|
||||
{
|
||||
return array('phpbb_db_migration_data_3_0_11');
|
||||
}
|
||||
|
||||
function update_schema()
|
||||
public function update_schema()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
function update_data()
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array(&$this, 'update_module_auth'))),
|
||||
array('custom', array(array(&$this, 'update_bots'))),
|
||||
array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))),
|
||||
|
||||
array('config.update', array('version', '3.0.12-rc1')),
|
||||
);
|
||||
}
|
||||
|
||||
public function disable_bots_from_receiving_pms()
|
||||
{
|
||||
// Disable receiving pms for bots
|
||||
$sql = 'SELECT user_id
|
||||
FROM ' . BOTS_TABLE;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$bot_user_ids = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$bot_user_ids[] = (int) $row['user_id'];
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (!empty($bot_user_ids))
|
||||
{
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
SET user_allow_pm = 0
|
||||
WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids);
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function update_module_auth()
|
||||
{
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . '
|
||||
SET module_auth = \'acl_u_sig\'
|
||||
WHERE module_class = \'ucp\'
|
||||
AND module_basename = \'profile\'
|
||||
AND module_mode = \'signature\'';
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
public function update_bots()
|
||||
{
|
||||
// Update bots
|
||||
if (!function_exists('user_delete'))
|
||||
{
|
||||
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
|
||||
$bots_updates = array(
|
||||
// Bot Deletions
|
||||
'NG-Search [Bot]' => false,
|
||||
'Nutch/CVS [Bot]' => false,
|
||||
'OmniExplorer [Bot]' => false,
|
||||
'Seekport [Bot]' => false,
|
||||
'Synoo [Bot]' => false,
|
||||
'WiseNut [Bot]' => false,
|
||||
|
||||
// Bot Updates
|
||||
// Bot name to bot user agent map
|
||||
'Baidu [Spider]' => 'Baiduspider',
|
||||
'Exabot [Bot]' => 'Exabot',
|
||||
'Voyager [Bot]' => 'voyager/',
|
||||
'W3C [Validator]' => 'W3C_Validator',
|
||||
);
|
||||
|
||||
foreach ($bots_updates as $bot_name => $bot_agent)
|
||||
{
|
||||
$sql = 'SELECT user_id
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_type = ' . USER_IGNORE . "
|
||||
AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$bot_user_id = (int) $this->db->sql_fetchfield('user_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($bot_user_id)
|
||||
{
|
||||
if ($bot_agent === false)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . BOTS_TABLE . "
|
||||
WHERE user_id = $bot_user_id";
|
||||
$this->sql_query($sql);
|
||||
|
||||
user_delete('remove', $bot_user_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE ' . BOTS_TABLE . "
|
||||
SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "'
|
||||
WHERE user_id = $bot_user_id";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -36,12 +36,12 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration
|
|||
array('config.add', array('queue_trigger_posts', '3')),
|
||||
array('config.add', array('pm_max_recipients', '0')),
|
||||
array('custom', array(array(&$this, 'set_group_default_max_recipients'))),
|
||||
array('config.add', array('dbms_version', '')),
|
||||
array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL),
|
||||
array('config.add', array('dbms_version', $this->db->sql_server_info(true))),
|
||||
array('permission.add', array('u_masspm_group', true, 'u_masspm')),
|
||||
array('custom', array(array(&$this, 'correct_acp_email_permissions'))),
|
||||
|
||||
array('config.update', array('version', '3.0.3-rc1')),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
function correct_acp_email_permissions()
|
||||
|
|
|
@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration
|
|||
|
||||
function rename_log_delete_topic()
|
||||
{
|
||||
if ($db->sql_layer == 'oracle')
|
||||
if ($this->db->sql_layer == 'oracle')
|
||||
{
|
||||
// log_operation is CLOB - but we can change this later
|
||||
$sql = 'UPDATE ' . $this->table_prefix . "log
|
||||
|
|
|
@ -69,7 +69,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration
|
|||
// Update the Custom Profile Fields based on previous settings to the new format
|
||||
$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
|
||||
FROM ' . PROFILE_FIELDS_TABLE;
|
||||
$result = $this->sql_query($sql);
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
|
@ -101,5 +101,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration
|
|||
|
||||
$this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
|
||||
}
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration
|
|||
return array(
|
||||
array('config.add', array('captcha_gd_wave', 0)),
|
||||
array('config.add', array('captcha_gd_3d_noise', 1)),
|
||||
array('config.add', array('captcha_gd_refresh', 1)),
|
||||
array('config.add', array('captcha_gd_fonts', 1)),
|
||||
array('config.add', array('confirm_refresh', 1)),
|
||||
array('config.add', array('max_num_search_keywords', 10)),
|
||||
array('config.remove', array('search_indexing_state')),
|
||||
|
@ -47,7 +47,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration
|
|||
$sql = 'SELECT user_id, user_password
|
||||
FROM ' . $this->table_prefix . 'users
|
||||
WHERE user_pass_convert = 1';
|
||||
$result = $this->sql_query($sql);
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration
|
|||
$this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']);
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
function update_ichiro_bot()
|
||||
|
@ -99,7 +99,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration
|
|||
WHERE auth_option = '" . $db->sql_escape($option) . "'
|
||||
ORDER BY auth_option_id DESC";
|
||||
// sql_query_limit not possible here, due to bug in postgresql layer
|
||||
$result = $this->sql_query($sql);
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
// Skip first row, this is our original auth option we want to preserve
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
|
|
|
@ -35,7 +35,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
$this->table_prefix . 'reports' => array(
|
||||
'pm_id' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'fields' => array(
|
||||
$this->table_prefix . 'profile_fields' => array(
|
||||
'field_show_on_vt' => array('BOOL', 0),
|
||||
),
|
||||
$this->table_prefix . 'forums' => array(
|
||||
|
@ -89,19 +89,19 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
array('config.add', array('allow_avatar', 0)),
|
||||
array('if', array(
|
||||
($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']),
|
||||
array('config.add', array('allow_avatar', 1)),
|
||||
array('config.update', array('allow_avatar', 1)),
|
||||
)),
|
||||
array('config.add', array('allow_avatar_remote_upload', 0)),
|
||||
array('if', array(
|
||||
($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']),
|
||||
array('config.add', array('allow_avatar_remote_upload', 1)),
|
||||
array('config.update', array('allow_avatar_remote_upload', 1)),
|
||||
)),
|
||||
|
||||
array('module.add', array(
|
||||
'acp',
|
||||
'ACP_BOARD_CONFIGURATION',
|
||||
array(
|
||||
'module_basename' => 'board',
|
||||
'module_basename' => 'acp_board',
|
||||
'modes' => array('feed'),
|
||||
),
|
||||
)),
|
||||
|
@ -109,7 +109,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
'acp',
|
||||
'ACP_CAT_USERS',
|
||||
array(
|
||||
'module_basename' => 'users',
|
||||
'module_basename' => 'acp_users',
|
||||
'modes' => array('warnings'),
|
||||
),
|
||||
)),
|
||||
|
@ -117,7 +117,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
'acp',
|
||||
'ACP_SERVER_CONFIGURATION',
|
||||
array(
|
||||
'module_basename' => 'send_statistics',
|
||||
'module_basename' => 'acp_send_statistics',
|
||||
'modes' => array('send_statistics'),
|
||||
),
|
||||
)),
|
||||
|
@ -125,7 +125,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
'acp',
|
||||
'ACP_FORUM_BASED_PERMISSIONS',
|
||||
array(
|
||||
'module_basename' => 'permissions',
|
||||
'module_basename' => 'acp_permissions',
|
||||
'modes' => array('setting_forum_copy'),
|
||||
),
|
||||
)),
|
||||
|
@ -133,24 +133,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
'mcp',
|
||||
'MCP_REPORTS',
|
||||
array(
|
||||
'module_basename' => 'pm_reports',
|
||||
'modes' => array('pm_reports'),
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
'mcp',
|
||||
'MCP_REPORTS',
|
||||
array(
|
||||
'module_basename' => 'pm_reports',
|
||||
'modes' => array('pm_reports_closed'),
|
||||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
'mcp',
|
||||
'MCP_REPORTS',
|
||||
array(
|
||||
'module_basename' => 'pm_reports',
|
||||
'modes' => array('pm_report_details'),
|
||||
'module_basename' => 'mcp_pm_reports',
|
||||
'modes' => array('pm_reports','pm_reports_closed','pm_report_details'),
|
||||
),
|
||||
)),
|
||||
array('custom', array(array(&$this, 'add_newly_registered_group'))),
|
||||
|
@ -209,17 +193,14 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
$this->sql_query($sql);
|
||||
$u_role = $this->db->sql_nextid();
|
||||
|
||||
if (!$errored)
|
||||
{
|
||||
// Now add the correct data to the roles...
|
||||
// The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
|
||||
$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
|
||||
$this->sql_query($sql);
|
||||
// Now add the correct data to the roles...
|
||||
// The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
|
||||
$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
|
||||
$this->sql_query($sql);
|
||||
|
||||
// Add user role to group
|
||||
$sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
// Add user role to group
|
||||
$sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
// Insert new forum role
|
||||
|
@ -246,11 +227,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
$this->sql_query($sql);
|
||||
$f_role = $this->db->sql_nextid();
|
||||
|
||||
if (!$errored)
|
||||
{
|
||||
$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
// Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once)
|
||||
|
@ -294,7 +272,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration
|
|||
}
|
||||
|
||||
// Clear permissions...
|
||||
include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx);
|
||||
include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext);
|
||||
$auth_admin = new auth_admin();
|
||||
$auth_admin->acl_clear_prefetch();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration
|
|||
$this->sql_query($sql);
|
||||
}
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($i < $limit)
|
||||
{
|
||||
|
|
|
@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration
|
|||
'acp',
|
||||
'ACP_MESSAGES',
|
||||
array(
|
||||
'module_basename' => 'board',
|
||||
'module_basename' => 'acp_board',
|
||||
'modes' => array('post'),
|
||||
),
|
||||
)),
|
||||
|
@ -60,9 +60,9 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration
|
|||
// On an already updated board, they can also already be in language/.../acp/attachments.php
|
||||
// in the board root.
|
||||
$lang_files = array(
|
||||
"{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx",
|
||||
"{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx",
|
||||
"{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx",
|
||||
"{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}",
|
||||
"{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}",
|
||||
"{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}",
|
||||
);
|
||||
|
||||
foreach ($lang_files as $lang_file)
|
||||
|
@ -140,7 +140,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration
|
|||
|
||||
if (!function_exists('user_add'))
|
||||
{
|
||||
include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx);
|
||||
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
|
||||
$user_row = array(
|
||||
|
|
|
@ -44,7 +44,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration
|
|||
),
|
||||
),
|
||||
'change_columns' => array(
|
||||
$this->table_prefix . 'bbcode' => array(
|
||||
$this->table_prefix . 'bbcodes' => array(
|
||||
'bbcode_id' => array('USINT', 0),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class phpbb_db_migration_data_extensions extends phpbb_db_migration
|
||||
class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration
|
||||
{
|
||||
public function depends_on()
|
||||
{
|
||||
|
@ -78,6 +78,8 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration
|
|||
array('config.add', array('site_home_url', '')),
|
||||
array('config.add', array('site_home_text', '')),
|
||||
|
||||
array('permission.add', array('u_chgprofileinfo', true, 'u_sig')),
|
||||
|
||||
array('module.add', array(
|
||||
'acp',
|
||||
'ACP_GROUPS',
|
||||
|
@ -103,7 +105,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration
|
|||
),
|
||||
)),
|
||||
array('module.add', array(
|
||||
'acp',
|
||||
'ucp',
|
||||
'UCP_PROFILE',
|
||||
array(
|
||||
'module_basename' => 'ucp_profile',
|
||||
|
@ -113,20 +115,104 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration
|
|||
|
||||
array('module.remove', array(
|
||||
'acp',
|
||||
'ACP_CAT_STYLES',
|
||||
array(
|
||||
'module_basename' => 'styles',
|
||||
'modes' => array('imageset', 'theme', 'template'),
|
||||
),
|
||||
false,
|
||||
'ACP_TEMPLATES',
|
||||
)),
|
||||
array('module.remove', array(
|
||||
'acp',
|
||||
false,
|
||||
'ACP_THEMES',
|
||||
)),
|
||||
array('module.remove', array(
|
||||
'acp',
|
||||
false,
|
||||
'ACP_IMAGESETS',
|
||||
)),
|
||||
|
||||
array('custom', array(array($this, 'rename_module_basenames'))),
|
||||
array('custom', array(array($this, 'rename_styles_module'))),
|
||||
array('custom', array(array($this, 'add_group_teampage'))),
|
||||
array('custom', array(array($this, 'update_group_legend'))),
|
||||
array('custom', array(array($this, 'localise_global_announcements'))),
|
||||
array('custom', array(array($this, 'update_ucp_pm_basename'))),
|
||||
array('custom', array(array($this, 'update_ucp_profile_auth'))),
|
||||
array('custom', array(array($this, 'move_customise_modules'))),
|
||||
|
||||
array('config.update', array('version', '3.1.0-dev')),
|
||||
);
|
||||
}
|
||||
|
||||
public function move_customise_modules()
|
||||
{
|
||||
// Move language management to new location in the Customise tab
|
||||
// First get language module id
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
WHERE module_basename = 'acp_language'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$language_module_id = $this->db->sql_fetchfield('module_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
// Next get language management module id of the one just created
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
WHERE module_langname = 'ACP_LANGUAGE'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$language_management_module_id = $this->db->sql_fetchfield('module_id');
|
||||
$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
|
||||
if (!function_exists('adm_back_link'))
|
||||
{
|
||||
include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext);
|
||||
}
|
||||
$module_manager = new acp_modules();
|
||||
$module_manager->module_class = 'acp';
|
||||
$module_manager->move_module($language_module_id, $language_management_module_id);
|
||||
}
|
||||
|
||||
public function update_ucp_pm_basename()
|
||||
{
|
||||
$sql = 'SELECT module_id, module_basename
|
||||
FROM ' . MODULES_TABLE . "
|
||||
WHERE module_basename <> 'ucp_pm' AND
|
||||
module_langname='UCP_PM'";
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
|
||||
if ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
// This update is still not applied. Applying it
|
||||
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . "
|
||||
SET module_basename = 'ucp_pm'
|
||||
WHERE module_id = " . (int) $row['module_id'];
|
||||
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public function update_ucp_profile_auth()
|
||||
{
|
||||
// Update the auth setting for the module
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . "
|
||||
SET module_auth = 'acl_u_chgprofileinfo'
|
||||
WHERE module_class = 'ucp'
|
||||
AND module_basename = 'ucp_profile'
|
||||
AND module_mode = 'profile_info'";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
public function rename_styles_module()
|
||||
{
|
||||
// Rename styles module to Customise
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . "
|
||||
SET module_langname = 'ACP_CAT_CUSTOMISE'
|
||||
WHERE module_langname = 'ACP_CAT_STYLES'";
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
public function rename_module_basenames()
|
||||
{
|
||||
// rename all module basenames to full classname
|
||||
|
|
|
@ -39,10 +39,11 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration
|
|||
'acp',
|
||||
'ACP_GENERAL_TASKS',
|
||||
array(
|
||||
'module_basename' => 'extensions',
|
||||
'module_basename' => 'acp_extensions',
|
||||
'modes' => array('main'),
|
||||
),
|
||||
)),
|
||||
array('permission.add', array('a_extensions', true, 'a_styles')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration
|
|||
// Get list of valid 3.1 styles
|
||||
$available_styles = array('prosilver');
|
||||
|
||||
$iterator = new DirectoryIterator($phpbb_root_path . 'styles');
|
||||
$iterator = new DirectoryIterator($this->phpbb_root_path . 'styles');
|
||||
$skip_dirs = array('.', '..', 'prosilver');
|
||||
foreach ($iterator as $fileinfo)
|
||||
{
|
||||
|
@ -91,9 +91,67 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration
|
|||
'style_parent_id' => 0,
|
||||
'style_parent_tree' => '',
|
||||
);
|
||||
$this->sql_query('UPDATE ' . STYLES_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE style_id = ' . $style_row['style_id'], $errored, $error_ary);
|
||||
$this->sql_query('UPDATE ' . STYLES_TABLE . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
WHERE style_id = ' . $style_row['style_id']);
|
||||
$valid_styles[] = (int) $style_row['style_id'];
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old entries from styles table
|
||||
if (!sizeof($valid_styles))
|
||||
{
|
||||
// No valid styles: remove everything and add prosilver
|
||||
$this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
|
||||
|
||||
$sql_ary = array(
|
||||
'style_name' => 'prosilver',
|
||||
'style_copyright' => '© phpBB Group',
|
||||
'style_active' => 1,
|
||||
'style_path' => 'prosilver',
|
||||
'bbcode_bitfield' => 'kNg=',
|
||||
'style_parent_id' => 0,
|
||||
'style_parent_tree' => '',
|
||||
|
||||
// Will be removed in the next step
|
||||
'imageset_id' => 0,
|
||||
'template_id' => 0,
|
||||
'theme_id' => 0,
|
||||
);
|
||||
|
||||
$sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->sql_query($sql);
|
||||
|
||||
$sql = 'SELECT style_id
|
||||
FROM ' . $table . "
|
||||
WHERE style_name = 'prosilver'";
|
||||
$result = $this->sql_query($sql);
|
||||
$default_style = $this->db->sql_fetchfield($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
set_config('default_style', $default_style);
|
||||
|
||||
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0';
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
// There are valid styles in styles table. Remove styles that are outdated
|
||||
$this->sql_query('DELETE FROM ' . STYLES_TABLE . '
|
||||
WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true));
|
||||
|
||||
// Change default style
|
||||
if (!in_array($this->config['default_style'], $valid_styles))
|
||||
{
|
||||
$this->sql_query('UPDATE ' . CONFIG_TABLE . "
|
||||
SET config_value = '" . $valid_styles[0] . "'
|
||||
WHERE config_name = 'default_style'");
|
||||
}
|
||||
|
||||
// Reset styles for users
|
||||
$this->sql_query('UPDATE ' . USERS_TABLE . '
|
||||
SET user_style = 0
|
||||
WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,47 +37,6 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration
|
|||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array($this, 'styles_update'))),
|
||||
);
|
||||
}
|
||||
|
||||
public function styles_update()
|
||||
{
|
||||
// Remove old entries from styles table
|
||||
if (!sizeof($valid_styles))
|
||||
{
|
||||
// No valid styles: remove everything and add prosilver
|
||||
$this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
|
||||
|
||||
$sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')";
|
||||
$this->sql_query($sql);
|
||||
|
||||
$sql = 'SELECT style_id
|
||||
FROM ' . $table . "
|
||||
WHERE style_name = 'prosilver'";
|
||||
$result = $this->sql_query($sql);
|
||||
$default_style = $this->db->sql_fetchfield($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
set_config('default_style', $default_style);
|
||||
|
||||
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0';
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
// There are valid styles in styles table. Remove styles that are outdated
|
||||
$this->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true), $errored, $error_ary);
|
||||
|
||||
// Change default style
|
||||
if (!in_array($config['default_style'], $valid_styles))
|
||||
{
|
||||
set_config('default_style', $valid_styles[0]);
|
||||
}
|
||||
|
||||
// Reset styles for users
|
||||
$this->sql_query('UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true), $errored, $error_ary);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,10 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration
|
|||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Update board default timezone
|
||||
set_config('board_timezone', $this->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst']));
|
||||
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
||||
SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "'
|
||||
WHERE config_name = 'board_timezone'";
|
||||
$this->sql_query($sql);
|
||||
|
||||
// After we have calculated the timezones we can delete user_dst column from user table.
|
||||
$this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst');
|
||||
|
|
40
phpBB/includes/db/migration/exception.php
Normal file
40
phpBB/includes/db/migration/exception.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package db
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The migrator is responsible for applying new migrations in the correct order.
|
||||
*
|
||||
* @package db
|
||||
*/
|
||||
class phpbb_db_migration_exception extends \Exception
|
||||
{
|
||||
protected $parameters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$parameters = func_get_args();
|
||||
$message = array_shift($parameters);
|
||||
parent::__construct($message);
|
||||
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->message . ': ' . var_export($this->parameters, true);
|
||||
}
|
||||
}
|
|
@ -36,20 +36,20 @@ abstract class phpbb_db_migration
|
|||
|
||||
protected $errors;
|
||||
|
||||
private $queries = array();
|
||||
|
||||
/**
|
||||
* Migration constructor
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies
|
||||
*/
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container)
|
||||
public function __construct($config, phpbb_db_driver $db, $db_tools, $phpbb_root_path, $php_ext, $table_prefix)
|
||||
{
|
||||
$this->config = $this->container->get('config');
|
||||
$this->db = $this->container->get('dbal.conn');
|
||||
$this->db_tools = $this->container->get('dbal.tools');
|
||||
$this->table_prefix = $this->container->getParameters('core.table_prefix');
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->db_tools = $db_tools;
|
||||
$this->table_prefix = $table_prefix;
|
||||
|
||||
$this->phpbb_root_path = $this->container->getParameters('core.root_path');
|
||||
$this->php_ext = $this->container->getParameters('core.php_ext');
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->errors = array();
|
||||
}
|
||||
|
@ -88,10 +88,7 @@ abstract class phpbb_db_migration
|
|||
*/
|
||||
protected function sql_query($sql)
|
||||
{
|
||||
if (defined('DEBUG'))
|
||||
{
|
||||
echo "<br />\n{$sql}\n<br />";
|
||||
}
|
||||
$this->queries[] = $sql;
|
||||
|
||||
$this->db->sql_return_on_error(true);
|
||||
|
||||
|
@ -119,4 +116,14 @@ abstract class phpbb_db_migration
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of queries run
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_queries()
|
||||
{
|
||||
return $this->queries;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class phpbb_db_migration_tools_config
|
||||
class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interface
|
||||
{
|
||||
/** @var phpbb_config */
|
||||
protected $config = null;
|
||||
|
@ -17,6 +17,14 @@ class phpbb_db_migration_tools_config
|
|||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'config';
|
||||
}
|
||||
|
||||
/**
|
||||
* Config Add
|
||||
*
|
||||
|
@ -33,7 +41,7 @@ class phpbb_db_migration_tools_config
|
|||
throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name);
|
||||
}
|
||||
|
||||
$this->config->set($config_name, $config_value, $is_dynamic);
|
||||
$this->config->set($config_name, $config_value, !$is_dynamic);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -97,4 +105,4 @@ class phpbb_db_migration_tools_config
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
18
phpBB/includes/db/migration/tool/interface.php
Normal file
18
phpBB/includes/db/migration/tool/interface.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package migration
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
interface phpbb_db_migration_tool_interface
|
||||
{
|
||||
/**
|
||||
* Retrieve a short name used for commands in migrations.
|
||||
*
|
||||
* @return string short name
|
||||
*/
|
||||
public function get_name();
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class phpbb_db_migration_tools_module
|
||||
class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interface
|
||||
{
|
||||
/** @var phpbb_cache_service */
|
||||
protected $cache = null;
|
||||
|
@ -24,13 +24,25 @@ class phpbb_db_migration_tools_module
|
|||
/** @var string */
|
||||
protected $php_ext = null;
|
||||
|
||||
public function __construct(dbal $db, phpbb_cache_driver_interface $cache, $user, $phpbb_root_path, $php_ext)
|
||||
/** @var string */
|
||||
protected $modules_table = null;
|
||||
|
||||
public function __construct(phpbb_db_driver $db, $cache, $user, $phpbb_root_path, $php_ext, $modules_table)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->user = $user;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->modules_table = $modules_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'module';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +75,8 @@ class phpbb_db_migration_tools_module
|
|||
|
||||
if (!is_numeric($parent))
|
||||
{
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
|
||||
AND module_class = '$class'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -83,7 +96,8 @@ class phpbb_db_migration_tools_module
|
|||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_class = '$class'
|
||||
$parent_sql
|
||||
AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'");
|
||||
|
@ -149,15 +163,15 @@ class phpbb_db_migration_tools_module
|
|||
$basename = (isset($data['module_basename'])) ? $data['module_basename'] : '';
|
||||
$basename = str_replace(array('/', '\\'), '', $basename);
|
||||
$class = str_replace(array('/', '\\'), '', $class);
|
||||
$info_file = "$class/info/{$class}_$basename.{$this->php_ext}";
|
||||
$info_file = "$class/info/$basename.{$this->php_ext}";
|
||||
|
||||
// The manual and automatic ways both failed...
|
||||
if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file))
|
||||
{
|
||||
throw new phpbb_db_migration_exception('MODULE_ADD', $class, $info_file);
|
||||
throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $info_file);
|
||||
}
|
||||
|
||||
$classname = "{$class}_{$basename}_info";
|
||||
$classname = "{$basename}_info";
|
||||
|
||||
if (!class_exists($classname))
|
||||
{
|
||||
|
@ -198,7 +212,8 @@ class phpbb_db_migration_tools_module
|
|||
|
||||
if (!is_numeric($parent))
|
||||
{
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
|
||||
AND module_class = '$class'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -254,40 +269,46 @@ class phpbb_db_migration_tools_module
|
|||
// Move the module if requested above/below an existing one
|
||||
if (isset($data['before']) && $data['before'])
|
||||
{
|
||||
$sql = 'SELECT left_id FROM ' . MODULES_TABLE . '
|
||||
$sql = 'SELECT left_id
|
||||
FROM ' . $this->modules_table . '
|
||||
WHERE module_class = \'' . $class . '\'
|
||||
AND parent_id = ' . (int) $parent . '
|
||||
AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\'';
|
||||
$this->db->sql_query($sql);
|
||||
$to_left = $this->db->sql_fetchfield('left_id');
|
||||
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = left_id + 2, right_id = right_id + 2
|
||||
WHERE module_class = '$class'
|
||||
AND left_id >= $to_left
|
||||
AND left_id < {$module_data['left_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . "
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = $to_left, right_id = " . ($to_left + 1) . "
|
||||
WHERE module_class = '$class'
|
||||
AND module_id = {$module_data['module_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
else if (isset($data['after']) && $data['after'])
|
||||
{
|
||||
$sql = 'SELECT right_id FROM ' . MODULES_TABLE . '
|
||||
$sql = 'SELECT right_id
|
||||
FROM ' . $this->modules_table . '
|
||||
WHERE module_class = \'' . $class . '\'
|
||||
AND parent_id = ' . (int) $parent . '
|
||||
AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\'';
|
||||
$this->db->sql_query($sql);
|
||||
$to_right = $this->db->sql_fetchfield('right_id');
|
||||
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = left_id + 2, right_id = right_id + 2
|
||||
WHERE module_class = '$class'
|
||||
AND left_id >= $to_right
|
||||
AND left_id < {$module_data['left_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . "
|
||||
$sql = 'UPDATE ' . $this->modules_table . '
|
||||
SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . "
|
||||
WHERE module_class = '$class'
|
||||
AND module_id = {$module_data['module_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
|
@ -330,14 +351,14 @@ class phpbb_db_migration_tools_module
|
|||
// Automatic method
|
||||
$basename = str_replace(array('/', '\\'), '', $module['module_basename']);
|
||||
$class = str_replace(array('/', '\\'), '', $class);
|
||||
$info_file = "$class/info/{$class}_$basename.{$this->php_ext}";
|
||||
$info_file = "$class/info/$basename.{$this->php_ext}";
|
||||
|
||||
if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file))
|
||||
{
|
||||
throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file);
|
||||
}
|
||||
|
||||
$classname = "{$class}_{$basename}_info";
|
||||
$classname = "{$basename}_info";
|
||||
|
||||
if (!class_exists($classname))
|
||||
{
|
||||
|
@ -374,7 +395,8 @@ class phpbb_db_migration_tools_module
|
|||
|
||||
if (!is_numeric($parent))
|
||||
{
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
|
||||
AND module_class = '$class'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -394,7 +416,8 @@ class phpbb_db_migration_tools_module
|
|||
if (!is_numeric($module))
|
||||
{
|
||||
$module = $this->db->sql_escape($module);
|
||||
$sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_langname = '$module'
|
||||
AND module_class = '$class'
|
||||
$parent_sql";
|
||||
|
@ -410,7 +433,8 @@ class phpbb_db_migration_tools_module
|
|||
else
|
||||
{
|
||||
$module = (int) $module;
|
||||
$sql = 'SELECT module_langname FROM ' . MODULES_TABLE . "
|
||||
$sql = 'SELECT module_langname
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_id = $module
|
||||
AND module_class = '$class'
|
||||
$parent_sql";
|
||||
|
@ -439,9 +463,9 @@ class phpbb_db_migration_tools_module
|
|||
}
|
||||
}
|
||||
|
||||
$cache->destroy("_modules_$class");
|
||||
$this->cache->destroy("_modules_$class");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
||||
class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_interface
|
||||
{
|
||||
/** @var phpbb_auth */
|
||||
protected $auth = null;
|
||||
|
@ -24,7 +24,7 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
/** @var string */
|
||||
protected $php_ext = null;
|
||||
|
||||
public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext)
|
||||
public function __construct(phpbb_db_driver $db, $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
|
@ -33,6 +33,14 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'permission';
|
||||
}
|
||||
|
||||
/**
|
||||
* Permission Exists
|
||||
*
|
||||
|
@ -81,7 +89,7 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
*
|
||||
* @return result
|
||||
*/
|
||||
public function add($auth_option, $global = true)
|
||||
public function add($auth_option, $global = true, $copy_from = false)
|
||||
{
|
||||
if ($this->exists($auth_option, $global))
|
||||
{
|
||||
|
@ -105,8 +113,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
'is_local' => 1,
|
||||
);
|
||||
$sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'";
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
|
||||
WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
else
|
||||
|
@ -121,6 +129,38 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
}
|
||||
}
|
||||
|
||||
// The permission has been added, now we can copy it if needed
|
||||
if ($copy_from && isset($auth_admin->acl_options['id'][$copy_from]))
|
||||
{
|
||||
$old_id = $auth_admin->acl_options['id'][$copy_from];
|
||||
$new_id = $auth_admin->acl_options['id'][$auth_option];
|
||||
|
||||
$tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . $table . '
|
||||
WHERE auth_option_id = ' . $old_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$sql_ary = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$row['auth_option_id'] = $new_id;
|
||||
$sql_ary[] = $row;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (sizeof($sql_ary))
|
||||
{
|
||||
$this->db->sql_multi_insert($table, $sql_ary);
|
||||
}
|
||||
}
|
||||
|
||||
$auth_admin->acl_clear_prefetch();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -149,7 +189,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
{
|
||||
$type_sql = ' AND is_local = 1';
|
||||
}
|
||||
$sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . "
|
||||
$sql = 'SELECT auth_option_id, is_global, is_local
|
||||
FROM ' . ACL_OPTIONS_TABLE . "
|
||||
WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" .
|
||||
$type_sql;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -190,8 +231,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
*/
|
||||
public function role_add($role_name, $role_type = '', $role_description = '')
|
||||
{
|
||||
$sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\'';
|
||||
$sql = 'SELECT role_id
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_name = '" . $this->db->sql_escape($role_name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$role_id = $this->db->sql_fetchfield('role_id');
|
||||
|
||||
|
@ -200,8 +242,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name);
|
||||
}
|
||||
|
||||
$sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\'';
|
||||
$sql = 'SELECT MAX(role_order) AS max
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_type = '" . $this->db->sql_escape($role_type) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$role_order = $this->db->sql_fetchfield('max');
|
||||
$role_order = (!$role_order) ? 1 : $role_order + 1;
|
||||
|
@ -227,8 +270,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
*/
|
||||
public function role_update($old_role_name, $new_role_name = '')
|
||||
{
|
||||
$sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\'';
|
||||
$sql = 'SELECT role_id
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$role_id = $this->db->sql_fetchfield('role_id');
|
||||
|
||||
|
@ -237,9 +281,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name);
|
||||
}
|
||||
|
||||
$sql = 'UPDATE ' . ACL_ROLES_TABLE . '
|
||||
SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\'
|
||||
WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\'';
|
||||
$sql = 'UPDATE ' . ACL_ROLES_TABLE . "
|
||||
SET role_name = '" . $this->db->sql_escape($new_role_name) . "'
|
||||
WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
return false;
|
||||
|
@ -252,8 +296,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
*/
|
||||
public function role_remove($role_name)
|
||||
{
|
||||
$sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\'';
|
||||
$sql = 'SELECT role_id
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_name = '" . $this->db->sql_escape($role_name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$role_id = $this->db->sql_fetchfield('role_id');
|
||||
|
||||
|
@ -293,7 +338,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
}
|
||||
|
||||
$new_auth = array();
|
||||
$sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . '
|
||||
$sql = 'SELECT auth_option_id
|
||||
FROM ' . ACL_OPTIONS_TABLE . '
|
||||
WHERE ' . $this->db->sql_in_set('auth_option', $auth_option);
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
|
@ -314,8 +360,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
switch ($type)
|
||||
{
|
||||
case 'role' :
|
||||
$sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_name = \'' . $this->db->sql_escape($name) . '\'';
|
||||
$sql = 'SELECT role_id
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_name = '" . $this->db->sql_escape($name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$role_id = $this->db->sql_fetchfield('role_id');
|
||||
|
||||
|
@ -324,7 +371,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name);
|
||||
}
|
||||
|
||||
$sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . '
|
||||
$sql = 'SELECT auth_option_id, auth_setting
|
||||
FROM ' . ACL_ROLES_DATA_TABLE . '
|
||||
WHERE role_id = ' . $role_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
|
@ -335,7 +383,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
break;
|
||||
|
||||
case 'group' :
|
||||
$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\'';
|
||||
$sql = 'SELECT group_id
|
||||
FROM ' . GROUPS_TABLE . "
|
||||
WHERE group_name = '" . $this->db->sql_escape($name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$group_id = $this->db->sql_fetchfield('group_id');
|
||||
|
||||
|
@ -345,7 +395,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
}
|
||||
|
||||
// If the group has a role set for them we will add the requested permissions to that role.
|
||||
$sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . '
|
||||
$sql = 'SELECT auth_role_id
|
||||
FROM ' . ACL_GROUPS_TABLE . '
|
||||
WHERE group_id = ' . $group_id . '
|
||||
AND auth_role_id <> 0
|
||||
AND forum_id = 0';
|
||||
|
@ -353,7 +404,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
$role_id = $this->db->sql_fetchfield('auth_role_id');
|
||||
if ($role_id)
|
||||
{
|
||||
$sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . '
|
||||
$sql = 'SELECT role_name
|
||||
FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_id = ' . $role_id;
|
||||
$this->db->sql_query($sql);
|
||||
$role_name = $this->db->sql_fetchfield('role_name');
|
||||
|
@ -361,7 +413,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
return $this->set($role_name, $auth_option, 'role', $has_permission);
|
||||
}
|
||||
|
||||
$sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . '
|
||||
$sql = 'SELECT auth_option_id, auth_setting
|
||||
FROM ' . ACL_GROUPS_TABLE . '
|
||||
WHERE group_id = ' . $group_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
|
@ -430,7 +483,8 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
}
|
||||
|
||||
$to_remove = array();
|
||||
$sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . '
|
||||
$sql = 'SELECT auth_option_id
|
||||
FROM ' . ACL_OPTIONS_TABLE . '
|
||||
WHERE ' . $this->db->sql_in_set('auth_option', $auth_option);
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
|
@ -449,8 +503,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
switch ($type)
|
||||
{
|
||||
case 'role' :
|
||||
$sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_name = \'' . $this->db->sql_escape($name) . '\'';
|
||||
$sql = 'SELECT role_id
|
||||
FROM ' . ACL_ROLES_TABLE . "
|
||||
WHERE role_name = '" . $this->db->sql_escape($name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$role_id = $this->db->sql_fetchfield('role_id');
|
||||
|
||||
|
@ -465,8 +520,9 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
break;
|
||||
|
||||
case 'group' :
|
||||
$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . '
|
||||
WHERE group_name = \'' . $this->db->sql_escape($name) . '\'';
|
||||
$sql = 'SELECT group_id
|
||||
FROM ' . GROUPS_TABLE . "
|
||||
WHERE group_name = '" . $this->db->sql_escape($name) . "'";
|
||||
$this->db->sql_query($sql);
|
||||
$group_id = $this->db->sql_fetchfield('group_id');
|
||||
|
||||
|
@ -476,14 +532,16 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
}
|
||||
|
||||
// If the group has a role set for them we will remove the requested permissions from that role.
|
||||
$sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . '
|
||||
$sql = 'SELECT auth_role_id
|
||||
FROM ' . ACL_GROUPS_TABLE . '
|
||||
WHERE group_id = ' . $group_id . '
|
||||
AND auth_role_id <> 0';
|
||||
$this->db->sql_query($sql);
|
||||
$role_id = $this->db->sql_fetchfield('auth_role_id');
|
||||
if ($role_id)
|
||||
{
|
||||
$sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . '
|
||||
$sql = 'SELECT role_name
|
||||
FROM ' . ACL_ROLES_TABLE . '
|
||||
WHERE role_id = ' . $role_id;
|
||||
$this->db->sql_query($sql);
|
||||
$role_name = $this->db->sql_fetchfield('role_name');
|
||||
|
@ -501,4 +559,4 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -22,7 +22,7 @@ if (!defined('IN_PHPBB'))
|
|||
*/
|
||||
class phpbb_db_migrator
|
||||
{
|
||||
protected $container;
|
||||
protected $config;
|
||||
protected $db;
|
||||
protected $db_tools;
|
||||
protected $table_prefix;
|
||||
|
@ -33,31 +33,31 @@ class phpbb_db_migrator
|
|||
protected $migrations_table;
|
||||
protected $migration_state;
|
||||
|
||||
protected $migrations;
|
||||
protected $migrations = array();
|
||||
|
||||
/** @var string Name of the last migration run */
|
||||
public $last_run_migration = false;
|
||||
|
||||
/**
|
||||
* Constructor of the database migrator
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies
|
||||
*/
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations)
|
||||
public function __construct($config, phpbb_db_driver $db, $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->db = $this->container->get('dbal.conn');
|
||||
$this->db_tools = $this->container->get('dbal.tools');
|
||||
$this->table_prefix = $this->container->getParameters('core.table_prefix');
|
||||
$this->migrations_table = $this->container->getParameters('tables.migrations');
|
||||
$this->migrations = $migrations;
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->db_tools = $db_tools;
|
||||
|
||||
$this->phpbb_root_path = $this->container->getParameters('core.root_path');
|
||||
$this->php_ext = $this->container->getParameters('core.php_ext');
|
||||
$this->migrations_table = $migrations_table;
|
||||
|
||||
/** @todo replace with collection_pass when merged */
|
||||
$this->tools = array(
|
||||
'config' => new phpbb_db_migration_tools_config,
|
||||
'module' => new phpbb_db_migration_tools_module,
|
||||
'permission' => new phpbb_db_migration_tools_permission,
|
||||
);
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->table_prefix = $table_prefix;
|
||||
|
||||
foreach ($tools as $tool)
|
||||
{
|
||||
$this->tools[$tool->get_name()] = $tool;
|
||||
}
|
||||
|
||||
$this->load_migration_state();
|
||||
}
|
||||
|
@ -93,13 +93,44 @@ class phpbb_db_migrator
|
|||
$this->migrations = $class_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load migration data files from a directory
|
||||
*
|
||||
* @param string $path
|
||||
* @return array Array of migrations with names
|
||||
*/
|
||||
public function load_migrations($path)
|
||||
{
|
||||
$handle = opendir($path);
|
||||
while (($file = readdir($handle)) !== false)
|
||||
{
|
||||
if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1))
|
||||
{
|
||||
$name = 'phpbb_db_migration_data_' . substr($file, 0, -(strlen($this->php_ext) + 1));
|
||||
|
||||
if (!in_array($name, $this->migrations))
|
||||
{
|
||||
$this->migrations[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->migrations as $name)
|
||||
{
|
||||
if ($this->unfulfillable($name))
|
||||
{
|
||||
throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->migrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a single update step from the next migration to be applied.
|
||||
*
|
||||
* The update step can either be a schema or a (partial) data update. To
|
||||
* check if update() needs to be called again use the finished() method.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
|
@ -134,7 +165,8 @@ class phpbb_db_migrator
|
|||
return false;
|
||||
}
|
||||
|
||||
$migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext);
|
||||
$migration = $this->get_migration($name);
|
||||
|
||||
$state = (isset($this->migration_state[$name])) ?
|
||||
$this->migration_state[$name] :
|
||||
array(
|
||||
|
@ -157,6 +189,11 @@ class phpbb_db_migrator
|
|||
}
|
||||
}
|
||||
|
||||
$this->last_run_migration = array(
|
||||
'name' => $name,
|
||||
'class' => $migration,
|
||||
);
|
||||
|
||||
if (!isset($this->migration_state[$name]))
|
||||
{
|
||||
$state['migration_start_time'] = time();
|
||||
|
@ -187,20 +224,20 @@ class phpbb_db_migrator
|
|||
|
||||
protected function process_data_step($migration)
|
||||
{
|
||||
$continue = false;
|
||||
//$continue = false;
|
||||
$steps = $migration->update_data();
|
||||
|
||||
foreach ($steps as $step)
|
||||
{
|
||||
$continue = $this->run_step($step);
|
||||
|
||||
if (!$continue)
|
||||
/*if ($continue === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return $continue;
|
||||
//return $continue;
|
||||
}
|
||||
|
||||
protected function run_step($step)
|
||||
|
@ -211,13 +248,12 @@ class phpbb_db_migrator
|
|||
$callable = $callable_and_parameters[0];
|
||||
$parameters = $callable_and_parameters[1];
|
||||
|
||||
call_user_func_array($callable, $parameters);
|
||||
|
||||
return false;
|
||||
return call_user_func_array($callable, $parameters);
|
||||
}
|
||||
catch (phpbb_db_migration_exception $e)
|
||||
{
|
||||
echo $e;die();
|
||||
echo $e;
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,7 +361,7 @@ class phpbb_db_migrator
|
|||
return true;
|
||||
}
|
||||
|
||||
$migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext);
|
||||
$migration = $this->get_migration($name);
|
||||
$depends = $migration->depends_on();
|
||||
|
||||
foreach ($depends as $depend)
|
||||
|
@ -374,4 +410,15 @@ class phpbb_db_migrator
|
|||
{
|
||||
$this->db_tools->perform_schema_changes($schema_changes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get a migration
|
||||
*
|
||||
* @param string $name Name of the migration
|
||||
* @return phpbb_db_migration
|
||||
*/
|
||||
protected function get_migration($name)
|
||||
{
|
||||
return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2868,6 +2868,7 @@ function send_status_line($code, $message)
|
|||
else
|
||||
{
|
||||
$version = phpbb_request_http_version();
|
||||
|
||||
header("$version $code $message", true, $code);
|
||||
}
|
||||
}
|
||||
|
@ -5582,7 +5583,7 @@ function phpbb_convert_30_dbms_to_31($dbms)
|
|||
|
||||
/*
|
||||
$reflection = new \ReflectionClass($dbms);
|
||||
|
||||
|
||||
if ($reflection->isSubclassOf('phpbb_db_driver'))
|
||||
{
|
||||
return $dbms;
|
||||
|
|
|
@ -1521,8 +1521,6 @@ function change_database_data(&$no_updates, $version)
|
|||
),
|
||||
);
|
||||
|
||||
global $db_tools;
|
||||
|
||||
$statements = $db_tools->perform_schema_changes($changes);
|
||||
|
||||
foreach ($statements as $sql)
|
||||
|
@ -2164,26 +2162,41 @@ function change_database_data(&$no_updates, $version)
|
|||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
global $db_tools, $table_prefix;
|
||||
|
||||
// Recover from potentially broken Q&A CAPTCHA table on firebird
|
||||
// Q&A CAPTCHA was uninstallable, so it's safe to remove these
|
||||
// without data loss
|
||||
/*
|
||||
* Due to a bug, vanilla phpbb could not create captcha tables
|
||||
* in 3.0.8 on firebird. It was possible for board administrators
|
||||
* to adjust the code to work. If code was manually adjusted by
|
||||
* board administrators, index names would not be the same as
|
||||
* what 3.0.9 and newer expect. This code fragment drops captcha
|
||||
* tables, destroying all entered Q&A captcha configuration, such
|
||||
* that when Q&A is configured next the respective tables will be
|
||||
* created with correct index names.
|
||||
*
|
||||
* If you wish to preserve your Q&A captcha configuration, you can
|
||||
* manually rename indexes to the currently expected name:
|
||||
* phpbb_captcha_questions_lang_iso => phpbb_captcha_questions_lang
|
||||
* phpbb_captcha_answers_question_id => phpbb_captcha_answers_qid
|
||||
*
|
||||
* Again, this needs to be done only if a board was manually modified
|
||||
* to fix broken captcha code.
|
||||
*
|
||||
if ($db_tools->sql_layer == 'firebird')
|
||||
{
|
||||
$tables = array(
|
||||
$table_prefix . 'captcha_questions',
|
||||
$table_prefix . 'captcha_answers',
|
||||
$table_prefix . 'qa_confirm',
|
||||
$changes = array(
|
||||
'drop_tables' => array(
|
||||
$table_prefix . 'captcha_questions',
|
||||
$table_prefix . 'captcha_answers',
|
||||
$table_prefix . 'qa_confirm',
|
||||
),
|
||||
);
|
||||
foreach ($tables as $table)
|
||||
$statements = $db_tools->perform_schema_changes($changes);
|
||||
|
||||
foreach ($statements as $sql)
|
||||
{
|
||||
if ($db_tools->sql_table_exists($table))
|
||||
{
|
||||
$db_tools->sql_table_drop($table);
|
||||
}
|
||||
_sql($sql, $errored, $error_ary);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$no_updates = false;
|
||||
break;
|
||||
|
@ -2360,6 +2373,26 @@ function change_database_data(&$no_updates, $version)
|
|||
}
|
||||
}
|
||||
|
||||
// Disable receiving pms for bots
|
||||
$sql = 'SELECT user_id
|
||||
FROM ' . BOTS_TABLE;
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$bot_user_ids = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$bot_user_ids[] = (int) $row['user_id'];
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!empty($bot_user_ids))
|
||||
{
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
SET user_allow_pm = 0
|
||||
WHERE ' . $db->sql_in_set('user_id', $bot_user_ids);
|
||||
_sql($sql, $errored, $error_ary);
|
||||
}
|
||||
|
||||
$no_updates = false;
|
||||
break;
|
||||
|
||||
|
|
|
@ -573,18 +573,6 @@ CREATE INDEX phpbb_login_attempts_att_for ON phpbb_login_attempts(attempt_forwar
|
|||
CREATE INDEX phpbb_login_attempts_att_time ON phpbb_login_attempts(attempt_time);;
|
||||
CREATE INDEX phpbb_login_attempts_user_id ON phpbb_login_attempts(user_id);;
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||
migration_schema_done INTEGER DEFAULT 0 NOT NULL,
|
||||
migration_data_done INTEGER DEFAULT 0 NOT NULL,
|
||||
migration_data_state BLOB SUB_TYPE TEXT CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||
migration_start_time INTEGER DEFAULT 0 NOT NULL,
|
||||
migration_end_time INTEGER DEFAULT 0 NOT NULL
|
||||
);;
|
||||
|
||||
CREATE UNIQUE INDEX phpbb_migrations_migration_name ON phpbb_migrations(migration_name);;
|
||||
|
||||
# Table: 'phpbb_moderator_cache'
|
||||
CREATE TABLE phpbb_moderator_cache (
|
||||
forum_id INTEGER DEFAULT 0 NOT NULL,
|
||||
|
@ -598,6 +586,19 @@ CREATE TABLE phpbb_moderator_cache (
|
|||
CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache(display_on_index);;
|
||||
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache(forum_id);;
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||
migration_schema_done INTEGER DEFAULT 0 NOT NULL,
|
||||
migration_data_done INTEGER DEFAULT 0 NOT NULL,
|
||||
migration_data_state BLOB SUB_TYPE TEXT CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||
migration_start_time INTEGER DEFAULT 0 NOT NULL,
|
||||
migration_end_time INTEGER DEFAULT 0 NOT NULL
|
||||
);;
|
||||
|
||||
ALTER TABLE phpbb_migrations ADD PRIMARY KEY (migration_name);;
|
||||
|
||||
|
||||
# Table: 'phpbb_modules'
|
||||
CREATE TABLE phpbb_modules (
|
||||
module_id INTEGER NOT NULL,
|
||||
|
@ -924,8 +925,8 @@ CREATE TABLE phpbb_reports (
|
|||
report_time INTEGER DEFAULT 0 NOT NULL,
|
||||
report_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL,
|
||||
reported_post_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL,
|
||||
reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||
reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL
|
||||
reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||
reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL
|
||||
);;
|
||||
|
||||
ALTER TABLE phpbb_reports ADD PRIMARY KEY (report_id);;
|
||||
|
|
|
@ -696,23 +696,6 @@ CREATE INDEX [user_id] ON [phpbb_login_attempts]([user_id]) ON [PRIMARY]
|
|||
GO
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_migrations'
|
||||
*/
|
||||
CREATE TABLE [phpbb_migrations] (
|
||||
[migration_name] [varchar] (255) DEFAULT ('') NOT NULL ,
|
||||
[migration_schema_done] [int] DEFAULT (0) NOT NULL ,
|
||||
[migration_data_done] [int] DEFAULT (0) NOT NULL ,
|
||||
[migration_data_state] [varchar] (8000) DEFAULT ('') NOT NULL ,
|
||||
[migration_start_time] [int] DEFAULT (0) NOT NULL ,
|
||||
[migration_end_time] [int] DEFAULT (0) NOT NULL
|
||||
) ON [PRIMARY]
|
||||
GO
|
||||
|
||||
CREATE UNIQUE INDEX [migration_name] ON [phpbb_migrations]([migration_name]) ON [PRIMARY]
|
||||
GO
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_moderator_cache'
|
||||
*/
|
||||
|
@ -733,6 +716,27 @@ CREATE INDEX [forum_id] ON [phpbb_moderator_cache]([forum_id]) ON [PRIMARY]
|
|||
GO
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_migrations'
|
||||
*/
|
||||
CREATE TABLE [phpbb_migrations] (
|
||||
[migration_name] [varchar] (255) DEFAULT ('') NOT NULL ,
|
||||
[migration_schema_done] [int] DEFAULT (0) NOT NULL ,
|
||||
[migration_data_done] [int] DEFAULT (0) NOT NULL ,
|
||||
[migration_data_state] [varchar] (8000) DEFAULT ('') NOT NULL ,
|
||||
[migration_start_time] [int] DEFAULT (0) NOT NULL ,
|
||||
[migration_end_time] [int] DEFAULT (0) NOT NULL
|
||||
) ON [PRIMARY]
|
||||
GO
|
||||
|
||||
ALTER TABLE [phpbb_migrations] WITH NOCHECK ADD
|
||||
CONSTRAINT [PK_phpbb_migrations] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[migration_name]
|
||||
) ON [PRIMARY]
|
||||
GO
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_modules'
|
||||
*/
|
||||
|
@ -1128,8 +1132,8 @@ CREATE TABLE [phpbb_reports] (
|
|||
[report_time] [int] DEFAULT (0) NOT NULL ,
|
||||
[report_text] [text] DEFAULT ('') NOT NULL ,
|
||||
[reported_post_text] [text] DEFAULT ('') NOT NULL ,
|
||||
[reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL ,
|
||||
[reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL
|
||||
[reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL ,
|
||||
[reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL
|
||||
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
|
||||
GO
|
||||
|
||||
|
|
|
@ -397,18 +397,6 @@ CREATE TABLE phpbb_login_attempts (
|
|||
);
|
||||
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varbinary(255) DEFAULT '' NOT NULL,
|
||||
migration_schema_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_state blob NOT NULL,
|
||||
migration_start_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_end_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
UNIQUE migration_name (migration_name)
|
||||
);
|
||||
|
||||
|
||||
# Table: 'phpbb_moderator_cache'
|
||||
CREATE TABLE phpbb_moderator_cache (
|
||||
forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
|
@ -422,6 +410,18 @@ CREATE TABLE phpbb_moderator_cache (
|
|||
);
|
||||
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varbinary(255) DEFAULT '' NOT NULL,
|
||||
migration_schema_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_state blob NOT NULL,
|
||||
migration_start_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_end_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (migration_name)
|
||||
);
|
||||
|
||||
|
||||
# Table: 'phpbb_modules'
|
||||
CREATE TABLE phpbb_modules (
|
||||
module_id mediumint(8) UNSIGNED NOT NULL auto_increment,
|
||||
|
@ -661,8 +661,8 @@ CREATE TABLE phpbb_reports (
|
|||
report_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
report_text mediumblob NOT NULL,
|
||||
reported_post_text mediumblob NOT NULL,
|
||||
reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL,
|
||||
reported_post_uid varbinary(8) DEFAULT '' NOT NULL,
|
||||
reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL,
|
||||
PRIMARY KEY (report_id),
|
||||
KEY post_id (post_id),
|
||||
KEY pm_id (pm_id)
|
||||
|
|
|
@ -397,18 +397,6 @@ CREATE TABLE phpbb_login_attempts (
|
|||
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
||||
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar(255) DEFAULT '' NOT NULL,
|
||||
migration_schema_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_state text NOT NULL,
|
||||
migration_start_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_end_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
UNIQUE migration_name (migration_name)
|
||||
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
||||
|
||||
|
||||
# Table: 'phpbb_moderator_cache'
|
||||
CREATE TABLE phpbb_moderator_cache (
|
||||
forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
|
@ -422,6 +410,18 @@ CREATE TABLE phpbb_moderator_cache (
|
|||
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
||||
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar(255) DEFAULT '' NOT NULL,
|
||||
migration_schema_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_data_state text NOT NULL,
|
||||
migration_start_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
migration_end_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
PRIMARY KEY (migration_name)
|
||||
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
||||
|
||||
|
||||
# Table: 'phpbb_modules'
|
||||
CREATE TABLE phpbb_modules (
|
||||
module_id mediumint(8) UNSIGNED NOT NULL auto_increment,
|
||||
|
@ -661,8 +661,8 @@ CREATE TABLE phpbb_reports (
|
|||
report_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
report_text mediumtext NOT NULL,
|
||||
reported_post_text mediumtext NOT NULL,
|
||||
reported_post_bitfield varchar(255) DEFAULT '' NOT NULL,
|
||||
reported_post_uid varchar(8) DEFAULT '' NOT NULL,
|
||||
reported_post_bitfield varchar(255) DEFAULT '' NOT NULL,
|
||||
PRIMARY KEY (report_id),
|
||||
KEY post_id (post_id),
|
||||
KEY pm_id (pm_id)
|
||||
|
|
|
@ -780,21 +780,6 @@ CREATE INDEX phpbb_login_attempts_att_time ON phpbb_login_attempts (attempt_time
|
|||
CREATE INDEX phpbb_login_attempts_user_id ON phpbb_login_attempts (user_id)
|
||||
/
|
||||
|
||||
/*
|
||||
Table: 'phpbb_migrations'
|
||||
*/
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar2(255) DEFAULT '' ,
|
||||
migration_schema_done number(1) DEFAULT '0' NOT NULL,
|
||||
migration_data_done number(1) DEFAULT '0' NOT NULL,
|
||||
migration_data_state clob DEFAULT '' ,
|
||||
migration_start_time number(11) DEFAULT '0' NOT NULL,
|
||||
migration_end_time number(11) DEFAULT '0' NOT NULL,
|
||||
CONSTRAINT u_phpbb_migration_name UNIQUE (migration_name)
|
||||
)
|
||||
/
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_moderator_cache'
|
||||
*/
|
||||
|
@ -813,6 +798,21 @@ CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache (display_on
|
|||
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache (forum_id)
|
||||
/
|
||||
|
||||
/*
|
||||
Table: 'phpbb_migrations'
|
||||
*/
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar2(255) DEFAULT '' ,
|
||||
migration_schema_done number(1) DEFAULT '0' NOT NULL,
|
||||
migration_data_done number(1) DEFAULT '0' NOT NULL,
|
||||
migration_data_state clob DEFAULT '' ,
|
||||
migration_start_time number(11) DEFAULT '0' NOT NULL,
|
||||
migration_end_time number(11) DEFAULT '0' NOT NULL,
|
||||
CONSTRAINT pk_phpbb_migrations PRIMARY KEY (migration_name)
|
||||
)
|
||||
/
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_modules'
|
||||
*/
|
||||
|
@ -1231,8 +1231,8 @@ CREATE TABLE phpbb_reports (
|
|||
report_time number(11) DEFAULT '0' NOT NULL,
|
||||
report_text clob DEFAULT '' ,
|
||||
reported_post_text clob DEFAULT '' ,
|
||||
reported_post_bitfield varchar2(255) DEFAULT '' ,
|
||||
reported_post_uid varchar2(8) DEFAULT '' ,
|
||||
reported_post_bitfield varchar2(255) DEFAULT '' ,
|
||||
CONSTRAINT pk_phpbb_reports PRIMARY KEY (report_id)
|
||||
)
|
||||
/
|
||||
|
|
|
@ -557,20 +557,6 @@ CREATE INDEX phpbb_login_attempts_att_for ON phpbb_login_attempts (attempt_forwa
|
|||
CREATE INDEX phpbb_login_attempts_att_time ON phpbb_login_attempts (attempt_time);
|
||||
CREATE INDEX phpbb_login_attempts_user_id ON phpbb_login_attempts (user_id);
|
||||
|
||||
/*
|
||||
Table: 'phpbb_migrations'
|
||||
*/
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar(255) DEFAULT '' NOT NULL,
|
||||
migration_schema_done INT2 DEFAULT '0' NOT NULL CHECK (migration_schema_done >= 0),
|
||||
migration_data_done INT2 DEFAULT '0' NOT NULL CHECK (migration_data_done >= 0),
|
||||
migration_data_state varchar(8000) DEFAULT '' NOT NULL,
|
||||
migration_start_time INT4 DEFAULT '0' NOT NULL CHECK (migration_start_time >= 0),
|
||||
migration_end_time INT4 DEFAULT '0' NOT NULL CHECK (migration_end_time >= 0)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX phpbb_migrations_migration_name ON phpbb_migrations (migration_name);
|
||||
|
||||
/*
|
||||
Table: 'phpbb_moderator_cache'
|
||||
*/
|
||||
|
@ -586,6 +572,20 @@ CREATE TABLE phpbb_moderator_cache (
|
|||
CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache (display_on_index);
|
||||
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache (forum_id);
|
||||
|
||||
/*
|
||||
Table: 'phpbb_migrations'
|
||||
*/
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar(255) DEFAULT '' NOT NULL,
|
||||
migration_schema_done INT2 DEFAULT '0' NOT NULL CHECK (migration_schema_done >= 0),
|
||||
migration_data_done INT2 DEFAULT '0' NOT NULL CHECK (migration_data_done >= 0),
|
||||
migration_data_state varchar(8000) DEFAULT '' NOT NULL,
|
||||
migration_start_time INT4 DEFAULT '0' NOT NULL CHECK (migration_start_time >= 0),
|
||||
migration_end_time INT4 DEFAULT '0' NOT NULL CHECK (migration_end_time >= 0),
|
||||
PRIMARY KEY (migration_name)
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
Table: 'phpbb_modules'
|
||||
*/
|
||||
|
@ -869,8 +869,8 @@ CREATE TABLE phpbb_reports (
|
|||
report_time INT4 DEFAULT '0' NOT NULL CHECK (report_time >= 0),
|
||||
report_text TEXT DEFAULT '' NOT NULL,
|
||||
reported_post_text TEXT DEFAULT '' NOT NULL,
|
||||
reported_post_bitfield varchar(255) DEFAULT '' NOT NULL,
|
||||
reported_post_uid varchar(8) DEFAULT '' NOT NULL,
|
||||
reported_post_bitfield varchar(255) DEFAULT '' NOT NULL,
|
||||
PRIMARY KEY (report_id)
|
||||
);
|
||||
|
||||
|
|
|
@ -385,18 +385,6 @@ CREATE INDEX phpbb_login_attempts_att_for ON phpbb_login_attempts (attempt_forwa
|
|||
CREATE INDEX phpbb_login_attempts_att_time ON phpbb_login_attempts (attempt_time);
|
||||
CREATE INDEX phpbb_login_attempts_user_id ON phpbb_login_attempts (user_id);
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar(255) NOT NULL DEFAULT '',
|
||||
migration_schema_done INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
migration_data_done INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
migration_data_state text(65535) NOT NULL DEFAULT '',
|
||||
migration_start_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
migration_end_time INTEGER UNSIGNED NOT NULL DEFAULT '0'
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX phpbb_migrations_migration_name ON phpbb_migrations (migration_name);
|
||||
|
||||
# Table: 'phpbb_moderator_cache'
|
||||
CREATE TABLE phpbb_moderator_cache (
|
||||
forum_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
|
@ -410,6 +398,18 @@ CREATE TABLE phpbb_moderator_cache (
|
|||
CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache (display_on_index);
|
||||
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache (forum_id);
|
||||
|
||||
# Table: 'phpbb_migrations'
|
||||
CREATE TABLE phpbb_migrations (
|
||||
migration_name varchar(255) NOT NULL DEFAULT '',
|
||||
migration_schema_done INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
migration_data_done INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
migration_data_state text(65535) NOT NULL DEFAULT '',
|
||||
migration_start_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
migration_end_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (migration_name)
|
||||
);
|
||||
|
||||
|
||||
# Table: 'phpbb_modules'
|
||||
CREATE TABLE phpbb_modules (
|
||||
module_id INTEGER PRIMARY KEY NOT NULL ,
|
||||
|
@ -642,8 +642,8 @@ CREATE TABLE phpbb_reports (
|
|||
report_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||
report_text mediumtext(16777215) NOT NULL DEFAULT '',
|
||||
reported_post_text mediumtext(16777215) NOT NULL DEFAULT '',
|
||||
reported_post_bitfield varchar(255) NOT NULL DEFAULT '',
|
||||
reported_post_uid varchar(8) NOT NULL DEFAULT ''
|
||||
reported_post_uid varchar(8) NOT NULL DEFAULT '',
|
||||
reported_post_bitfield varchar(255) NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE INDEX phpbb_reports_post_id ON phpbb_reports (post_id);
|
||||
|
|
121
phpBB/test.php
Normal file
121
phpBB/test.php
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('IN_PHPBB', true);
|
||||
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
||||
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
||||
|
||||
require($phpbb_root_path . 'includes/startup.' . $phpEx);
|
||||
|
||||
if (file_exists($phpbb_root_path . 'config.' . $phpEx))
|
||||
{
|
||||
require($phpbb_root_path . 'config.' . $phpEx);
|
||||
}
|
||||
|
||||
// Include files
|
||||
require($phpbb_root_path . 'includes/class_loader.' . $phpEx);
|
||||
|
||||
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/functions_container.' . $phpEx);
|
||||
|
||||
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
||||
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
|
||||
|
||||
// Set PHP error handler to ours
|
||||
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
|
||||
|
||||
// Setup class loader first
|
||||
$phpbb_class_loader = new phpbb_class_loader('phpbb_', "{$phpbb_root_path}includes/", ".$phpEx");
|
||||
$phpbb_class_loader->register();
|
||||
|
||||
/*$phpbb_container = phpbb_create_container(
|
||||
array(
|
||||
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
|
||||
new phpbb_di_extension_core($phpbb_root_path),
|
||||
),
|
||||
array(
|
||||
new phpbb_di_pass_collection_pass(),
|
||||
new phpbb_di_pass_kernel_pass(),
|
||||
),
|
||||
$phpbb_root_path, $phpEx);
|
||||
$phpbb_container->compile();*/
|
||||
|
||||
// Set up container
|
||||
$container_extensions = array(
|
||||
new phpbb_di_extension_config($phpbb_root_path . 'config.' . $phpEx),
|
||||
new phpbb_di_extension_core($phpbb_root_path),
|
||||
);
|
||||
$container_passes = array(
|
||||
new phpbb_di_pass_collection_pass(),
|
||||
//new phpbb_di_pass_kernel_pass(),
|
||||
);
|
||||
$phpbb_container = phpbb_create_container($container_extensions, $phpbb_root_path, $phpEx);
|
||||
|
||||
// Compile the container
|
||||
foreach ($container_passes as $pass)
|
||||
{
|
||||
$phpbb_container->addCompilerPass($pass);
|
||||
}
|
||||
$phpbb_container->compile();
|
||||
|
||||
// set up caching
|
||||
$cache = $phpbb_container->get('cache');
|
||||
|
||||
// Instantiate some basic classes
|
||||
$phpbb_dispatcher = $phpbb_container->get('dispatcher');
|
||||
$request = $phpbb_container->get('request');
|
||||
$user = $phpbb_container->get('user');
|
||||
$auth = $phpbb_container->get('auth');
|
||||
$db = $phpbb_container->get('dbal.conn');
|
||||
|
||||
// make sure request_var uses this request instance
|
||||
request_var('', 0, false, false, $request); // "dependency injection" for a function
|
||||
|
||||
// Grab global variables, re-cache if necessary
|
||||
$config = $phpbb_container->get('config');
|
||||
set_config(null, null, null, $config);
|
||||
set_config_count(null, null, null, $config);
|
||||
|
||||
// End startup code
|
||||
|
||||
$db_tools = $phpbb_container->get('dbal.tools');
|
||||
if (!$db_tools->sql_table_exists(MIGRATIONS_TABLE))
|
||||
{
|
||||
$db_tools->sql_create_table(MIGRATIONS_TABLE, array(
|
||||
'COLUMNS' => array(
|
||||
'migration_name' => array('VCHAR', ''),
|
||||
'migration_schema_done' => array('BOOL', 0),
|
||||
'migration_data_done' => array('BOOL', 0),
|
||||
'migration_data_state' => array('TEXT', ''),
|
||||
'migration_start_time' => array('TIMESTAMP', 0),
|
||||
'migration_end_time' => array('TIMESTAMP', 0),
|
||||
),
|
||||
'PRIMARY_KEY' => 'migration_name',
|
||||
));
|
||||
}
|
||||
|
||||
$migrator = $phpbb_container->get('migrator');
|
||||
$migrator->load_migrations($phpbb_root_path . 'includes/db/migration/data/');
|
||||
|
||||
while (!$migrator->finished())
|
||||
{
|
||||
$migrator->update();
|
||||
|
||||
echo $migrator->last_run_migration['name'] . '<br />';
|
||||
}
|
||||
|
||||
echo 'Finished';
|
42
tests/dbal/fixtures/migrator_module.xml
Normal file
42
tests/dbal/fixtures/migrator_module.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_modules">
|
||||
<column>module_id</column>
|
||||
<column>module_enabled</column>
|
||||
<column>module_display</column>
|
||||
<column>module_basename</column>
|
||||
<column>module_class</column>
|
||||
<column>parent_id</column>
|
||||
<column>left_id</column>
|
||||
<column>right_id</column>
|
||||
<column>module_langname</column>
|
||||
<column>module_mode</column>
|
||||
<column>module_auth</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>acp</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>4</value>
|
||||
<value>ACP_CAT</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>acp_test</value>
|
||||
<value>acp</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
<value>ACP_MODULE</value>
|
||||
<value>test</value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
31
tests/dbal/fixtures/migrator_permission.xml
Normal file
31
tests/dbal/fixtures/migrator_permission.xml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_acl_options">
|
||||
<column>auth_option_id</column>
|
||||
<column>auth_option</column>
|
||||
<column>is_global</column>
|
||||
<column>is_local</column>
|
||||
<column>founder_only</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>global</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>local</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>both</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/migration/dummy.php';
|
||||
|
@ -28,11 +28,17 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setup();
|
||||
parent::setUp();
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->db_tools = new phpbb_db_tools($this->db);
|
||||
$this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, 'phpbb_', MIGRATIONS_TABLE, 'phpBB/', '.php');
|
||||
|
||||
$this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config');
|
||||
|
||||
$tools = array(
|
||||
new phpbb_db_migration_tool_config($this->config),
|
||||
);
|
||||
$this->migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
|
|
97
tests/dbal/migrator_tool_config_test.php
Normal file
97
tests/dbal/migrator_tool_config_test.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
|
||||
|
||||
class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case
|
||||
{
|
||||
public function setup()
|
||||
{
|
||||
$this->config = new phpbb_config(array());
|
||||
|
||||
$this->tool = new phpbb_db_migration_tool_config($this->config);
|
||||
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
public function test_add()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('foo', 'bar');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar', $this->config['foo']);
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->add('foo', 'bar');
|
||||
$this->fail('Exception not thrown');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
public function test_update()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
try
|
||||
{
|
||||
$this->tool->update('foo', 'bar2');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar2', $this->config['foo']);
|
||||
}
|
||||
|
||||
public function test_update_if_equals()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->update_if_equals('', 'foo', 'bar2');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar', $this->config['foo']);
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->update_if_equals('bar', 'foo', 'bar2');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar2', $this->config['foo']);
|
||||
}
|
||||
|
||||
public function test_remove()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->remove('foo');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertFalse(isset($this->config['foo']));
|
||||
}
|
||||
}
|
128
tests/dbal/migrator_tool_module.php
Normal file
128
tests/dbal/migrator_tool_module.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
|
||||
|
||||
class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml');
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
// Need global $db, $user for delete_module function in acp_modules
|
||||
global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user;
|
||||
|
||||
parent::setup();
|
||||
|
||||
// Force add_log function to not be used
|
||||
$skip_add_log = true;
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
$this->cache = new phpbb_cache_service(new phpbb_cache_driver_null());
|
||||
$user = $this->user = new phpbb_user();
|
||||
|
||||
$this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx);
|
||||
}
|
||||
|
||||
public function exists_data()
|
||||
{
|
||||
return array(
|
||||
// Test the category
|
||||
array(
|
||||
'',
|
||||
'ACP_CAT',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
0,
|
||||
'ACP_CAT',
|
||||
true,
|
||||
),
|
||||
|
||||
// Test the module
|
||||
array(
|
||||
'',
|
||||
'ACP_MODULE',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
false,
|
||||
'ACP_MODULE',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'ACP_CAT',
|
||||
'ACP_MODULE',
|
||||
true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider exists_data
|
||||
*/
|
||||
public function test_exists($parent, $module, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->tool->exists('acp', $parent, $module));
|
||||
}
|
||||
|
||||
public function test_add()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
|
||||
|
||||
// Should throw an exception when trying to add a module that already exists
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
|
||||
$this->fail('Exception not thrown');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', ACP_NEW_CAT, array(
|
||||
'module_basename' => 'acp_new_module',
|
||||
'module_langname' => 'ACP_NEW_MODULE',
|
||||
'module_mode' => 'test',
|
||||
'module_auth' => '',
|
||||
));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE'));
|
||||
}
|
||||
|
||||
public function test_remove()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE'));
|
||||
}
|
||||
}
|
136
tests/dbal/migrator_tool_permission.php
Normal file
136
tests/dbal/migrator_tool_permission.php
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
|
||||
|
||||
class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
// Global $db and $cache are needed in acp/auth.php constructor
|
||||
global $phpbb_root_path, $phpEx, $db, $cache;
|
||||
|
||||
parent::setup();
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
$cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null());
|
||||
$this->auth = new phpbb_auth();
|
||||
|
||||
$this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
|
||||
}
|
||||
|
||||
public function exists_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'global',
|
||||
true,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'local',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'both',
|
||||
true,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'both',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'does_not_exist',
|
||||
true,
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider exists_data
|
||||
*/
|
||||
public function test_exists($auth_option, $global, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->tool->exists($auth_option, $global));
|
||||
}
|
||||
|
||||
public function test_add()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('new', true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('new', true));
|
||||
$this->assertEquals(false, $this->tool->exists('new', false));
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->add('new', false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('new', false));
|
||||
|
||||
// Should fail (duplicate)
|
||||
try
|
||||
{
|
||||
$this->tool->add('new', true);
|
||||
$this->fail('Did not throw exception on duplicate');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
public function test_remove()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->remove('global', true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(false, $this->tool->exists('global', true));
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->remove('both', false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(false, $this->tool->exists('both', false));
|
||||
|
||||
// Should fail (does not exist)
|
||||
try
|
||||
{
|
||||
$this->tool->remove('new', true);
|
||||
$this->fail('Did not throw exception on duplicate');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue