mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-29 06:38:52 +00:00
[feature/migrations] Update 3.0.3-3.0.5 migrations to work
This commit is contained in:
parent
167faed163
commit
b52a0f50ab
5 changed files with 107 additions and 160 deletions
34
phpBB/includes/db/migration/305rc1part2.php
Normal file
34
phpBB/includes/db/migration/305rc1part2.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package migration
|
||||||
|
* @copyright (c) 2012 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_db_migration_v305rc1part2 extends phpbb_db_migration
|
||||||
|
{
|
||||||
|
function depends_on()
|
||||||
|
{
|
||||||
|
return array('phpbb_db_migration_v305rc1');
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'drop_keys' => array(
|
||||||
|
ACL_OPTIONS_TABLE => array('auth_option'),
|
||||||
|
),
|
||||||
|
'add_unique_index' => array(
|
||||||
|
ACL_OPTIONS_TABLE => array(
|
||||||
|
'auth_option' => array('auth_option'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_data()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,93 +35,20 @@ class phpbb_db_migration_v303rc1 extends phpbb_db_migration
|
||||||
array('config.add', array('enable_queue_trigger', '0')),
|
array('config.add', array('enable_queue_trigger', '0')),
|
||||||
array('config.add', array('queue_trigger_posts', '3')),
|
array('config.add', array('queue_trigger_posts', '3')),
|
||||||
array('config.add', array('pm_max_recipients', '0')),
|
array('config.add', array('pm_max_recipients', '0')),
|
||||||
array('custom', array('set_group_default_max_recipients'))
|
array('custom', array(array(&$this, 'set_group_default_max_recipients'))),
|
||||||
|
array('config.add', array('dbms_version', '')),
|
||||||
// Not prefilling yet
|
array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL),
|
||||||
set_config('dbms_version', '');
|
array('custom', array(array(&$this, 'correct_acp_email_permissions'))),
|
||||||
|
));
|
||||||
// Add new permission u_masspm_group and duplicate settings from u_masspm
|
|
||||||
include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
|
|
||||||
$auth_admin = new auth_admin();
|
|
||||||
|
|
||||||
// Only add the new permission if it does not already exist
|
|
||||||
if (empty($auth_admin->acl_options['id']['u_masspm_group']))
|
|
||||||
{
|
|
||||||
$auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
|
|
||||||
|
|
||||||
// Now the tricky part, filling the permission
|
|
||||||
$old_id = $auth_admin->acl_options['id']['u_masspm'];
|
|
||||||
$new_id = $auth_admin->acl_options['id']['u_masspm_group'];
|
|
||||||
|
|
||||||
$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 = _sql($sql, $errored, $error_ary);
|
|
||||||
|
|
||||||
$sql_ary = array();
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$row['auth_option_id'] = $new_id;
|
|
||||||
$sql_ary[] = $row;
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
|
|
||||||
if (sizeof($sql_ary))
|
|
||||||
{
|
|
||||||
$db->sql_multi_insert($table, $sql_ary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any old permission entries
|
function correct_acp_email_permissions()
|
||||||
$auth_admin->acl_clear_prefetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Do not resync post counts here. An admin may do this later from the ACP
|
|
||||||
$start = 0;
|
|
||||||
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
|
|
||||||
|
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
|
|
||||||
_sql($sql, $errored, $error_ary);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
|
$sql = 'UPDATE ' . $this->table_prefix . 'modules
|
||||||
FROM ' . POSTS_TABLE . '
|
|
||||||
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
|
|
||||||
AND post_postcount = 1 AND post_approved = 1
|
|
||||||
GROUP BY poster_id';
|
|
||||||
$result = _sql($sql, $errored, $error_ary);
|
|
||||||
|
|
||||||
if ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
|
|
||||||
_sql($sql, $errored, $error_ary);
|
|
||||||
}
|
|
||||||
while ($row = $db->sql_fetchrow($result));
|
|
||||||
|
|
||||||
$start += $step;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$start = 0;
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
}
|
|
||||||
while ($start);
|
|
||||||
*/
|
|
||||||
|
|
||||||
$sql = 'UPDATE ' . MODULES_TABLE . '
|
|
||||||
SET module_auth = \'acl_a_email && cfg_email_enable\'
|
SET module_auth = \'acl_a_email && cfg_email_enable\'
|
||||||
WHERE module_class = \'acp\'
|
WHERE module_class = \'acp\'
|
||||||
AND module_basename = \'email\'';
|
AND module_basename = \'email\'';
|
||||||
_sql($sql, $errored, $error_ary);
|
$this->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_group_default_max_recipients()
|
function set_group_default_max_recipients()
|
||||||
|
@ -131,5 +58,4 @@ class phpbb_db_migration_v303rc1 extends phpbb_db_migration
|
||||||
WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
|
WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
|
||||||
$this->sql_query($sql);
|
$this->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,21 +20,28 @@ class phpbb_db_migration_v304 extends phpbb_db_migration
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_data()
|
function update_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('custom', array(array(&$this, 'rename_log_delete_topic'))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rename_log_delete_topic()
|
||||||
{
|
{
|
||||||
if ($db->sql_layer == 'oracle')
|
if ($db->sql_layer == 'oracle')
|
||||||
{
|
{
|
||||||
// log_operation is CLOB - but we can change this later
|
// log_operation is CLOB - but we can change this later
|
||||||
$sql = 'UPDATE ' . LOG_TABLE . "
|
$sql = 'UPDATE ' . $this->table_prefix . "log
|
||||||
SET log_operation = 'LOG_DELETE_TOPIC'
|
SET log_operation = 'LOG_DELETE_TOPIC'
|
||||||
WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
|
WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
|
||||||
_sql($sql, $errored, $error_ary);
|
$this->sql_query($sql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . LOG_TABLE . "
|
$sql = 'UPDATE ' . $this->table_prefix . "log
|
||||||
SET log_operation = 'LOG_DELETE_TOPIC'
|
SET log_operation = 'LOG_DELETE_TOPIC'
|
||||||
WHERE log_operation = 'LOG_TOPIC_DELETED'";
|
WHERE log_operation = 'LOG_TOPIC_DELETED'";
|
||||||
_sql($sql, $errored, $error_ary);
|
$this->sql_query($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,13 +56,20 @@ class phpbb_db_migration_v304rc1 extends phpbb_db_migration
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_data()
|
function update_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('custom', array(array(&$this, 'update_custom_profile_fields'))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_custom_profile_fields()
|
||||||
{
|
{
|
||||||
// Update the Custom Profile Fields based on previous settings to the new format
|
// 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
|
$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
|
||||||
FROM ' . PROFILE_FIELDS_TABLE;
|
FROM ' . PROFILE_FIELDS_TABLE;
|
||||||
$result = _sql($sql, $errored, $error_ary);
|
$result = $this->sql_query($sql);
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$sql_ary = array(
|
$sql_ary = array(
|
||||||
'field_required' => 0,
|
'field_required' => 0,
|
||||||
|
@ -90,7 +97,7 @@ class phpbb_db_migration_v304rc1 extends phpbb_db_migration
|
||||||
$sql_ary['field_show_profile'] = 1;
|
$sql_ary['field_show_profile'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,28 +27,29 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration
|
||||||
|
|
||||||
function update_data()
|
function update_data()
|
||||||
{
|
{
|
||||||
// Captcha config variables
|
$search_indexing_state = $this->config['search_indexing_state'];
|
||||||
set_config('captcha_gd_wave', 0);
|
|
||||||
set_config('captcha_gd_3d_noise', 1);
|
|
||||||
set_config('captcha_gd_fonts', 1);
|
|
||||||
set_config('confirm_refresh', 1);
|
|
||||||
|
|
||||||
// Maximum number of keywords
|
return array(
|
||||||
set_config('max_num_search_keywords', 10);
|
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('confirm_refresh', 1)),
|
||||||
|
array('config.add', array('max_num_search_keywords', 10)),
|
||||||
|
array('config.remove', array('search_indexing_state')),
|
||||||
|
array('config.add', array('search_indexing_state', $search_indexing_state, true)),
|
||||||
|
array('custom', array(array(&$this, 'hash_old_passwords'))),
|
||||||
|
array('custom', array(array(&$this, 'update_ichiro_bot'))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove static config var and put it back as dynamic variable
|
function hash_old_passwords()
|
||||||
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
{
|
||||||
SET is_dynamic = 1
|
|
||||||
WHERE config_name = 'search_indexing_state'";
|
|
||||||
_sql($sql, $errored, $error_ary);
|
|
||||||
|
|
||||||
// Hash old MD5 passwords
|
|
||||||
$sql = 'SELECT user_id, user_password
|
$sql = 'SELECT user_id, user_password
|
||||||
FROM ' . USERS_TABLE . '
|
FROM ' . $this->table_prefix . 'users
|
||||||
WHERE user_pass_convert = 1';
|
WHERE user_pass_convert = 1';
|
||||||
$result = _sql($sql, $errored, $error_ary);
|
$result = $this->sql_query($sql);
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
if (strlen($row['user_password']) == 32)
|
if (strlen($row['user_password']) == 32)
|
||||||
{
|
{
|
||||||
|
@ -56,33 +57,36 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration
|
||||||
'user_password' => phpbb_hash($row['user_password']),
|
'user_password' => phpbb_hash($row['user_password']),
|
||||||
);
|
);
|
||||||
|
|
||||||
_sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary);
|
$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);
|
$db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_ichiro_bot()
|
||||||
|
{
|
||||||
// Adjust bot entry
|
// Adjust bot entry
|
||||||
$sql = 'UPDATE ' . BOTS_TABLE . "
|
$sql = 'UPDATE ' . $this->table_prefix . "bots
|
||||||
SET bot_agent = 'ichiro/'
|
SET bot_agent = 'ichiro/'
|
||||||
WHERE bot_agent = 'ichiro/2'";
|
WHERE bot_agent = 'ichiro/2'";
|
||||||
_sql($sql, $errored, $error_ary);
|
$this->sql_query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_duplicate_auth_options()
|
||||||
|
{
|
||||||
// Before we are able to add a unique key to auth_option, we need to remove duplicate entries
|
// Before we are able to add a unique key to auth_option, we need to remove duplicate entries
|
||||||
|
|
||||||
// We get duplicate entries first
|
|
||||||
$sql = 'SELECT auth_option
|
$sql = 'SELECT auth_option
|
||||||
FROM ' . ACL_OPTIONS_TABLE . '
|
FROM ' . $this->table_prefix . 'acl_options
|
||||||
GROUP BY auth_option
|
GROUP BY auth_option
|
||||||
HAVING COUNT(*) >= 2';
|
HAVING COUNT(*) >= 2';
|
||||||
$result = $db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
|
|
||||||
$auth_options = array();
|
$auth_options = array();
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$auth_options[] = $row['auth_option'];
|
$auth_options[] = $row['auth_option'];
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
// Remove specific auth options
|
// Remove specific auth options
|
||||||
if (!empty($auth_options))
|
if (!empty($auth_options))
|
||||||
|
@ -95,52 +99,21 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration
|
||||||
WHERE auth_option = '" . $db->sql_escape($option) . "'
|
WHERE auth_option = '" . $db->sql_escape($option) . "'
|
||||||
ORDER BY auth_option_id DESC";
|
ORDER BY auth_option_id DESC";
|
||||||
// sql_query_limit not possible here, due to bug in postgresql layer
|
// sql_query_limit not possible here, due to bug in postgresql layer
|
||||||
$result = $db->sql_query($sql);
|
$result = $this->sql_query($sql);
|
||||||
|
|
||||||
// Skip first row, this is our original auth option we want to preserve
|
// Skip first row, this is our original auth option we want to preserve
|
||||||
$row = $db->sql_fetchrow($result);
|
$row = $this->db->sql_fetchrow($result);
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
// Ok, remove this auth option...
|
// Ok, remove this auth option...
|
||||||
_sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
|
$this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
|
||||||
_sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
|
$this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
|
||||||
_sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
|
$this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
|
||||||
_sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
|
$this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']);
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$this->db->sql_freeresult($result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one.
|
|
||||||
$changes = array(
|
|
||||||
'drop_keys' => array(
|
|
||||||
ACL_OPTIONS_TABLE => array('auth_option'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
global $db_tools;
|
|
||||||
|
|
||||||
$statements = $db_tools->perform_schema_changes($changes);
|
|
||||||
|
|
||||||
foreach ($statements as $sql)
|
|
||||||
{
|
|
||||||
_sql($sql, $errored, $error_ary);
|
|
||||||
}
|
|
||||||
|
|
||||||
$changes = array(
|
|
||||||
'add_unique_index' => array(
|
|
||||||
ACL_OPTIONS_TABLE => array(
|
|
||||||
'auth_option' => array('auth_option'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$statements = $db_tools->perform_schema_changes($changes);
|
|
||||||
|
|
||||||
foreach ($statements as $sql)
|
|
||||||
{
|
|
||||||
_sql($sql, $errored, $error_ary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue