-
Bug
-
Resolution: Fixed
-
3.0.1
-
None
-
PHP Environment: 5.2.5
Database: MSSql Server 2005
I was having problems with compiled styles saving to the database. I took a look at style.php to determine the execution flow and discovered that style.php is coded to use $id as both the style_id and theme_id, which aren't always the same, at least on my board.
Around Line 46 $id is assigned with the style_id value:
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
$id is assigned the value of the style ID passed via URI
Around Line 103 the style is queries with $id as the key:
$sql = 'SELECT s.style_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i
WHERE s.style_id = ' . $id . '
AND t.template_id = s.template_id
AND c.theme_id = s.theme_id
AND i.imageset_id = s.imageset_id';
Finally, around line 200 an unmodified $id is used as the key to update the theme table:
$sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
WHERE theme_id = $id";
The problem with the query is that STYLES_THEME_TABLE is only updated if theme_id = $id, but it is possible for a theme_id not to match a style_id if a user creates a custom theme. Both theme_id and style_id are autoincrement values in their respective tables, so they are not guaranteed to match.
Here is how I fixed it:
Around line 103:
$sql = 'SELECT s.style_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
I added c.theme_id to the query:
$sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
Then around line 201:
WHERE theme_id = $id";
Change $id to $theme[theme_id]
WHERE theme_id = $theme[theme_id]";
That makes it work as expected.