Changing a theme name (or adding a subtheme) without losing block and theme settings
This happens to me periodically, so I thought I'd write it down.
Situation: An existing site has had its theme hacked in place, or just has a stock theme deployed and I need a subtheme. But that means that I'm going to have to change the name of the theme, which can mean having to go back and do all the theme and block settings again. I really don't like manual work, so this time I tried to write down what has to be done to create a new theme with the old theme's settings and block settings.
I did this on a Drupal 6 site, but I believe the basics are the same for any Drupal version. Edit (26 May 2011): Drupal 7 block table changed its name and one field, so a recipe for it is at the bottom of the article.
- Create your new theme or subtheme. Our theme's machine name will be 'newtheme'. The theme we're replacing (which has the same regions and behavior) will be 'oldtheme'.
- Create new records in the blocks table for the new theme
DELETE FROM blocks WHERE theme="newtheme";<br> INSERT INTO blocks SELECT 0, module, delta, 'newtheme', status, weight, region, custom, throttle, visibility, pages, title, cache FROM blocks WHERE theme="oldtheme";
- Make a copy of the theme_settings information:
DELETE FROM variable WHERE name="theme_newtheme_settings";<br> INSERT INTO variable SELECT 'theme_newtheme_settings', value from variable where name="theme_oldtheme_settings";
- You may have other theme specific variables. For example, if you use skinr...
DELETE FROM variable WHERE name="skinr_newtheme";<br>INSERT INTO variable SELECT 'skinr_newtheme', value from variable where name="skinr_oldtheme";
- Clear your cache
drush cc all
Now of course you should look around and see if it all worked, but this may give you a start.
Here's the full set of sql statements, and you can do these over and over with no damage.
DELETE FROM blocks WHERE theme="newtheme";<br>DELETE FROM variable WHERE name IN ('theme_newtheme_settings', 'skinr_newtheme');<br>INSERT INTO variable SELECT 'theme_newtheme_settings', value FROM variable WHERE name="theme_oldtheme_settings"; <br>INSERT INTO variable SELECT 'skinr_newtheme', value FROM variable WHERE name="skinr_oldtheme"; <br>INSERT INTO blocks <br> SELECT 0, module, delta, 'newtheme', status, weight, region, custom, throttle, visibility, pages, title, cache <br> FROM blocks WHERE theme="oldtheme";
For Drupal 7:
DELETE FROM block WHERE theme="newtheme";<br>DELETE FROM variable WHERE name IN ('theme_newtheme_settings', 'skinr_newtheme');<br>INSERT INTO variable SELECT 'theme_newtheme_settings', value FROM variable WHERE name="theme_oldtheme_settings"; <br>INSERT INTO variable SELECT 'skinr_newtheme', value FROM variable WHERE name="skinr_oldtheme"; <br>INSERT INTO block<br> SELECT 0, module, delta, 'newtheme', status, weight, region, custom, visibility, pages, title, cache<br> FROM block WHERE theme="oldtheme";
Edit: You'll need the color module's settings if you've used it also
Update the variables for color_themename_logo, color_themename_palette, color_themename_screenshot, and color_themename_stylesheets