1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-02 12:34:59 +02:00

[feature/migrations] Migrations back through 3.0.6

PHPBB3-9737
This commit is contained in:
Nathaniel Guse 2012-11-10 05:59:01 -06:00 committed by Nathan Guse
parent e7389e4c32
commit 2a7985c26f
5 changed files with 197 additions and 204 deletions

View File

@ -61,109 +61,141 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration
function update_data()
{
// Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled...
if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin']))
{
set_config('captcha_plugin', 'phpbb_captcha_gd');
}
else if (!isset($config['captcha_plugin']))
{
set_config('captcha_plugin', 'phpbb_captcha_nogd');
}
return array(
//array('custom', array(array(&$this, '')))
array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')),
array('config.update_if', array(
($this->config['captcha_gd']),
'captcha_plugin',
'phpbb_captcha_gd',
)),
// Entries for the Feed Feature
set_config('feed_enable', '0');
set_config('feed_limit', '10');
array('config.add', array('feed_enable', 0)),
array('config.add', array('feed_limit', 10)),
array('config.add', array('feed_overall_forums', 1)),
array('config.add', array('feed_overall_forums_limit', 15)),
array('config.add', array('feed_overall_topics', 0)),
array('config.add', array('feed_overall_topics_limit', 15)),
array('config.add', array('feed_forum', 1)),
array('config.add', array('feed_topic', 1)),
array('config.add', array('feed_item_statistics', 1)),
set_config('feed_overall_forums', '1');
set_config('feed_overall_forums_limit', '15');
array('config.add', array('smilies_per_page', 50)),
array('config.add', array('allow_pm_report', 1)),
array('config.add', array('min_post_chars', 1)),
array('config.add', array('allow_quick_reply', 1)),
array('config.add', array('new_member_post_limit', 0)),
array('config.add', array('new_member_group_default', 0)),
array('config.add', array('delete_time', $this->config['edit_time'])),
set_config('feed_overall_topics', '0');
set_config('feed_overall_topics_limit', '15');
array('config.add', array('allow_avatar', 0)),
array('config.add_if', array(
($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']),
'allow_avatar',
1,
)),
array('config.add', array('allow_avatar_remote_upload', 0)),
array('config.add_if', array(
($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']),
'allow_avatar_remote_upload',
1,
)),
set_config('feed_forum', '1');
set_config('feed_topic', '1');
set_config('feed_item_statistics', '1');
// Entries for smiley pagination
set_config('smilies_per_page', '50');
// Entry for reporting PMs
set_config('allow_pm_report', '1');
// Install modules
$modules_to_install = array(
'feed' => array(
'base' => 'board',
'class' => 'acp',
'title' => 'ACP_FEED_SETTINGS',
'auth' => 'acl_a_board',
'cat' => 'ACP_BOARD_CONFIGURATION',
'after' => array('signature', 'ACP_SIGNATURE_SETTINGS')
),
'warnings' => array(
'base' => 'users',
'class' => 'acp',
'title' => 'ACP_USER_WARNINGS',
'auth' => 'acl_a_user',
'display' => 0,
'cat' => 'ACP_CAT_USERS',
'after' => array('feedback', 'ACP_USER_FEEDBACK')
),
'send_statistics' => array(
'base' => 'send_statistics',
'class' => 'acp',
'title' => 'ACP_SEND_STATISTICS',
'auth' => 'acl_a_server',
'cat' => 'ACP_SERVER_CONFIGURATION'
),
'setting_forum_copy' => array(
'base' => 'permissions',
'class' => 'acp',
'title' => 'ACP_FORUM_PERMISSIONS_COPY',
'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
'cat' => 'ACP_FORUM_BASED_PERMISSIONS',
'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')
),
'pm_reports' => array(
'base' => 'pm_reports',
'class' => 'mcp',
'title' => 'MCP_PM_REPORTS_OPEN',
'auth' => 'aclf_m_report',
'cat' => 'MCP_REPORTS'
),
'pm_reports_closed' => array(
'base' => 'pm_reports',
'class' => 'mcp',
'title' => 'MCP_PM_REPORTS_CLOSED',
'auth' => 'aclf_m_report',
'cat' => 'MCP_REPORTS'
),
'pm_report_details' => array(
'base' => 'pm_reports',
'class' => 'mcp',
'title' => 'MCP_PM_REPORT_DETAILS',
'auth' => 'aclf_m_report',
'cat' => 'MCP_REPORTS'
),
array('module.add', array(
'feed' => array(
'base' => 'board',
'class' => 'acp',
'title' => 'ACP_FEED_SETTINGS',
'auth' => 'acl_a_board',
'cat' => 'ACP_BOARD_CONFIGURATION',
'after' => array('signature', 'ACP_SIGNATURE_SETTINGS')
),
)),
array('module.add', array(
'warnings' => array(
'base' => 'users',
'class' => 'acp',
'title' => 'ACP_USER_WARNINGS',
'auth' => 'acl_a_user',
'display' => 0,
'cat' => 'ACP_CAT_USERS',
'after' => array('feedback', 'ACP_USER_FEEDBACK')
),
)),
array('module.add', array(
'send_statistics' => array(
'base' => 'send_statistics',
'class' => 'acp',
'title' => 'ACP_SEND_STATISTICS',
'auth' => 'acl_a_server',
'cat' => 'ACP_SERVER_CONFIGURATION'
),
)),
array('module.add', array(
'setting_forum_copy' => array(
'base' => 'permissions',
'class' => 'acp',
'title' => 'ACP_FORUM_PERMISSIONS_COPY',
'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
'cat' => 'ACP_FORUM_BASED_PERMISSIONS',
'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')
),
)),
array('module.add', array(
'pm_reports' => array(
'base' => 'pm_reports',
'class' => 'mcp',
'title' => 'MCP_PM_REPORTS_OPEN',
'auth' => 'aclf_m_report',
'cat' => 'MCP_REPORTS'
),
)),
array('module.add', array(
'pm_reports_closed' => array(
'base' => 'pm_reports',
'class' => 'mcp',
'title' => 'MCP_PM_REPORTS_CLOSED',
'auth' => 'aclf_m_report',
'cat' => 'MCP_REPORTS'
),
)),
array('module.add', array(
'pm_report_details' => array(
'base' => 'pm_reports',
'class' => 'mcp',
'title' => 'MCP_PM_REPORT_DETAILS',
'auth' => 'aclf_m_report',
'cat' => 'MCP_REPORTS'
),
)),
array('custom', array(array(&$this, 'add_newly_registered_group'))),
array('custom', array(array(&$this, 'set_user_options_default'))),
);
}
_add_modules($modules_to_install);
function set_user_options_default()
{
// 229376 is the added value to enable all three signature options
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
$this->sql_query($sql);
}
function add_newly_registered_group()
{
// Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = 'NEWLY_REGISTERED'";
$result = $db->sql_query($sql);
$group_id = (int) $db->sql_fetchfield('group_id');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$group_id = (int) $this->db->sql_fetchfield('group_id');
$this->db->sql_freeresult($result);
if (!$group_id)
{
$sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)";
_sql($sql, $errored, $error_ary);
$this->sql_query($sql);
$group_id = $db->sql_nextid();
$group_id = $this->db->sql_nextid();
}
// Insert new user role... at the end of the chain
@ -171,35 +203,35 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = 'ROLE_USER_NEW_MEMBER'
AND role_type = 'u_'";
$result = $db->sql_query($sql);
$u_role = (int) $db->sql_fetchfield('role_id');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$u_role = (int) $this->db->sql_fetchfield('role_id');
$this->db->sql_freeresult($result);
if (!$u_role)
{
$sql = 'SELECT MAX(role_order) as max_order_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_type = 'u_'";
$result = $db->sql_query($sql);
$next_order_id = (int) $db->sql_fetchfield('max_order_id');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$next_order_id = (int) $this->db->sql_fetchfield('max_order_id');
$this->db->sql_freeresult($result);
$next_order_id++;
$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)";
_sql($sql, $errored, $error_ary);
$u_role = $db->sql_nextid();
$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')";
_sql($sql, $errored, $error_ary);
$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)";
_sql($sql, $errored, $error_ary);
$this->sql_query($sql);
}
}
@ -208,29 +240,29 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = 'ROLE_FORUM_NEW_MEMBER'
AND role_type = 'f_'";
$result = $db->sql_query($sql);
$f_role = (int) $db->sql_fetchfield('role_id');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$f_role = (int) $this->db->sql_fetchfield('role_id');
$this->db->sql_freeresult($result);
if (!$f_role)
{
$sql = 'SELECT MAX(role_order) as max_order_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_type = 'f_'";
$result = $db->sql_query($sql);
$next_order_id = (int) $db->sql_fetchfield('max_order_id');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$next_order_id = (int) $this->db->sql_fetchfield('max_order_id');
$this->db->sql_freeresult($result);
$next_order_id++;
$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)";
_sql($sql, $errored, $error_ary);
$f_role = $db->sql_nextid();
$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')";
_sql($sql, $errored, $error_ary);
$this->sql_query($sql);
}
}
@ -238,25 +270,14 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration
$sql = 'SELECT 1
FROM ' . USERS_TABLE . '
WHERE user_new = 0';
$result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row)
{
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
_sql($sql, $errored, $error_ary);
}
// Newly registered users limit
if (!isset($config['new_member_post_limit']))
{
set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0);
}
if (!isset($config['new_member_group_default']))
{
set_config('new_member_group_default', 0);
$this->sql_query($sql);
}
// To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts...
@ -265,9 +286,9 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration
FROM ' . ACL_GROUPS_TABLE . '
WHERE group_id = ' . $group_id . '
AND auth_role_id = ' . $f_role;
$result = $db->sql_query($sql);
$is_options = (int) $db->sql_fetchfield('forum_id');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$is_options = (int) $this->db->sql_fetchfield('forum_id');
$this->db->sql_freeresult($result);
// Not assigned at all... :/
if (!$is_options)
@ -276,75 +297,18 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE forum_type != ' . FORUM_LINK;
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
_sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary);
$this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)');
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
}
// Clear permissions...
include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx);
$auth_admin = new auth_admin();
$auth_admin->acl_clear_prefetch();
if (!isset($config['allow_avatar']))
{
if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote'])
{
set_config('allow_avatar', '1');
}
else
{
set_config('allow_avatar', '0');
}
}
if (!isset($config['allow_avatar_remote_upload']))
{
if ($config['allow_avatar_remote'] && $config['allow_avatar_upload'])
{
set_config('allow_avatar_remote_upload', '1');
}
else
{
set_config('allow_avatar_remote_upload', '0');
}
}
// Minimum number of characters
if (!isset($config['min_post_chars']))
{
set_config('min_post_chars', '1');
}
if (!isset($config['allow_quick_reply']))
{
set_config('allow_quick_reply', '1');
}
// Set every members user_options column to enable
// bbcode, smilies and URLs for signatures by default
$sql = 'SELECT user_options
FROM ' . USERS_TABLE . '
WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
$result = $db->sql_query_limit($sql, 1);
$user_option = (int) $db->sql_fetchfield('user_options');
$db->sql_freeresult($result);
// Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option
if (!($user_option & 1 << 15))
{
// 229376 is the added value to enable all three signature options
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
_sql($sql, $errored, $error_ary);
}
if (!isset($config['delete_time']))
{
set_config('delete_time', $config['edit_time']);
}
}
}

View File

@ -20,12 +20,19 @@ class phpbb_db_migration_v306rc3 extends phpbb_db_migration
}
function update_data()
{
return array(
array('custom', array(array(&$this, 'update_cp_fields'))),
);
}
function update_cp_fields()
{
// Update the Custom Profile Fields based on previous settings to the new format
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
SET field_show_on_vt = 1
WHERE field_hide = 0
AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
_sql($sql, $errored, $error_ary);
$this->sql_query($sql);
}
}

View File

@ -30,17 +30,22 @@ class phpbb_db_migration_v307rc1 extends phpbb_db_migration
function update_data()
{
// ATOM Feeds
set_config('feed_overall', '1');
set_config('feed_http_auth', '0');
set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15));
set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10));
set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0'));
set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0'));
return array(
array('config.add', array('feed_overall', 1)),
array('config.add', array('feed_http_auth', 0)),
array('config.add', array('feed_limit_post', $this->config['feed_limit'])),
array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])),
array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])),
array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])),
array('custom', array(array(&$this, 'delete_text_templates'))),
);
}
function delete_text_templates()
{
// Delete all text-templates from the template_data
$sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt');
_sql($sql, $errored, $error_ary);
WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt');
$this->sql_query($sql);
}
}

View File

@ -21,15 +21,26 @@ class phpbb_db_migration_v307rc2 extends phpbb_db_migration
function update_data()
{
return array(
array('custom', array(array(&$this, 'update_email_hash'))),
);
}
function update_email_hash($start = 0)
{
$limit = 1000;
$sql = 'SELECT user_id, user_email, user_email_hash
FROM ' . USERS_TABLE . '
WHERE user_type <> ' . USER_IGNORE . "
AND user_email <> ''";
$result = $db->sql_query($sql);
$result = $this->db->sql_query_limit($sql, $limit, $start);
$i = 0;
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$i++;
// Snapshot of the phpbb_email_hash() function
// We cannot call it directly because the auto updater updates the DB first. :/
$user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']);
@ -41,13 +52,19 @@ class phpbb_db_migration_v307rc2 extends phpbb_db_migration
);
$sql = 'UPDATE ' . USERS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $row['user_id'];
_sql($sql, $errored, $error_ary, ($i % 100 == 0));
++$i;
$this->sql_query($sql);
}
}
$db->sql_freeresult($result);
if ($i < $limit)
{
// Completed
return false;
}
return $start + $limit;
}
}

View File

@ -37,8 +37,8 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration
),
)),
array('config.add', array('load_unreads_search', 1)),
array('config.update_if', array(600, 'queue_interval', 60)),
array('config.update_if', array(50, 'email_package_size', 20)),
array('config.update_if_equals', array(600, 'queue_interval', 60)),
array('config.update_if_equals', array(50, 'email_package_size', 20)),
);
}