aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-01-08 22:09:14 -0600
committerNathan Guse <nathaniel.guse@gmail.com>2013-01-09 16:44:07 -0600
commit5c91e2569cb3a400acd20bf06cc0e609dd63a778 (patch)
tree0e449198b6e9c5c0875b5107008de4e633b63cd3
parent826607a40509d40ba5a85e5b0bc72a54f77d41d6 (diff)
downloadforums-5c91e2569cb3a400acd20bf06cc0e609dd63a778.tar
forums-5c91e2569cb3a400acd20bf06cc0e609dd63a778.tar.gz
forums-5c91e2569cb3a400acd20bf06cc0e609dd63a778.tar.bz2
forums-5c91e2569cb3a400acd20bf06cc0e609dd63a778.tar.xz
forums-5c91e2569cb3a400acd20bf06cc0e609dd63a778.zip
[feature/migrations] Migrations now somewhat works
PHPBB3-9737
-rw-r--r--phpBB/config/migrator.yml49
-rw-r--r--phpBB/config/services.yml40
-rw-r--r--phpBB/config/tables.yml1
-rw-r--r--phpBB/develop/create_schema_files.php4
-rw-r--r--phpBB/includes/db/driver/mysqli.php1
-rw-r--r--phpBB/includes/db/migration/data/3_0_11_rc1.php2
-rw-r--r--phpBB/includes/db/migration/data/3_0_12_rc1.php101
-rw-r--r--phpBB/includes/db/migration/data/3_0_3_rc1.php6
-rw-r--r--phpBB/includes/db/migration/data/3_0_4.php2
-rw-r--r--phpBB/includes/db/migration/data/3_0_4_rc1.php4
-rw-r--r--phpBB/includes/db/migration/data/3_0_5_rc1.php8
-rw-r--r--phpBB/includes/db/migration/data/3_0_6_rc1.php60
-rw-r--r--phpBB/includes/db/migration/data/3_0_7_rc2.php2
-rw-r--r--phpBB/includes/db/migration/data/3_0_8_rc1.php10
-rw-r--r--phpBB/includes/db/migration/data/3_0_9_rc1.php2
-rw-r--r--phpBB/includes/db/migration/data/3_1_0_dev.php100
-rw-r--r--phpBB/includes/db/migration/data/extensions.php3
-rw-r--r--phpBB/includes/db/migration/data/style_update_p1.php62
-rw-r--r--phpBB/includes/db/migration/data/style_update_p2.php43
-rw-r--r--phpBB/includes/db/migration/data/timezone.php5
-rw-r--r--phpBB/includes/db/migration/exception.php40
-rw-r--r--phpBB/includes/db/migration/migration.php (renamed from phpBB/includes/db/migration.php)33
-rw-r--r--phpBB/includes/db/migration/tool/config.php (renamed from phpBB/includes/db/migration/tools/config.php)14
-rw-r--r--phpBB/includes/db/migration/tool/interface.php18
-rw-r--r--phpBB/includes/db/migration/tool/module.php (renamed from phpBB/includes/db/migration/tools/module.php)66
-rw-r--r--phpBB/includes/db/migration/tool/permission.php (renamed from phpBB/includes/db/migration/tools/permission.php)124
-rw-r--r--phpBB/includes/db/migration/tools/umil.php3037
-rw-r--r--phpBB/includes/db/migrator.php113
-rw-r--r--phpBB/includes/functions.php3
-rw-r--r--phpBB/install/database_update.php65
-rw-r--r--phpBB/install/schemas/firebird_schema.sql29
-rw-r--r--phpBB/install/schemas/mssql_schema.sql42
-rw-r--r--phpBB/install/schemas/mysql_40_schema.sql26
-rw-r--r--phpBB/install/schemas/mysql_41_schema.sql26
-rw-r--r--phpBB/install/schemas/oracle_schema.sql32
-rw-r--r--phpBB/install/schemas/postgres_schema.sql30
-rw-r--r--phpBB/install/schemas/sqlite_schema.sql28
-rw-r--r--phpBB/test.php121
-rw-r--r--tests/dbal/fixtures/migrator_module.xml42
-rw-r--r--tests/dbal/fixtures/migrator_permission.xml31
-rw-r--r--tests/dbal/migrator_test.php12
-rw-r--r--tests/dbal/migrator_tool_config_test.php97
-rw-r--r--tests/dbal/migrator_tool_module.php128
-rw-r--r--tests/dbal/migrator_tool_permission.php136
44 files changed, 1377 insertions, 3421 deletions
diff --git a/phpBB/config/migrator.yml b/phpBB/config/migrator.yml
new file mode 100644
index 0000000000..999a2d41a3
--- /dev/null
+++ b/phpBB/config/migrator.yml
@@ -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 }
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index 4125491dd0..ee52ca2800 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -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
diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml
index a9414cf66c..dd53417b1c 100644
--- a/phpBB/config/tables.yml
+++ b/phpBB/config/tables.yml
@@ -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
diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php
index 1abafb3b6d..b37dcc246f 100644
--- a/phpBB/develop/create_schema_files.php
+++ b/phpBB/develop/create_schema_files.php
@@ -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),
diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php
index 7448bf1670..94921a22b7 100644
--- a/phpBB/includes/db/driver/mysqli.php
+++ b/phpBB/includes/db/driver/mysqli.php
@@ -24,6 +24,7 @@ if (!defined('IN_PHPBB'))
class phpbb_db_driver_mysqli extends phpbb_db_driver
{
var $multi_insert = true;
+
var $connect_error = '';
/**
diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php
index 1509120f68..daf106accf 100644
--- a/phpBB/includes/db/migration/data/3_0_11_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php
@@ -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))
{
diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php
index e5ff8c5814..0d8702f19e 100644
--- a/phpBB/includes/db/migration/data/3_0_12_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php
@@ -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);
+ }
+ }
+ }
+ }
}
-*/ \ No newline at end of file
diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php
index d5c110eb7d..2320c4ac4b 100644
--- a/phpBB/includes/db/migration/data/3_0_3_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php
@@ -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()
diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php
index 4965ac38d0..1af4508331 100644
--- a/phpBB/includes/db/migration/data/3_0_4.php
+++ b/phpBB/includes/db/migration/data/3_0_4.php
@@ -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
diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php
index 2964dcebc9..e9bb0e01f5 100644
--- a/phpBB/includes/db/migration/data/3_0_4_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php
@@ -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);
}
}
diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php
index 9205f0d5f8..cbf28c0be6 100644
--- a/phpBB/includes/db/migration/data/3_0_5_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php
@@ -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);
diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php
index a868d70684..35adcf52be 100644
--- a/phpBB/includes/db/migration/data/3_0_6_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php
@@ -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();
}
diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php
index e043f35705..e2c6acce1e 100644
--- a/phpBB/includes/db/migration/data/3_0_7_rc2.php
+++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php
@@ -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)
{
diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php
index 3f51806fd9..b58b0966a5 100644
--- a/phpBB/includes/db/migration/data/3_0_8_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php
@@ -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(
diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php
index 256426849c..ea49cdbba9 100644
--- a/phpBB/includes/db/migration/data/3_0_9_rc1.php
+++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php
@@ -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),
),
),
diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php
index 987ab94646..6eb5a6ddee 100644
--- a/phpBB/includes/db/migration/data/3_1_0_dev.php
+++ b/phpBB/includes/db/migration/data/3_1_0_dev.php
@@ -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
diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php
index 85d5511ef0..d28e0ebabb 100644
--- a/phpBB/includes/db/migration/data/extensions.php
+++ b/phpBB/includes/db/migration/data/extensions.php
@@ -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')),
);
}
}
diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php
index d570caae04..1c46e4147b 100644
--- a/phpBB/includes/db/migration/data/style_update_p1.php
+++ b/phpBB/includes/db/migration/data/style_update_p1.php
@@ -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' => '&copy; 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));
+ }
}
}
diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php
index 2c0991de59..db4b7f1753 100644
--- a/phpBB/includes/db/migration/data/style_update_p2.php
+++ b/phpBB/includes/db/migration/data/style_update_p2.php
@@ -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', '&copy; 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();
}
}
diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php
index 89fafbad28..7734ed4b76 100644
--- a/phpBB/includes/db/migration/data/timezone.php
+++ b/phpBB/includes/db/migration/data/timezone.php
@@ -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');
diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php
new file mode 100644
index 0000000000..19fb39ab23
--- /dev/null
+++ b/phpBB/includes/db/migration/exception.php
@@ -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);
+ }
+}
diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration/migration.php
index 10f7b71551..c2c6da855b 100644
--- a/phpBB/includes/db/migration.php
+++ b/phpBB/includes/db/migration/migration.php
@@ -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;
+ }
}
diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tool/config.php
index 2d58c8093c..35fa3ce566 100644
--- a/phpBB/includes/db/migration/tools/config.php
+++ b/phpBB/includes/db/migration/tool/config.php
@@ -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;
@@ -18,6 +18,14 @@ class phpbb_db_migration_tools_config
}
/**
+ * {@inheritdoc}
+ */
+ public function get_name()
+ {
+ return 'config';
+ }
+
+ /**
* Config Add
*
* This function allows you to add a config setting.
@@ -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;
}
-} \ No newline at end of file
+}
diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php
new file mode 100644
index 0000000000..1815f5e8a2
--- /dev/null
+++ b/phpBB/includes/db/migration/tool/interface.php
@@ -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();
+}
diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tool/module.php
index e17197d73e..a503f08c01 100644
--- a/phpBB/includes/db/migration/tools/module.php
+++ b/phpBB/includes/db/migration/tool/module.php
@@ -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;
}
}
-} \ No newline at end of file
+}
diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tool/permission.php
index 7694bae0cb..ebe404bc62 100644
--- a/phpBB/includes/db/migration/tools/permission.php
+++ b/phpBB/includes/db/migration/tool/permission.php
@@ -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;
@@ -34,6 +34,14 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base
}
/**
+ * {@inheritdoc}
+ */
+ public function get_name()
+ {
+ return 'permission';
+ }
+
+ /**
* Permission Exists
*
* Check if a permission (auth) setting 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;
}
-} \ No newline at end of file
+}
diff --git a/phpBB/includes/db/migration/tools/umil.php b/phpBB/includes/db/migration/tools/umil.php
deleted file mode 100644
index ce7b8ff3be..0000000000
--- a/phpBB/includes/db/migration/tools/umil.php
+++ /dev/null
@@ -1,3037 +0,0 @@
-<?php
-/**
- *
- * @author Nathan Guse (EXreaction) http://lithiumstudios.org
- * @author David Lewis (Highway of Life) highwayoflife@gmail.com
- * @package umil
- * @version $Id$
- * @copyright (c) 2008 phpBB Group
- * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
- *
- */
-
-/**
- * @ignore
- */
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-define('UMIL_VERSION', '1.0.4');
-
-/**
-* Multicall instructions
-*
-* With the "multicall" (as I am calling it) you can make a single function call and have it repeat the actions multiple times on information sent from an array.
-*
-* To do this (it does not work on the _exists functions), all you must do is send the first variable in the function call as an array and for each item, send an array for each of the variables in order.
-*
-* Example:
-* $umil->config_add(array(
-* array('config_name', 'config_value'),
-* array('config_name1', 'config_value1'),
-* array('config_name2', 'config_value2', true),
-* array('config_name3', 'config_value3', true),
-* );
-*/
-
-/**
-* UMIL - Unified MOD Installation Library class
-*
-* Cache Functions
-* cache_purge($type = '', $style_id = 0)
-*
-* Config Functions:
-* config_exists($config_name, $return_result = false)
-* config_add($config_name, $config_value = '', $is_dynamic = false)
-* config_update($config_name, $config_value, $is_dynamic = false)
-* config_remove($config_name)
-*
-* Module Functions
-* module_exists($class, $parent, $module)
-* module_add($class, $parent = 0, $data = array())
-* module_remove($class, $parent = 0, $module = '')
-*
-* Permissions/Auth Functions
-* permission_exists($auth_option, $global = true)
-* permission_add($auth_option, $global = true)
-* permission_remove($auth_option, $global = true)
-* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true)
-* permission_unset($name, $auth_option = array(), $type = 'role', $global = true)
-*
-* Table Functions
-* table_exists($table_name)
-* table_add($table_name, $table_data = array())
-* table_remove($table_name)
-*
-* Table Column Functions
-* table_column_exists($table_name, $column_name)
-* table_column_add($table_name, $column_name = '', $column_data = array())
-* table_column_update($table_name, $column_name = '', $column_data = array())
-* table_column_remove($table_name, $column_name = '')
-*
-* Table Key/Index Functions
-* table_index_exists($table_name, $index_name)
-* table_index_add($table_name, $index_name = '', $column = array())
-* table_index_remove($table_name, $index_name = '')
-*
-* Table Row Functions (note that these actions are not reversed automatically during uninstallation)
-* table_row_insert($table_name, $data = array())
-* table_row_remove($table_name, $data = array())
-* table_row_update($table_name, $data = array(), $new_data = array())
-*
-* Version Check Function
-* version_check($url, $path, $file)
-*/
-class umil
-{
- /**
- * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran)
- *
- * @var string
- */
- var $command = '';
-
- /**
- * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked.
- *
- * @var string
- */
- var $result = '';
-
- /**
- * Auto run $this->display_results after running a command
- */
- var $auto_display_results = false;
-
- /**
- * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff
- */
- var $stand_alone = false;
-
- /**
- * Were any new permissions added (used in umil_frontend)?
- */
- var $permissions_added = false;
-
- /**
- * Database Object
- */
- var $db = false;
-
- /**
- * Database Tools Object
- */
- var $db_tools = false;
-
- /**
- * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this...
- */
- var $table_prefix = false;
-
- /**
- * Constructor
- */
- function umil($stand_alone = false, $db = false)
- {
- // Setup $this->db
- if ($db !== false)
- {
- if (!is_object($db) || !method_exists($db, 'sql_query'))
- {
- trigger_error('Invalid $db Object');
- }
-
- $this->db = $db;
- }
- else
- {
- global $db;
- $this->db = $db;
- }
-
- // Setup $this->db_tools
- if (!class_exists('phpbb_db_tools'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
- }
- $this->db_tools = new phpbb_db_tools($this->db);
-
- $this->stand_alone = $stand_alone;
-
- if (!$stand_alone)
- {
- global $config, $user, $phpbb_root_path, $phpEx;
-
- /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed.
- if (method_exists('user', 'set_custom_lang_path'))
- {
- $user->set_custom_lang_path($phpbb_root_path . 'umil/language/');
- $user->add_lang('umil');
- $user->set_custom_lang_path($phpbb_root_path . 'language/');
- }
- else
- {*/
- // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file.
- if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx"))
- {
- $path = $user->data['user_lang'];
- }
- else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx"))
- {
- $path = basename($config['default_lang']);
- }
- else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx"))
- {
- $path = 'en';
- }
- else
- {
- trigger_error('Language Files Missing.<br /><br />Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
- }
-
- $user->add_lang('./../../umil/language/' . $path . '/umil');
- //}
-
- $user->add_lang(array('acp/common', 'acp/permissions'));
-
- // Check to see if a newer version is available.
- $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt'));
- if (is_array($info) && isset($info[0]) && isset($info[1]))
- {
- if (version_compare(UMIL_VERSION, $info[0], '<'))
- {
- global $template;
-
- // Make sure user->setup() has been called
- if (empty($user->lang))
- {
- $user->setup();
- }
-
- page_header('', false);
-
- $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.<br /><br />Please download the latest UMIL (Unified MOD Install Library) from: <a href="%1$s">%1$s</a>';
- $template->assign_vars(array(
- 'S_BOARD_DISABLED' => true,
- 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]),
- ));
- }
- }
- }
- }
-
- /**
- * umil_start
- *
- * A function which runs (almost) every time a function here is ran
- */
- function umil_start()
- {
- global $user;
-
- // Set up the command. This will get the arguments sent to the function.
- $args = func_get_args();
- $this->command = call_user_func_array(array($this, 'get_output_text'), $args);
-
- $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS';
- $this->db->sql_return_on_error(true);
-
- //$this->db->sql_transaction('begin');
- }
-
- /**
- * umil_end
- *
- * A function which runs (almost) every time a function here is ran
- */
- function umil_end()
- {
- global $user;
-
- // Set up the result. This will get the arguments sent to the function.
- $args = func_get_args();
- $result = call_user_func_array(array($this, 'get_output_text'), $args);
- $this->result = ($result) ? $result : $this->result;
-
- if ($this->db->sql_error_triggered)
- {
- if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'))
- {
- $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message'];
- }
- else
- {
- $this->result .= '<br /><br />SQL ERROR ' . $this->db->sql_error_returned['message'];
- }
-
- //$this->db->sql_transaction('rollback');
- }
- else
- {
- //$this->db->sql_transaction('commit');
- }
-
- $this->db->sql_return_on_error(false);
-
- // Auto output if requested.
- if ($this->auto_display_results && method_exists($this, 'display_results'))
- {
- $this->display_results();
- }
-
- return '<strong>' . $this->command . '</strong><br />' . $this->result;
- }
-
- /**
- * Get text for output
- *
- * Takes the given arguments and prepares them for the UI
- *
- * First argument sent is used as the language key
- * Further arguments (if send) are used on the language key through vsprintf()
- *
- * @return string Returns the prepared string for output
- */
- function get_output_text()
- {
- global $user;
-
- // Set up the command. This will get the arguments sent to the function.
- $args = func_get_args();
- if (sizeof($args))
- {
- $lang_key = array_shift($args);
-
- if (sizeof($args))
- {
- $lang_args = array();
- foreach ($args as $arg)
- {
- $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg;
- }
-
- return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args);
- }
- else
- {
- return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key);
- }
- }
-
- return '';
- }
-
- /**
- * Run Actions
- *
- * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions.
- *
- * @param string $action The action. install|update|uninstall
- * @param array $versions The array of versions and the actions for each
- * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version
- * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to.
- */
- function run_actions($action, $versions, $version_config_name, $version_select = '')
- {
- // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers
- uksort($versions, 'version_compare');
-
- // Find the current version to install
- $current_version = '0.0.0';
- foreach ($versions as $version => $actions)
- {
- $current_version = $version;
- }
-
- $db_version = '';
- if ($this->config_exists($version_config_name))
- {
- global $config;
- $db_version = $config[$version_config_name];
- }
-
- // Set the action to install from update if nothing is currently installed
- if ($action == 'update' && !$db_version)
- {
- $action = 'install';
- }
-
- if ($action == 'install' || $action == 'update')
- {
- $version_installed = $db_version;
- foreach ($versions as $version => $version_actions)
- {
- // If we are updating
- if ($db_version && version_compare($version, $db_version, '<='))
- {
- continue;
- }
-
- if ($version_select && version_compare($version, $version_select, '>'))
- {
- break;
- }
-
- foreach ($version_actions as $method => $params)
- {
- if ($method == 'custom')
- {
- $this->_call_custom_function($params, $action, $version);
- }
- else
- {
- if (method_exists($this, $method))
- {
- call_user_func(array($this, $method), $params);
- }
- }
- }
-
- $version_installed = $version;
- }
-
- // update the version number or add it
- if ($this->config_exists($version_config_name))
- {
- $this->config_update($version_config_name, $version_installed);
- }
- else
- {
- $this->config_add($version_config_name, $version_installed);
- }
- }
- else if ($action == 'uninstall' && $db_version)
- {
- // reverse version list
- $versions = array_reverse($versions);
-
- foreach ($versions as $version => $version_actions)
- {
- // Uninstalling and this listed version is newer than installed
- if (version_compare($version, $db_version, '>'))
- {
- continue;
- }
-
- // Version selection stuff
- if ($version_select && version_compare($version, $version_select, '<='))
- {
- // update the version number
- $this->config_update($version_config_name, $version);
- break;
- }
-
- $cache_purge = false;
- $version_actions = array_reverse($version_actions);
- foreach ($version_actions as $method => $params)
- {
- if ($method == 'custom')
- {
- $this->_call_custom_function($params, $action, $version);
- }
- else
- {
- // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end).
- if ($method == 'cache_purge')
- {
- $cache_purge = $params;
- continue;
- }
-
- // A few things are not possible for uninstallations update actions and table_row actions
- if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false)
- {
- continue;
- }
-
- // reverse function call
- $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method);
- $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method);
-
- if (method_exists($this, $method))
- {
- call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params)));
- }
- }
- }
-
- if ($cache_purge !== false)
- {
- $this->cache_purge($cache_purge);
- }
- }
-
- if (!$version_select)
- {
- // Unset the version number
- $this->config_remove($version_config_name);
- }
- }
- }
-
- /**
- * Call custom function helper
- */
- function _call_custom_function($functions, $action, $version)
- {
- if (!is_array($functions))
- {
- $functions = array($functions);
- }
-
- $return = '';
-
- foreach ($functions as $function)
- {
- if (function_exists($function))
- {
- // Must reset before calling the function
- $this->umil_start();
-
- $returned = call_user_func($function, $action, $version);
- if (is_string($returned))
- {
- $this->command = $this->get_output_text($returned);
- }
- else if (is_array($returned) && isset($returned['command']))
- {
- if (is_array($returned['command']))
- {
- $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']);
- }
- else
- {
- $this->command = $this->get_output_text($returned['command']);
- }
-
- if (isset($returned['result']))
- {
- $this->result = $this->get_output_text($returned['result']);
- }
- }
- else
- {
- $this->command = $this->get_output_text('UNKNOWN');
- }
-
- $return .= $this->umil_end() . '<br />';
- }
- }
-
- return $return;
- }
-
- /**
- * Multicall Helper
- *
- * @param mixed $function Function name to call
- * @param mixed $params The parameters array
- *
- * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array)
- */
- function multicall($function, $params)
- {
- if (is_array($params) && !empty($params))
- {
- foreach ($params as $param)
- {
- if (!is_array($param))
- {
- call_user_func(array($this, $function), $param);
- }
- else
- {
- call_user_func_array(array($this, $function), $param);
- }
- }
- return true;
- }
-
- return false;
- }
-
- /**
- * Cache Purge
- *
- * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache.
- *
- * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache.
- * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section)
- */
- function cache_purge($type = '', $style_id = 0)
- {
- global $auth, $cache, $user, $phpbb_root_path, $phpEx;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $type))
- {
- return;
- }
-
- $style_id = (int) $style_id;
- $type = (string) $type; // Prevent PHP bug.
-
- switch ($type)
- {
- case 'auth' :
- $this->umil_start('AUTH_CACHE_PURGE');
- $cache->destroy('_acl_options');
- $auth->acl_clear_prefetch();
-
- return $this->umil_end();
- break;
-
- case 'imageset' :
- if ($style_id == 0)
- {
- $return = array();
- $sql = 'SELECT imageset_id
- FROM ' . STYLES_IMAGESET_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $return[] = $this->cache_purge('imageset', $row['imageset_id']);
- }
- $this->db->sql_freeresult($result);
-
- return implode('<br /><br />', $return);
- }
- else
- {
- $sql = 'SELECT *
- FROM ' . STYLES_IMAGESET_TABLE . "
- WHERE imageset_id = $style_id";
- $result = $this->db->sql_query($sql);
- $imageset_row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if (!$imageset_row)
- {
- $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
-
- $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']);
-
- // The following is from includes/acp/acp_styles.php (edited)
- $sql_ary = array();
-
- $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg");
-
- $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
- WHERE imageset_id = ' . $style_id;
- $result = $this->db->sql_query($sql);
-
- foreach ($cfg_data_imageset as $image_name => $value)
- {
- if (strpos($value, '*') !== false)
- {
- if (substr($value, -1, 1) === '*')
- {
- list($image_filename, $image_height) = explode('*', $value);
- $image_width = 0;
- }
- else
- {
- list($image_filename, $image_height, $image_width) = explode('*', $value);
- }
- }
- else
- {
- $image_filename = $value;
- $image_height = $image_width = 0;
- }
-
- if (strpos($image_name, 'img_') === 0 && $image_filename)
- {
- $image_name = substr($image_name, 4);
-
- $sql_ary[] = array(
- 'image_name' => (string) $image_name,
- 'image_filename' => (string) $image_filename,
- 'image_height' => (int) $image_height,
- 'image_width' => (int) $image_width,
- 'imageset_id' => (int) $style_id,
- 'image_lang' => '',
- );
- }
- }
-
- $sql = 'SELECT lang_dir
- FROM ' . LANG_TABLE;
- $result = $this->db->sql_query($sql);
-
- while ($row = $this->db->sql_fetchrow($result))
- {
- if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"))
- {
- $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg");
- foreach ($cfg_data_imageset_data as $image_name => $value)
- {
- if (strpos($value, '*') !== false)
- {
- if (substr($value, -1, 1) === '*')
- {
- list($image_filename, $image_height) = explode('*', $value);
- $image_width = 0;
- }
- else
- {
- list($image_filename, $image_height, $image_width) = explode('*', $value);
- }
- }
- else
- {
- $image_filename = $value;
- $image_height = $image_width = 0;
- }
-
- if (strpos($image_name, 'img_') === 0 && $image_filename)
- {
- $image_name = substr($image_name, 4);
- $sql_ary[] = array(
- 'image_name' => (string) $image_name,
- 'image_filename' => (string) $image_filename,
- 'image_height' => (int) $image_height,
- 'image_width' => (int) $image_width,
- 'imageset_id' => (int) $style_id,
- 'image_lang' => (string) $row['lang_dir'],
- );
- }
- }
- }
- }
- $this->db->sql_freeresult($result);
-
- $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
-
- $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
-
- return $this->umil_end();
- }
- break;
- //case 'imageset' :
-
- case 'template' :
- if ($style_id == 0)
- {
- $return = array();
- $sql = 'SELECT template_id
- FROM ' . STYLES_TEMPLATE_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $return[] = $this->cache_purge('template', $row['template_id']);
- }
- $this->db->sql_freeresult($result);
-
- return implode('<br /><br />', $return);
- }
- else
- {
- $sql = 'SELECT *
- FROM ' . STYLES_TEMPLATE_TABLE . "
- WHERE template_id = $style_id";
- $result = $this->db->sql_query($sql);
- $template_row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if (!$template_row)
- {
- $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
-
- $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']);
-
- // The following is from includes/acp/acp_styles.php
- if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/"))
- {
- $filelist = array('' => array());
-
- $sql = 'SELECT template_filename, template_mtime
- FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
- WHERE template_id = $style_id";
- $result = $this->db->sql_query($sql);
-
- while ($row = $this->db->sql_fetchrow($result))
- {
-// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime'])
-// {
- // get folder info from the filename
- if (($slash_pos = strrpos($row['template_filename'], '/')) === false)
- {
- $filelist[''][] = $row['template_filename'];
- }
- else
- {
- $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1);
- }
-// }
- }
- $this->db->sql_freeresult($result);
-
- $includes = array();
- foreach ($filelist as $pathfile => $file_ary)
- {
- foreach ($file_ary as $file)
- {
- if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r')))
- {
- return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file");
- }
- $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"));
- fclose($fp);
-
- if (preg_match_all('#<!-- INCLUDE (.*?\.html) -->#is', $template_data, $matches))
- {
- foreach ($matches[1] as $match)
- {
- $includes[trim($match)][] = $file;
- }
- }
- }
- }
-
- foreach ($filelist as $pathfile => $file_ary)
- {
- foreach ($file_ary as $file)
- {
- // Skip index.
- if (strpos($file, 'index.') === 0)
- {
- continue;
- }
-
- // We could do this using extended inserts ... but that could be one
- // heck of a lot of data ...
- $sql_ary = array(
- 'template_id' => (int) $style_id,
- 'template_filename' => "$pathfile$file",
- 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '',
- 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"),
- 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"),
- );
-
- $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
- WHERE template_id = $style_id
- AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'";
- $this->db->sql_query($sql);
- }
- }
- unset($filelist);
- }
-
- // Purge the forum's cache as well.
- $cache->purge();
-
- return $this->umil_end();
- }
- break;
- //case 'template' :
-
- case 'theme' :
- if ($style_id == 0)
- {
- $return = array();
- $sql = 'SELECT theme_id
- FROM ' . STYLES_THEME_TABLE;
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $return[] = $this->cache_purge('theme', $row['theme_id']);
- }
- $this->db->sql_freeresult($result);
-
- return implode('<br /><br />', $return);
- }
- else
- {
- $sql = 'SELECT *
- FROM ' . STYLES_THEME_TABLE . "
- WHERE theme_id = $style_id";
- $result = $this->db->sql_query($sql);
- $theme_row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if (!$theme_row)
- {
- $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
-
- $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']);
-
- // The following is from includes/acp/acp_styles.php
- if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"))
- {
- $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css');
-
- // Match CSS imports
- $matches = array();
- preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches);
-
- if (sizeof($matches))
- {
- foreach ($matches[0] as $idx => $match)
- {
- if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}"))
- {
- continue;
- }
-
- $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}"));
- $stylesheet = str_replace($match, $content, $stylesheet);
- }
- }
-
- // adjust paths
- $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet);
-
- // Save CSS contents
- $sql_ary = array(
- 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"),
- 'theme_data' => $db_theme_data,
- );
-
- $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "
- WHERE theme_id = $style_id";
- $this->db->sql_query($sql);
-
- $cache->destroy('sql', STYLES_THEME_TABLE);
- }
-
- return $this->umil_end();
- }
- break;
- //case 'theme' :
-
- default:
- $this->umil_start('CACHE_PURGE');
- $cache->purge();
-
- return $this->umil_end();
- break;
- }
- }
-
- /**
- * Config Exists
- *
- * This function is to check to see if a config variable exists or if it does not.
- *
- * @param string $config_name The name of the config setting you wish to check for.
- * @param bool $return_result - return the config value/default if true : default false.
- *
- * @return bool true/false if config exists
- */
- function config_exists($config_name, $return_result = false)
- {
- global $config, $cache;
-
- $sql = 'SELECT *
- FROM ' . CONFIG_TABLE . "
- WHERE config_name = '" . $this->db->sql_escape($config_name) . "'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if ($row)
- {
- if (!isset($config[$config_name]))
- {
- $config[$config_name] = $row['config_value'];
-
- if (!$row['is_dynamic'])
- {
- $cache->destroy('config');
- }
- }
-
- return ($return_result) ? $row : true;
- }
-
- // this should never happen, but if it does, we need to remove the config from the array
- if (isset($config[$config_name]))
- {
- unset($config[$config_name]);
- $cache->destroy('config');
- }
-
- return false;
- }
-
- /**
- * Config Add
- *
- * This function allows you to add a config setting.
- *
- * @param string $config_name The name of the config setting you would like to add
- * @param mixed $config_value The value of the config setting
- * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not.
- *
- * @return result
- */
- function config_add($config_name, $config_value = '', $is_dynamic = false)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $config_name))
- {
- return;
- }
-
- $this->umil_start('CONFIG_ADD', $config_name);
-
- if ($this->config_exists($config_name))
- {
- return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name);
- }
-
- set_config($config_name, $config_value, $is_dynamic);
-
- return $this->umil_end();
- }
-
- /**
- * Config Update
- *
- * This function allows you to update an existing config setting.
- *
- * @param string $config_name The name of the config setting you would like to update
- * @param mixed $config_value The value of the config setting
- * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not.
- *
- * @return result
- */
- function config_update($config_name, $config_value = '', $is_dynamic = false)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $config_name))
- {
- return;
- }
-
- $this->umil_start('CONFIG_UPDATE', $config_name);
-
- if (!$this->config_exists($config_name))
- {
- return $this->umil_end('CONFIG_NOT_EXIST', $config_name);
- }
-
- set_config($config_name, $config_value, $is_dynamic);
-
- return $this->umil_end();
- }
-
- /**
- * Config Remove
- *
- * This function allows you to remove an existing config setting.
- *
- * @param string $config_name The name of the config setting you would like to remove
- *
- * @return result
- */
- function config_remove($config_name)
- {
- global $cache, $config;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $config_name))
- {
- return;
- }
-
- $this->umil_start('CONFIG_REMOVE', $config_name);
-
- if (!$this->config_exists($config_name))
- {
- return $this->umil_end('CONFIG_NOT_EXIST', $config_name);
- }
-
- $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'";
- $this->db->sql_query($sql);
-
- unset($config[$config_name]);
- $cache->destroy('config');
-
- return $this->umil_end();
- }
-
- /**
- * Module Exists
- *
- * Check if a module exists
- *
- * @param string $class The module class(acp|mcp|ucp)
- * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide.
- * @param int|string $module The module_id|module_langname you would like to check for to see if it exists
- */
- function module_exists($class, $parent, $module)
- {
- // the main root directory should return true
- if (!$module)
- {
- return true;
- }
-
- $class = $this->db->sql_escape($class);
- $module = $this->db->sql_escape($module);
-
- $parent_sql = '';
- if ($parent !== false)
- {
- // Allows '' to be sent as 0
- $parent = (!$parent) ? 0 : $parent;
-
- if (!is_numeric($parent))
- {
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
- AND module_class = '$class'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if (!$row)
- {
- return false;
- }
-
- $parent_sql = 'AND parent_id = ' . (int) $row['module_id'];
- }
- else
- {
- $parent_sql = 'AND parent_id = ' . (int) $parent;
- }
- }
-
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_class = '$class'
- $parent_sql
- AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'");
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if ($row)
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Module Add
- *
- * Add a new module
- *
- * @param string $class The module class(acp|mcp|ucp)
- * @param int|string $parent The parent module_id|module_langname (0 for no parent)
- * @param array $data an array of the data on the new module. This can be setup in two different ways.
- * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below,
- * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode.
- * array(
- * 'module_enabled' => 1,
- * 'module_display' => 1,
- * 'module_basename' => '',
- * 'module_class' => $class,
- * 'parent_id' => (int) $parent,
- * 'module_langname' => '',
- * 'module_mode' => '',
- * 'module_auth' => '',
- * )
- * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file.
- * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file):
- * array(
- * 'module_basename' => 'asacp',
- * 'modes' => array('settings', 'log', 'flag'),
- * )
- * Optionally you may not send 'modes' and it will insert all of the modules in that info file.
- * @param string|bool $include_path If you would like to use a custom include path, specify that here
- */
- function module_add($class, $parent = 0, $data = array(), $include_path = false)
- {
- global $cache, $user, $phpbb_root_path, $phpEx;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $class))
- {
- return;
- }
-
- // Prevent stupid things like trying to add a module with no name or any data on it
- if (empty($data))
- {
- $this->umil_start('MODULE_ADD', $class, 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
-
- // Allows '' to be sent as 0
- $parent = (!$parent) ? 0 : $parent;
-
- // allow sending the name as a string in $data to create a category
- if (!is_array($data))
- {
- $data = array('module_langname' => $data);
- }
-
- if (!isset($data['module_langname']))
- {
- // The "automatic" way
- $basename = (isset($data['module_basename'])) ? $data['module_basename'] : '';
- $basename = str_replace(array('/', '\\'), '', $basename);
- $class = str_replace(array('/', '\\'), '', $class);
- $info_file = "$class/info/{$class}_$basename.$phpEx";
-
- // The manual and automatic ways both failed...
- if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file))
- {
- $this->umil_start('MODULE_ADD', $class, $info_file);
- return $this->umil_end('FAIL');
- }
-
- $classname = "{$class}_{$basename}_info";
-
- if (!class_exists($classname))
- {
- include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file);
- }
-
- $info = new $classname;
- $module = $info->module();
- unset($info);
-
- $result = '';
- foreach ($module['modes'] as $mode => $module_info)
- {
- if (!isset($data['modes']) || in_array($mode, $data['modes']))
- {
- $new_module = array(
- 'module_basename' => $basename,
- 'module_langname' => $module_info['title'],
- 'module_mode' => $mode,
- 'module_auth' => $module_info['auth'],
- 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true,
- 'before' => (isset($module_info['before'])) ? $module_info['before'] : false,
- 'after' => (isset($module_info['after'])) ? $module_info['after'] : false,
- );
-
- // Run the "manual" way with the data we've collected.
- $result .= ((isset($data['spacer'])) ? $data['spacer'] : '<br />') . $this->module_add($class, $parent, $new_module);
- }
- }
-
- return $result;
- }
-
- // The "manual" way
- $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname']));
- add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname']));
-
- $class = $this->db->sql_escape($class);
-
- if (!is_numeric($parent))
- {
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
- AND module_class = '$class'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if (!$row)
- {
- return $this->umil_end('PARENT_NOT_EXIST');
- }
-
- $parent = $data['parent_id'] = $row['module_id'];
- }
- else if (!$this->module_exists($class, false, $parent))
- {
- return $this->umil_end('PARENT_NOT_EXIST');
- }
-
- if ($this->module_exists($class, $parent, $data['module_langname']))
- {
- return $this->umil_end('MODULE_ALREADY_EXIST');
- }
-
- if (!class_exists('acp_modules'))
- {
- include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
- $user->add_lang('acp/modules');
- }
- $acp_modules = new acp_modules();
-
- $module_data = array(
- 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,
- 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1,
- 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '',
- 'module_class' => $class,
- 'parent_id' => (int) $parent,
- 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '',
- 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '',
- 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
- );
- $result = $acp_modules->update_module_data($module_data, true);
-
- // update_module_data can either return a string or an empty array...
- if (is_string($result))
- {
- // Error
- $this->result = $this->get_output_text($result);
- }
- else
- {
- // Success
-
- // Move the module if requested above/below an existing one
- if (isset($data['before']) && $data['before'])
- {
- $sql = 'SELECT left_id FROM ' . 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
- 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) . "
- 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 . '
- 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
- 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) . "
- WHERE module_class = '$class'
- AND module_id = {$module_data['module_id']}";
- $this->db->sql_query($sql);
- }
- }
-
- // Clear the Modules Cache
- $cache->destroy("_modules_$class");
-
- return $this->umil_end();
- }
-
- /**
- * Module Remove
- *
- * Remove a module
- *
- * @param string $class The module class(acp|mcp|ucp)
- * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide.
- * @param int|string $module The module id|module_langname
- * @param string|bool $include_path If you would like to use a custom include path, specify that here
- */
- function module_remove($class, $parent = 0, $module = '', $include_path = false)
- {
- global $cache, $user, $phpbb_root_path, $phpEx;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $class))
- {
- return;
- }
-
- // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto
- if (is_array($module))
- {
- if (isset($module['module_langname']))
- {
- // Manual Method
- return $this->module_remove($class, $parent, $module['module_langname'], $include_path);
- }
-
- // Failed.
- if (!isset($module['module_basename']))
- {
- $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN');
- return $this->umil_end('FAIL');
- }
-
- // Automatic method
- $basename = str_replace(array('/', '\\'), '', $module['module_basename']);
- $class = str_replace(array('/', '\\'), '', $class);
- $info_file = "$class/info/{$class}_$basename.$phpEx";
-
- if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file))
- {
- $this->umil_start('MODULE_REMOVE', $class, $info_file);
- return $this->umil_end('FAIL');
- }
-
- $classname = "{$class}_{$basename}_info";
-
- if (!class_exists($classname))
- {
- include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file);
- }
-
- $info = new $classname;
- $module_info = $info->module();
- unset($info);
-
- $result = '';
- foreach ($module_info['modes'] as $mode => $info)
- {
- if (!isset($module['modes']) || in_array($mode, $module['modes']))
- {
- $result .= $this->module_remove($class, $parent, $info['title']) . '<br />';
- }
- }
- return $result;
- }
- else
- {
- $class = $this->db->sql_escape($class);
-
- if (!$this->module_exists($class, $parent, $module))
- {
- $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module));
- return $this->umil_end('MODULE_NOT_EXIST');
- }
-
- $parent_sql = '';
- if ($parent !== false)
- {
- // Allows '' to be sent as 0
- $parent = (!$parent) ? 0 : $parent;
-
- if (!is_numeric($parent))
- {
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
- AND module_class = '$class'";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- // we know it exists from the module_exists check
- $parent_sql = 'AND parent_id = ' . (int) $row['module_id'];
- }
- else
- {
- $parent_sql = 'AND parent_id = ' . (int) $parent;
- }
- }
-
- $module_ids = array();
- if (!is_numeric($module))
- {
- $module = $this->db->sql_escape($module);
- $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "
- WHERE module_langname = '$module'
- AND module_class = '$class'
- $parent_sql";
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $module_ids[] = (int) $row['module_id'];
- }
- $this->db->sql_freeresult($result);
-
- $module_name = $module;
- }
- else
- {
- $module = (int) $module;
- $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . "
- WHERE module_id = $module
- AND module_class = '$class'
- $parent_sql";
- $result = $this->db->sql_query($sql);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- $module_name = $row['module_langname'];
- $module_ids[] = $module;
- }
-
- $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name));
- add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name));
-
- if (!class_exists('acp_modules'))
- {
- include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
- $user->add_lang('acp/modules');
- }
- $acp_modules = new acp_modules();
- $acp_modules->module_class = $class;
-
- foreach ($module_ids as $module_id)
- {
- $result = $acp_modules->delete_module($module_id);
- if (!empty($result))
- {
- if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'))
- {
- $this->result = implode('<br />', $result);
- }
- else
- {
- $this->result .= '<br />' . implode('<br />', $result);
- }
- }
- }
-
- $cache->destroy("_modules_$class");
-
- return $this->umil_end();
- }
- }
-
- /**
- * Permission Exists
- *
- * Check if a permission (auth) setting exists
- *
- * @param string $auth_option The name of the permission (auth) option
- * @param bool $global True for checking a global permission setting, False for a local permission setting
- *
- * @return bool true if it exists, false if not
- */
- function permission_exists($auth_option, $global = true)
- {
- if ($global)
- {
- $type_sql = ' AND is_global = 1';
- }
- else
- {
- $type_sql = ' AND is_local = 1';
- }
-
- $sql = 'SELECT auth_option_id
- FROM ' . ACL_OPTIONS_TABLE . "
- WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'"
- . $type_sql;
- $result = $this->db->sql_query($sql);
-
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- if ($row)
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Permission Add
- *
- * Add a permission (auth) option
- *
- * @param string $auth_option The name of the permission (auth) option
- * @param bool $global True for checking a global permission setting, False for a local permission setting
- *
- * @return result
- */
- function permission_add($auth_option, $global = true)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $auth_option))
- {
- return;
- }
-
- $this->umil_start('PERMISSION_ADD', $auth_option);
-
- if ($this->permission_exists($auth_option, $global))
- {
- return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option);
- }
-
- // We've added permissions, so set to true to notify the user.
- $this->permissions_added = true;
-
- if (!class_exists('auth_admin'))
- {
- global $phpbb_root_path, $phpEx;
-
- include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
- }
- $auth_admin = new auth_admin();
-
- // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here.
- if ($this->permission_exists($auth_option, !$global))
- {
- $sql_ary = array(
- 'is_global' => 1,
- '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) . "'";
- $this->db->sql_query($sql);
- }
- else
- {
- if ($global)
- {
- $auth_admin->acl_add_option(array('global' => array($auth_option)));
- }
- else
- {
- $auth_admin->acl_add_option(array('local' => array($auth_option)));
- }
- }
-
- return $this->umil_end();
- }
-
- /**
- * Permission Remove
- *
- * Remove a permission (auth) option
- *
- * @param string $auth_option The name of the permission (auth) option
- * @param bool $global True for checking a global permission setting, False for a local permission setting
- *
- * @return result
- */
- function permission_remove($auth_option, $global = true)
- {
- global $auth, $cache;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $auth_option))
- {
- return;
- }
-
- $this->umil_start('PERMISSION_REMOVE', $auth_option);
-
- if (!$this->permission_exists($auth_option, $global))
- {
- return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option);
- }
-
- if ($global)
- {
- $type_sql = ' AND is_global = 1';
- }
- else
- {
- $type_sql = ' AND is_local = 1';
- }
- $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);
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
-
- $id = $row['auth_option_id'];
-
- // If it is a local and global permission, do not remove the row! :P
- if ($row['is_global'] && $row['is_local'])
- {
- $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
- SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . '
- WHERE auth_option_id = ' . $id;
- $this->db->sql_query($sql);
- }
- else
- {
- // Delete time
- $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id);
- $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id);
- $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id);
- $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id);
- }
-
- // Purge the auth cache
- $cache->destroy('_acl_options');
- $auth->acl_clear_prefetch();
-
- return $this->umil_end();
- }
-
- /**
- * Add a new permission role
- *
- * @param string $role_name The new role name
- * @param sting $role_type The type (u_, m_, a_)
- */
- function permission_role_add($role_name, $role_type = '', $role_description = '')
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $role_name))
- {
- return;
- }
-
- $this->umil_start('PERMISSION_ROLE_ADD', $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');
-
- if ($role_id)
- {
- return $this->umil_end('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) . '\'';
- $this->db->sql_query($sql);
- $role_order = $this->db->sql_fetchfield('max');
- $role_order = (!$role_order) ? 1 : $role_order + 1;
-
- $sql_ary = array(
- 'role_name' => $role_name,
- 'role_description' => $role_description,
- 'role_type' => $role_type,
- 'role_order' => $role_order,
- );
-
- $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
- $this->db->sql_query($sql);
-
- return $this->umil_end();
- }
-
- /**
- * Update the name on a permission role
- *
- * @param string $old_role_name The old role name
- * @param string $new_role_name The new role name
- */
- function permission_role_update($old_role_name, $new_role_name = '')
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $role_name))
- {
- return;
- }
-
- $this->umil_start('PERMISSION_ROLE_UPDATE', $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');
-
- if (!$role_id)
- {
- return $this->umil_end('ROLE_NOT_EXIST', $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 $this->umil_end();
- }
-
- /**
- * Remove a permission role
- *
- * @param string $role_name The role name to remove
- */
- function permission_role_remove($role_name)
- {
- global $auth;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $role_name))
- {
- return;
- }
-
- $this->umil_start('PERMISSION_ROLE_REMOVE', $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');
-
- if (!$role_id)
- {
- return $this->umil_end('ROLE_NOT_EXIST', $role_name);
- }
-
- $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
- WHERE role_id = ' . $role_id;
- $this->db->sql_query($sql);
-
- $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . '
- WHERE role_id = ' . $role_id;
- $this->db->sql_query($sql);
-
- $auth->acl_clear_prefetch();
-
- return $this->umil_end();
- }
-
- /**
- * Permission Set
- *
- * Allows you to set permissions for a certain group/role
- *
- * @param string $name The name of the role/group
- * @param string|array $auth_option The auth_option or array of auth_options you would like to set
- * @param string $type The type (role|group)
- * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission
- */
- function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true)
- {
- global $auth;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $name))
- {
- return;
- }
-
- if (!is_array($auth_option))
- {
- $auth_option = array($auth_option);
- }
-
- $new_auth = array();
- $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))
- {
- $new_auth[] = $row['auth_option_id'];
- }
- $this->db->sql_freeresult($result);
-
- if (!sizeof($new_auth))
- {
- return false;
- }
-
- $current_auth = array();
-
- $type = (string) $type; // Prevent PHP bug.
-
- switch ($type)
- {
- case 'role' :
- $this->umil_start('PERMISSION_SET_ROLE', $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');
-
- if (!$role_id)
- {
- return $this->umil_end('ROLE_NOT_EXIST');
- }
-
- $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))
- {
- $current_auth[$row['auth_option_id']] = $row['auth_setting'];
- }
- $this->db->sql_freeresult($result);
- break;
-
- case 'group' :
- $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');
-
- if (!$group_id)
- {
- $this->umil_start('PERMISSION_SET_GROUP', $name);
- return $this->umil_end('GROUP_NOT_EXIST');
- }
-
- // 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 . '
- WHERE group_id = ' . $group_id . '
- AND auth_role_id <> 0
- AND forum_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 . '
- WHERE role_id = ' . $role_id;
- $this->db->sql_query($sql);
- $role_name = $this->db->sql_fetchfield('role_name');
-
- return $this->permission_set($role_name, $auth_option, 'role', $has_permission);
- }
-
- $this->umil_start('PERMISSION_SET_GROUP', $name);
-
- $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))
- {
- $current_auth[$row['auth_option_id']] = $row['auth_setting'];
- }
- $this->db->sql_freeresult($result);
- break;
- }
-
- $sql_ary = array();
- switch ($type)
- {
- case 'role' :
- foreach ($new_auth as $auth_option_id)
- {
- if (!isset($current_auth[$auth_option_id]))
- {
- $sql_ary[] = array(
- 'role_id' => $role_id,
- 'auth_option_id' => $auth_option_id,
- 'auth_setting' => $has_permission,
- );
- }
- }
-
- $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);
- break;
-
- case 'group' :
- foreach ($new_auth as $auth_option_id)
- {
- if (!isset($current_auth[$auth_option_id]))
- {
- $sql_ary[] = array(
- 'group_id' => $group_id,
- 'auth_option_id' => $auth_option_id,
- 'auth_setting' => $has_permission,
- );
- }
- }
-
- $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary);
- break;
- }
-
- $auth->acl_clear_prefetch();
-
- return $this->umil_end();
- }
-
- /**
- * Permission Unset
- *
- * Allows you to unset (remove) permissions for a certain group/role
- *
- * @param string $name The name of the role/group
- * @param string|array $auth_option The auth_option or array of auth_options you would like to set
- * @param string $type The type (role|group)
- */
- function permission_unset($name, $auth_option = array(), $type = 'role')
- {
- global $auth;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $name))
- {
- return;
- }
-
- if (!is_array($auth_option))
- {
- $auth_option = array($auth_option);
- }
-
- $to_remove = array();
- $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))
- {
- $to_remove[] = $row['auth_option_id'];
- }
- $this->db->sql_freeresult($result);
-
- if (!sizeof($to_remove))
- {
- return false;
- }
-
- $type = (string) $type; // Prevent PHP bug.
-
- switch ($type)
- {
- case 'role' :
- $this->umil_start('PERMISSION_UNSET_ROLE', $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');
-
- if (!$role_id)
- {
- return $this->umil_end('ROLE_NOT_EXIST');
- }
-
- $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
- WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove);
- $this->db->sql_query($sql);
- break;
-
- case 'group' :
- $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');
-
- if (!$group_id)
- {
- $this->umil_start('PERMISSION_UNSET_GROUP', $name);
- return $this->umil_end('GROUP_NOT_EXIST');
- }
-
- // 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 . '
- 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 . '
- WHERE role_id = ' . $role_id;
- $this->db->sql_query($sql);
- $role_name = $this->db->sql_fetchfield('role_name');
-
- return $this->permission_unset($role_name, $auth_option, 'role');
- }
-
- $this->umil_start('PERMISSION_UNSET_GROUP', $name);
-
- $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
- WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove);
- $this->db->sql_query($sql);
- break;
- }
-
- $auth->acl_clear_prefetch();
-
- return $this->umil_end();
- }
-
- /**
- * Table Exists
- *
- * Check if a table exists in the DB or not
- *
- * @param string $table_name The table name to check for
- *
- * @return bool true if the table exists, false if not
- */
- function table_exists($table_name)
- {
- $this->get_table_name($table_name);
-
- // Use sql_table_exists if available
- if (method_exists($this->db_tools, 'sql_table_exists'))
- {
- $roe = $this->db->return_on_error;
- $result = $this->db_tools->sql_table_exists($table_name);
-
- // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before
- if ($roe)
- {
- $this->db->sql_return_on_error(true);
- }
-
- return $result;
- }
-
- if (!function_exists('get_tables'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/functions_install.' . $phpEx);
- }
-
- $tables = get_tables($this->db);
-
- if (in_array($table_name, $tables))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Table Add
- *
- * This only supports input from the array format of db_tools or create_schema_files.
- */
- function table_add($table_name, $table_data = array())
- {
- global $dbms, $user;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- /**
- * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given.
- * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error
- */
- if (empty($table_data))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_ADD', $table_name);
-
- if ($this->table_exists($table_name))
- {
- return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name);
- }
-
- if (!is_array($table_data))
- {
- return $this->umil_end('NO_TABLE_DATA');
- }
-
- if (!function_exists('get_available_dbms'))
- {
- global $phpbb_root_path, $phpEx;
- include("{$phpbb_root_path}includes/functions_install.$phpEx");
- }
-
- /*
- * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore
- if (method_exists($this->db_tools, 'sql_create_table'))
- {
- // Added in 3.0.5
- $this->db_tools->sql_create_table($table_name, $table_data);
- }
- else
- {*/
- $available_dbms = get_available_dbms($dbms);
-
- $sql_query = $this->create_table_sql($table_name, $table_data);
- $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']);
-
- foreach ($sql_query as $sql)
- {
- $this->db->sql_query($sql);
- }
- //}
-
- return $this->umil_end();
- }
-
- /**
- * Table Remove
- *
- * Delete/Drop a DB table
- */
- function table_remove($table_name)
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_REMOVE', $table_name);
-
- if (!$this->table_exists($table_name))
- {
- return $this->umil_end('TABLE_NOT_EXIST', $table_name);
- }
-
- if (method_exists($this->db_tools, 'sql_table_drop'))
- {
- // Added in 3.0.5
- $this->db_tools->sql_table_drop($table_name);
- }
- else
- {
- $this->db->sql_query('DROP TABLE ' . $table_name);
- }
-
- return $this->umil_end();
- }
-
- /**
- * Table Column Exists
- *
- * Check to see if a column exists in a table
- */
- function table_column_exists($table_name, $column_name)
- {
- $this->get_table_name($table_name);
-
- return $this->db_tools->sql_column_exists($table_name, $column_name);
- }
-
- /**
- * Table Column Add
- *
- * Add a new column to a table.
- */
- function table_column_add($table_name, $column_name = '', $column_data = array())
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- /**
- * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given.
- * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error
- */
- if (empty($column_data))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name);
-
- if ($this->table_column_exists($table_name, $column_name))
- {
- return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name);
- }
-
- $this->db_tools->sql_column_add($table_name, $column_name, $column_data);
-
- return $this->umil_end();
- }
-
- /**
- * Table Column Update
- *
- * Alter/Update a column in a table. You can not change a column name with this.
- */
- function table_column_update($table_name, $column_name = '', $column_data = array())
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name);
-
- if (!$this->table_column_exists($table_name, $column_name))
- {
- return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name);
- }
-
- $this->db_tools->sql_column_change($table_name, $column_name, $column_data);
-
- return $this->umil_end();
- }
-
- /**
- * Table Column Remove
- *
- * Remove a column from a table
- */
- function table_column_remove($table_name, $column_name = '')
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name);
-
- if (!$this->table_column_exists($table_name, $column_name))
- {
- return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name);
- }
-
- $this->db_tools->sql_column_remove($table_name, $column_name);
-
- return $this->umil_end();
- }
-
- /**
- * Table Index Exists
- *
- * Check if a table key/index exists on a table (can not check primary or unique)
- */
- function table_index_exists($table_name, $index_name)
- {
- $this->get_table_name($table_name);
-
- $indexes = $this->db_tools->sql_list_index($table_name);
-
- if (in_array($index_name, $indexes))
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Table Index Add
- *
- * Add a new key/index to a table
- */
- function table_index_add($table_name, $index_name = '', $column = array())
- {
- global $config;
-
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- // Let them skip the column field and just use the index name in that case as the column as well
- if (empty($column))
- {
- $column = array($index_name);
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name);
-
- if ($this->table_index_exists($table_name, $index_name))
- {
- return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name);
- }
-
- if (!is_array($column))
- {
- $column = array($column);
- }
-
- // remove index length if we are before 3.0.8
- // the feature (required for some types when using MySQL4)
- // was added in that release (ticket PHPBB3-8944)
- if (version_compare($config['version'], '3.0.7-pl1', '<='))
- {
- $column = preg_replace('#:.*$#', '', $column);
- }
-
- $this->db_tools->sql_create_index($table_name, $index_name, $column);
-
- return $this->umil_end();
- }
-
- /**
- * Table Index Remove
- *
- * Remove a key/index from a table
- */
- function table_index_remove($table_name, $index_name = '')
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name);
-
- if (!$this->table_index_exists($table_name, $index_name))
- {
- return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name);
- }
-
- $this->db_tools->sql_index_drop($table_name, $index_name);
-
- return $this->umil_end();
- }
-
- // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility
- function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); }
-
- /**
- * Table Insert
- *
- * Insert data into a table
- */
- function table_row_insert($table_name, $data = array())
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name);
-
- if (!$this->table_exists($table_name))
- {
- return $this->umil_end('TABLE_NOT_EXIST', $table_name);
- }
-
- $this->db->sql_multi_insert($table_name, $data);
-
- return $this->umil_end();
- }
-
- /**
- * Table Row Update
- *
- * Update a row in a table
- *
- * $data should be an array with the column names as keys and values as the items to check for each column. Example:
- * array('user_id' => 123, 'user_name' => 'test user') would become:
- * WHERE user_id = 123 AND user_name = 'test user'
- *
- * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ).
- */
- function table_row_update($table_name, $data = array(), $new_data = array())
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- if (!sizeof($data))
- {
- return $this->umil_end('FAIL');
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name);
-
- if (!$this->table_exists($table_name))
- {
- return $this->umil_end('TABLE_NOT_EXIST', $table_name);
- }
-
- $sql = 'UPDATE ' . $table_name . '
- SET ' . $this->db->sql_build_array('UPDATE', $new_data) . '
- WHERE ' . $this->db->sql_build_array('SELECT', $data);
- $this->db->sql_query($sql);
-
- return $this->umil_end();
- }
-
- /**
- * Table Row Remove
- *
- * Remove a row from a table
- *
- * $data should be an array with the column names as keys and values as the items to check for each column. Example:
- * array('user_id' => 123, 'user_name' => 'test user') would become:
- * WHERE user_id = 123 AND user_name = 'test user'
- */
- function table_row_remove($table_name, $data = array())
- {
- // Multicall
- if ($this->multicall(__FUNCTION__, $table_name))
- {
- return;
- }
-
- if (!sizeof($data))
- {
- return $this->umil_end('FAIL');
- }
-
- $this->get_table_name($table_name);
-
- $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name);
-
- if (!$this->table_exists($table_name))
- {
- return $this->umil_end('TABLE_NOT_EXIST', $table_name);
- }
-
- $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data);
- $this->db->sql_query($sql);
-
- return $this->umil_end();
- }
-
- /**
- * Version Checker
- *
- * Format the file like the following:
- * http://www.phpbb.com/updatecheck/30x.txt
- *
- * @param string $url The url to access (ex: www.phpbb.com)
- * @param string $path The path to access (ex: /updatecheck)
- * @param string $file The name of the file to access (ex: 30x.txt)
- *
- * @return array|string Error Message if there was any error, or an array (each line in the file as a value)
- */
- function version_check($url, $path, $file, $timeout = 10, $port = 80)
- {
- if (!function_exists('get_remote_file'))
- {
- global $phpbb_root_path, $phpEx;
-
- include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
- }
-
- $errstr = $errno = '';
-
- $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout);
-
- if ($info === false)
- {
- return $errstr . ' [ ' . $errno . ' ]';
- }
-
- $info = str_replace("\r\n", "\n", $info);
- $info = explode("\n", $info);
-
- return $info;
- }
-
- /**
- * Create table SQL
- *
- * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array
- *
- * @param string $table_name The name of the table
- * @param array $table_data The table data (formatted in the array format used by create_schema_files)
- * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS)
- *
- * @return The sql query to run for the submitted dbms to insert the table
- */
- function create_table_sql($table_name, $table_data, $dbms = '')
- {
- // To allow testing
- $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer;
-
- // A list of types being unsigned for better reference in some db's
- $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP');
- $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite');
-
- $sql = '';
-
- // Create Table statement
- $generator = $textimage = false;
-
- switch ($dbms)
- {
- case 'mysql_40':
- case 'mysql_41':
- case 'firebird':
- case 'oracle':
- case 'sqlite':
- case 'postgres':
- $sql .= "CREATE TABLE {$table_name} (\n";
- break;
-
- case 'mssql':
- $sql .= "CREATE TABLE [{$table_name}] (\n";
- break;
- }
-
- // Table specific so we don't get overlap
- $modded_array = array();
-
- // Write columns one by one...
- foreach ($table_data['COLUMNS'] as $column_name => $column_data)
- {
- // Get type
- if (strpos($column_data[0], ':') !== false)
- {
- list($orig_column_type, $column_length) = explode(':', $column_data[0]);
- if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']))
- {
- $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length);
- }
- else
- {
- if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule']))
- {
- switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0])
- {
- case 'div':
- $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1];
- $column_length = ceil($column_length);
- $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length);
- break;
- }
- }
-
- if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit']))
- {
- switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0])
- {
- case 'mult':
- $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1];
- if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2])
- {
- $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3];
- $modded_array[$column_name] = $column_type;
- }
- else
- {
- $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length);
- }
- break;
- }
- }
- }
- $orig_column_type .= ':';
- }
- else
- {
- $orig_column_type = $column_data[0];
- $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]];
- if ($column_type == 'text' || $column_type == 'blob')
- {
- $modded_array[$column_name] = $column_type;
- }
- }
-
- // Adjust default value if db-dependant specified
- if (is_array($column_data[1]))
- {
- $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default'];
- }
-
- switch ($dbms)
- {
- case 'mysql_40':
- case 'mysql_41':
- $sql .= "\t{$column_name} {$column_type} ";
-
- // For hexadecimal values do not use single quotes
- if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob')
- {
- $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' ";
- }
- $sql .= 'NOT NULL';
-
- if (isset($column_data[2]))
- {
- if ($column_data[2] == 'auto_increment')
- {
- $sql .= ' auto_increment';
- }
- else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort')
- {
- $sql .= ' COLLATE utf8_unicode_ci';
- }
- }
-
- $sql .= ",\n";
- break;
-
- case 'sqlite':
- if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
- {
- $sql .= "\t{$column_name} INTEGER PRIMARY KEY ";
- $generator = $column_name;
- }
- else
- {
- $sql .= "\t{$column_name} {$column_type} ";
- }
-
- $sql .= 'NOT NULL ';
- $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : '';
- $sql .= ",\n";
- break;
-
- case 'firebird':
- $sql .= "\t{$column_name} {$column_type} ";
-
- if (!is_null($column_data[1]))
- {
- $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
- }
-
- $sql .= 'NOT NULL';
-
- // This is a UNICODE column and thus should be given it's fair share
- if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0]))
- {
- $sql .= ' COLLATE UNICODE';
- }
-
- $sql .= ",\n";
-
- if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
- {
- $generator = $column_name;
- }
- break;
-
- case 'mssql':
- if ($column_type == '[text]')
- {
- $textimage = true;
- }
-
- $sql .= "\t[{$column_name}] {$column_type} ";
-
- if (!is_null($column_data[1]))
- {
- // For hexadecimal values do not use single quotes
- if (strpos($column_data[1], '0x') === 0)
- {
- $sql .= 'DEFAULT (' . $column_data[1] . ') ';
- }
- else
- {
- $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') ';
- }
- }
-
- if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
- {
- $sql .= 'IDENTITY (1, 1) ';
- }
-
- $sql .= 'NOT NULL';
- $sql .= " ,\n";
- break;
-
- case 'oracle':
- $sql .= "\t{$column_name} {$column_type} ";
- $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : '';
-
- // In Oracle empty strings ('') are treated as NULL.
- // Therefore in oracle we allow NULL's for all DEFAULT '' entries
- $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n";
-
- if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
- {
- $generator = $column_name;
- }
- break;
-
- case 'postgres':
- $sql .= "\t{$column_name} {$column_type} ";
-
- if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
- {
- $sql .= "DEFAULT nextval('{$table_name}_seq'),\n";
-
- // Make sure the sequence will be created before creating the table
- $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql;
- }
- else
- {
- $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : '';
- $sql .= "NOT NULL";
-
- // Unsigned? Then add a CHECK contraint
- if (in_array($orig_column_type, $unsigned_types))
- {
- $sql .= " CHECK ({$column_name} >= 0)";
- }
-
- $sql .= ",\n";
- }
- break;
- }
- }
-
- switch ($dbms)
- {
- case 'firebird':
- // Remove last line delimiter...
- $sql = substr($sql, 0, -2);
- $sql .= "\n);;\n\n";
- break;
-
- case 'mssql':
- $sql = substr($sql, 0, -2);
- $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n";
- $sql .= "GO\n\n";
- break;
- }
-
- // Write primary key
- if (isset($table_data['PRIMARY_KEY']))
- {
- if (!is_array($table_data['PRIMARY_KEY']))
- {
- $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']);
- }
-
- switch ($dbms)
- {
- case 'mysql_40':
- case 'mysql_41':
- case 'postgres':
- $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n";
- break;
-
- case 'firebird':
- $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n";
- break;
-
- case 'sqlite':
- if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY']))
- {
- $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n";
- }
- break;
-
- case 'mssql':
- $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n";
- $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n";
- $sql .= "\t(\n";
- $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n";
- $sql .= "\t) ON [PRIMARY] \n";
- $sql .= "GO\n\n";
- break;
-
- case 'oracle':
- $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n";
- break;
- }
- }
-
- switch ($dbms)
- {
- case 'oracle':
- // UNIQUE contrains to be added?
- if (isset($table_data['KEYS']))
- {
- foreach ($table_data['KEYS'] as $key_name => $key_data)
- {
- if (!is_array($key_data[1]))
- {
- $key_data[1] = array($key_data[1]);
- }
-
- if ($key_data[0] == 'UNIQUE')
- {
- $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n";
- }
- }
- }
-
- // Remove last line delimiter...
- $sql = substr($sql, 0, -2);
- $sql .= "\n)\n/\n\n";
- break;
-
- case 'postgres':
- // Remove last line delimiter...
- $sql = substr($sql, 0, -2);
- $sql .= "\n);\n\n";
- break;
-
- case 'sqlite':
- // Remove last line delimiter...
- $sql = substr($sql, 0, -2);
- $sql .= "\n);\n\n";
- break;
- }
-
- // Write Keys
- if (isset($table_data['KEYS']))
- {
- foreach ($table_data['KEYS'] as $key_name => $key_data)
- {
- if (!is_array($key_data[1]))
- {
- $key_data[1] = array($key_data[1]);
- }
-
- switch ($dbms)
- {
- case 'mysql_40':
- case 'mysql_41':
- $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : '';
- $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : '';
- foreach ($key_data[1] as $key => $col_name)
- {
- if (isset($modded_array[$col_name]))
- {
- switch ($modded_array[$col_name])
- {
- case 'text':
- case 'blob':
- $key_data[1][$key] = $col_name . '(255)';
- break;
- }
- }
- }
- $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n";
- break;
-
- case 'firebird':
- $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : '';
- $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : '';
-
- $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n";
- break;
-
- case 'mssql':
- $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : '';
- $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : '';
- $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n";
- $sql .= "GO\n\n";
- break;
-
- case 'oracle':
- if ($key_data[0] == 'UNIQUE')
- {
- continue;
- }
-
- $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : '';
-
- $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n";
- $sql .= "/\n";
- break;
-
- case 'sqlite':
- $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : '';
- $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : '';
-
- $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n";
- break;
-
- case 'postgres':
- $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : '';
- $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : '';
-
- $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n";
- break;
- }
- }
- }
-
- switch ($dbms)
- {
- case 'mysql_40':
- // Remove last line delimiter...
- $sql = substr($sql, 0, -2);
- $sql .= "\n);\n\n";
- break;
-
- case 'mysql_41':
- // Remove last line delimiter...
- $sql = substr($sql, 0, -2);
- $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n";
- break;
-
- // Create Generator
- case 'firebird':
- if ($generator !== false)
- {
- $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n";
- $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n";
-
- $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n";
- $sql .= "BEFORE INSERT\nAS\nBEGIN\n";
- $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n";
- }
- break;
-
- case 'oracle':
- if ($generator !== false)
- {
- $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n";
-
- $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n";
- $sql .= "BEFORE INSERT ON {$table_name}\n";
- $sql .= "FOR EACH ROW WHEN (\n";
- $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n";
- $sql .= ")\nBEGIN\n";
- $sql .= "\tSELECT {$table_name}_seq.nextval\n";
- $sql .= "\tINTO :new.{$generator}\n";
- $sql .= "\tFROM dual;\nEND;\n/\n\n";
- }
- break;
- }
-
- return $sql;
- }
-
- /**
- * Get the real table name
- * By A_Jelly_Doughnut
- *
- * @param string $table_name The table name to get the real table name from
- */
- function get_table_name(&$table_name)
- {
- // Use the global table prefix if a custom one is not specified
- if ($this->table_prefix === false)
- {
- global $table_prefix;
- }
- else
- {
- $table_prefix = $this->table_prefix;
- }
-
- static $constants = NULL;
-
- if (is_null($constants))
- {
- $constants = get_defined_constants();
- }
-
- /**
- * only do the replace if the table prefix is not already present
- * this is required since UMIL supports specifying a table via phpbb_foo
- * (where a replace would be needed)
- * or by FOO_TABLE (where a replace is already done at constant-define time)
- */
- if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true))
- {
- $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name);
- }
- }
-}
-
-?> \ No newline at end of file
diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php
index 216faf9866..2fd795b659 100644
--- a/phpBB/includes/db/migrator.php
+++ b/phpBB/includes/db/migrator.php
@@ -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->phpbb_root_path = $this->container->getParameters('core.root_path');
- $this->php_ext = $this->container->getParameters('core.php_ext');
-
- /** @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->config = $config;
+ $this->db = $db;
+ $this->db_tools = $db_tools;
+
+ $this->migrations_table = $migrations_table;
+
+ $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();
}
@@ -94,12 +94,43 @@ class phpbb_db_migrator
}
/**
+ * 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);
+ }
}
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index d0ef2759d5..057bdba0e3 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -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;
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 207ad716de..8950d677ae 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -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;
diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql
index 43099fc33b..535cbb0df4 100644
--- a/phpBB/install/schemas/firebird_schema.sql
+++ b/phpBB/install/schemas/firebird_schema.sql
@@ -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);;
diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql
index 1174cdfa3d..43b8f3e556 100644
--- a/phpBB/install/schemas/mssql_schema.sql
+++ b/phpBB/install/schemas/mssql_schema.sql
@@ -697,23 +697,6 @@ 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'
*/
CREATE TABLE [phpbb_moderator_cache] (
@@ -734,6 +717,27 @@ 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'
*/
CREATE 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
diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql
index d645c3384d..c46230744a 100644
--- a/phpBB/install/schemas/mysql_40_schema.sql
+++ b/phpBB/install/schemas/mysql_40_schema.sql
@@ -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)
diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql
index d10f2dc55a..fa94598e9c 100644
--- a/phpBB/install/schemas/mysql_41_schema.sql
+++ b/phpBB/install/schemas/mysql_41_schema.sql
@@ -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)
diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql
index 9993caeb7a..f8a9d5e1a6 100644
--- a/phpBB/install/schemas/oracle_schema.sql
+++ b/phpBB/install/schemas/oracle_schema.sql
@@ -781,21 +781,6 @@ 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'
*/
CREATE TABLE phpbb_moderator_cache (
@@ -814,6 +799,21 @@ 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'
*/
CREATE 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)
)
/
diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql
index ef138dac0f..c976659f05 100644
--- a/phpBB/install/schemas/postgres_schema.sql
+++ b/phpBB/install/schemas/postgres_schema.sql
@@ -558,20 +558,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 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'
*/
CREATE TABLE phpbb_moderator_cache (
@@ -587,6 +573,20 @@ 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 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'
*/
CREATE SEQUENCE phpbb_modules_seq;
@@ -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)
);
diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql
index 309297779e..31a6f715a0 100644
--- a/phpBB/install/schemas/sqlite_schema.sql
+++ b/phpBB/install/schemas/sqlite_schema.sql
@@ -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);
diff --git a/phpBB/test.php b/phpBB/test.php
new file mode 100644
index 0000000000..5887c08d2f
--- /dev/null
+++ b/phpBB/test.php
@@ -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';
diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml
new file mode 100644
index 0000000000..32afe7e6f3
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_module.xml
@@ -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>
diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml
new file mode 100644
index 0000000000..08cec42a42
--- /dev/null
+++ b/tests/dbal/fixtures/migrator_permission.xml
@@ -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>
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 898a197dfd..463cf9fcec 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -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()
diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php
new file mode 100644
index 0000000000..27511519ca
--- /dev/null
+++ b/tests/dbal/migrator_tool_config_test.php
@@ -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']));
+ }
+}
diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php
new file mode 100644
index 0000000000..0b57cbfbcb
--- /dev/null
+++ b/tests/dbal/migrator_tool_module.php
@@ -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'));
+ }
+}
diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php
new file mode 100644
index 0000000000..2229576cd9
--- /dev/null
+++ b/tests/dbal/migrator_tool_permission.php
@@ -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) {}
+ }
+}