mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
Merge PR #760 branch 'naderman/ticket/10759' into develop
* naderman/ticket/10759: [ticket/10759] Make sure style ids are integers [ticket/10759] Don't select imageset_id, it's not needed [ticket/10759] Clarify comments a bit [ticket/10759] Retrieve style_id after INSERT since we cannot set it [ticket/10759] Fix whitespace in database_update.php [ticket/10759] Fixing style in database updater
This commit is contained in:
commit
d4b89a13b1
1 changed files with 135 additions and 29 deletions
|
@ -1110,20 +1110,6 @@ function database_update_info()
|
||||||
'group_legend' => array('UINT', 0),
|
'group_legend' => array('UINT', 0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'drop_columns' => array(
|
|
||||||
STYLES_TABLE => array(
|
|
||||||
'imageset_id',
|
|
||||||
'template_id',
|
|
||||||
'theme_id',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'drop_tables' => array(
|
|
||||||
STYLES_IMAGESET_TABLE,
|
|
||||||
STYLES_IMAGESET_DATA_TABLE,
|
|
||||||
STYLES_TEMPLATE_TABLE,
|
|
||||||
STYLES_TEMPLATE_DATA_TABLE,
|
|
||||||
STYLES_THEME_TABLE,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1135,7 +1121,7 @@ function database_update_info()
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
function change_database_data(&$no_updates, $version)
|
function change_database_data(&$no_updates, $version)
|
||||||
{
|
{
|
||||||
global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
|
global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx, $db_tools;
|
||||||
|
|
||||||
switch ($version)
|
switch ($version)
|
||||||
{
|
{
|
||||||
|
@ -2312,13 +2298,6 @@ function change_database_data(&$no_updates, $version)
|
||||||
'auth' => 'acl_a_styles',
|
'auth' => 'acl_a_styles',
|
||||||
'cat' => 'ACP_STYLE_MANAGEMENT',
|
'cat' => 'ACP_STYLE_MANAGEMENT',
|
||||||
),
|
),
|
||||||
'edit' => array(
|
|
||||||
'base' => 'acp_styles',
|
|
||||||
'class' => 'acp',
|
|
||||||
'title' => 'ACP_STYLES_EDIT',
|
|
||||||
'auth' => 'acl_a_styles',
|
|
||||||
'cat' => 'ACP_STYLE_MANAGEMENT',
|
|
||||||
),
|
|
||||||
'cache' => array(
|
'cache' => array(
|
||||||
'base' => 'acp_styles',
|
'base' => 'acp_styles',
|
||||||
'class' => 'acp',
|
'class' => 'acp',
|
||||||
|
@ -2331,7 +2310,7 @@ function change_database_data(&$no_updates, $version)
|
||||||
_add_modules($modules_to_install);
|
_add_modules($modules_to_install);
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . MODULES_TABLE . "
|
$sql = 'DELETE FROM ' . MODULES_TABLE . "
|
||||||
WHERE (module_basename = 'styles' OR module_basename = 'acp_styles') AND (module_mode = 'imageset' OR module_mode = 'theme' OR module_mode = 'template')";
|
WHERE (module_basename = 'styles' OR module_basename = 'acp_styles') AND (module_mode = 'imageset' OR module_mode = 'theme' OR module_mode = 'template')";
|
||||||
_sql($sql, $errored, $error_ary);
|
_sql($sql, $errored, $error_ary);
|
||||||
|
|
||||||
// Localise Global Announcements
|
// Localise Global Announcements
|
||||||
|
@ -2422,11 +2401,138 @@ function change_database_data(&$no_updates, $version)
|
||||||
set_config('teampage_memberships', '1');
|
set_config('teampage_memberships', '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear styles table and add prosilver entry
|
// Check if styles table was already updated
|
||||||
_sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
|
if ($db_tools->sql_table_exists(STYLES_THEME_TABLE))
|
||||||
|
{
|
||||||
|
// Get list of valid 3.1 styles
|
||||||
|
$available_styles = array('prosilver');
|
||||||
|
|
||||||
$sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')";
|
$iterator = new DirectoryIterator($phpbb_root_path . 'styles');
|
||||||
_sql($sql, $errored, $error_ary);
|
$skip_dirs = array('.', '..', 'prosilver');
|
||||||
|
foreach ($iterator as $fileinfo)
|
||||||
|
{
|
||||||
|
if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg'))
|
||||||
|
{
|
||||||
|
$style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
|
||||||
|
if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>='))
|
||||||
|
{
|
||||||
|
// 3.1 style
|
||||||
|
$available_styles[] = $fileinfo->getFilename();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all installed styles
|
||||||
|
if ($db_tools->sql_table_exists(STYLES_IMAGESET_TABLE))
|
||||||
|
{
|
||||||
|
$sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path
|
||||||
|
FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i
|
||||||
|
WHERE t.template_id = s.template_id
|
||||||
|
AND c.theme_id = s.theme_id
|
||||||
|
AND i.imageset_id = s.imageset_id";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id
|
||||||
|
FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c
|
||||||
|
WHERE t.template_id = s.template_id
|
||||||
|
AND c.theme_id = s.theme_id";
|
||||||
|
}
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
$styles = array();
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$styles[] = $row;
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
// Decide which styles to keep, all others will be deleted
|
||||||
|
$valid_styles = array();
|
||||||
|
foreach ($styles as $style_row)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
// Delete styles with parent style (not supported yet)
|
||||||
|
$style_row['template_inherits_id'] == 0 &&
|
||||||
|
// Check if components match
|
||||||
|
$style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) &&
|
||||||
|
// Check if components are valid
|
||||||
|
in_array($style_row['template_path'], $available_styles)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Valid style. Keep it
|
||||||
|
$sql_ary = array(
|
||||||
|
'style_path' => $style_row['template_path'],
|
||||||
|
'bbcode_bitfield' => $style_row['bbcode_bitfield'],
|
||||||
|
'style_parent_id' => 0,
|
||||||
|
'style_parent_tree' => '',
|
||||||
|
);
|
||||||
|
_sql('UPDATE ' . STYLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE style_id = ' . $style_row['style_id'], $errored, $error_ary);
|
||||||
|
$valid_styles[] = (int) $style_row['style_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove old styles tables
|
||||||
|
$changes = array(
|
||||||
|
'drop_columns' => array(
|
||||||
|
STYLES_TABLE => array(
|
||||||
|
'imageset_id',
|
||||||
|
'template_id',
|
||||||
|
'theme_id',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'drop_tables' => array(
|
||||||
|
STYLES_IMAGESET_TABLE,
|
||||||
|
STYLES_IMAGESET_DATA_TABLE,
|
||||||
|
STYLES_TEMPLATE_TABLE,
|
||||||
|
STYLES_TEMPLATE_DATA_TABLE,
|
||||||
|
STYLES_THEME_TABLE,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$statements = $db_tools->perform_schema_changes($changes);
|
||||||
|
|
||||||
|
foreach ($statements as $sql)
|
||||||
|
{
|
||||||
|
_sql($sql, $errored, $error_ary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove old entries from styles table
|
||||||
|
if (!sizeof($valid_styles))
|
||||||
|
{
|
||||||
|
// No valid styles: remove everything and add prosilver
|
||||||
|
_sql('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
|
||||||
|
|
||||||
|
$sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')";
|
||||||
|
_sql($sql, $errored, $error_ary);
|
||||||
|
|
||||||
|
$sql = 'SELECT style_id
|
||||||
|
FROM ' . $table . "
|
||||||
|
WHERE style_name = 'prosilver'";
|
||||||
|
$result = _sql($sql, $errored, $error_ary);
|
||||||
|
$default_style = $db->sql_fetchfield($result);
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
set_config('default_style', $default_style);
|
||||||
|
|
||||||
|
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0';
|
||||||
|
_sql($sql, $errored, $error_ary);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// There are valid styles in styles table. Remove styles that are outdated
|
||||||
|
_sql('DELETE FROM ' . STYLES_TABLE . ' WHERE ' . $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
|
||||||
|
_sql('UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE ' . $db->sql_in_set('user_style', $valid_styles, true), $errored, $error_ary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$no_updates = false;
|
$no_updates = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue