Enabling multiple themes in Aegir install profiles


Couples using wedful.com can select from a variety of themes for their wedding website. So when building the install profile we wanted to have all of these themes enabled by default. Enabling multiple themes in an install profile should be something simple to do. In fact, the install profile api even has a function just for this: install_enable_theme(array('theme1', 'theme2')).

However, due to the issues I discussed previously with static variables, enabling multiple themes from within an install profile is actually extremely difficult.

At the end of the aegir site install all caches are cleared in the provision module including the theme cache with:


This makes sense as your site could load up with cache issues if everything isn't cleared after the install completes.

system_theme_data() returns a list of all available themes and their data. It gets a list of existing themes, then runs db_query("DELETE FROM {system} WHERE type = 'theme'") to clear out any stale data and re-inserts the themes that it knows about. The only problem, is that the existing theme data (which only has a single theme as enabled at the start of the process) is stored in a static variable that can't be reset and by the time the install process gets around to reading your install profile, that function has already been evaluated and the static variable has been filled with data.

This essentially means that you can not enable multiple themes from within your install profile. So give up on it right now while you're still ahead.

The solution I've used to overcome this is by implementing a drush provision-install hook. The hook runs /after/ the install profile has run and after the caches have been cleared.

file: ~/.drush/wedful.drush.inc

function drush_wedful_post_provision_install($url = NULL) {
  if (drush_get_option('profile') == 'wedful') {
    module_load_include('inc', 'install_profile_api', 'core/system');

    $themes = system_theme_data();

Peanut Gallery

Bug in core

This is obviously a bug in core. Can you file an item in the issue queue at least as a placeholder and link to it from this post?

Not a bug

Scott Hadfield

I don't believe this is a bug, but actually a feature ;). I also don't think this is an issue in D7. I guess in an ideal world system_theme_data() would have a reset parameter.

There are some related issues I found with this search.

I guess I think that you

I guess I think that you SHOULD be able to enable more than one theme in your install profile -- hence, bug. If it's fixed in D7, great.

Clone Feature


Did you consider trying to hook into the clone (http://community.aegirproject.org/node/24) feature in Aegir to create new sites from a "template" site. I am considering this route to avoid all the install profile nightmare. Just curious on your thoughts of that after this experience.